Entities & Players

The OOP module models Minecraft entities and players as Kotlin objects with selectors and context-aware extension functions.

Creating entities

val player = player("Steve") {
	gamemode = Gamemode.SURVIVAL
	team = "red"
}

val arenaMobs = entity("ArenaMob", limitToOne = false) {
	tag = "arena"
}

val zombie = entity {
	type = EntityTypes.ZOMBIE
}
Kotlin

player() creates a Player instance (subclass of Entity) with type = minecraft:player, limit = 1, and the given name. entity() creates a generic Entity with custom selector arguments, and can also start from a named entity selector when you already know the exact entity name to target.

Use player(...) when you want a selector already scoped to players, and entity { ... } when you need a reusable selector for mobs, armor stands, projectiles, or a more generic execute target. Use entity("Name", ...) when you want the same convenience as player("Name") without forcing the selector to minecraft:player.

Execute helpers

Entity-scoped execute shortcuts emit /execute as, /execute at, or both:

function("teleport_self") {
	player.executeAs {
		run { it.teleportTo(it) }
	}

	player.executeAt {
		run { it.giveItem(itemStack("diamond")) }
	}

	player.executeAsAt {
		run { it.sendMessage("Hello from my location!") }
	}
}
Kotlin

These helpers are especially valuable when you would otherwise repeat the same execute as, execute at, or execute as ... at ... boilerplate around several commands.

Batch

batch() creates a named sub-function that groups multiple commands under a single entity context:

function("setup") {
	player.batch("init_player") {
		giveItem(itemStack("diamond_sword"))
		giveEffect(Effects.SPEED, duration = 200)
		sendMessage("Welcome!")
	}
}
Kotlin

batch() is a good fit for onboarding flows, class kits, respawn setup, or any repeated multi-command routine that should stay grouped under one entity context.

Entity Commands

Extension functions on Entity for common Minecraft commands:

function("commands_demo") {
	player.kill()
	player.damage(5f)
	player.addTag("vip")
	player.removeTag("vip")
	player.giveXp(10.levels)
	player.setXp(0.points)
	player.setGamemode(Gamemode.CREATIVE)
	player.sendMessage("Hello!")
	player.showTitle(textComponent("Title"), textComponent("Subtitle"))
	player.showActionBar(textComponent("Action bar text"))
	player.playSound(Sounds.ENTITY_EXPERIENCE_ORB_PICKUP)
	player.mount(zombie)
	player.dismount()
	player.clearItems()
	player.giveItem(itemStack("diamond"))
	player.replaceItem(ItemSlotType.MAINHAND, itemStack("netherite_sword"))
}
Kotlin
Function Description
addTag Add a scoreboard tag
clearItems Clear inventory (optionally filtered)
damage Deal damage with optional damage type
dismount Dismount from current vehicle
giveItem Give an item stack
giveXp Add experience (levels or points)
kill Kill the entity
mount Mount another entity
playSound Play a sound at the entity
removeTag Remove a scoreboard tag
replaceItem Replace an item in a specific slot
sendMessage Send a tellraw message
setGamemode Change the player's gamemode
setXp Set experience to an exact value
showActionBar Display text on the action bar
showTitle Display a title and optional subtitle
teleportTo Teleport to coordinates or another entity

Practical pattern

function("round_start") {
	player.batch("round_start_player") {
		giveItem(itemStack("diamond"))
		giveEffect(Effects.SPEED, duration = 200)
		showActionBar(textComponent("Fight!"))
	}
}
Kotlin

This combines one reusable player selector with several entity-scoped actions, which is the core value of the OOP entity API.

Entity Effects

Extension functions on Entity for giving, clearing, and managing mob effects:

function("buff_player") {
	player.giveEffect(Effects.SPEED, duration = 200, amplifier = 1)
	player.giveInfiniteEffect(Effects.NIGHT_VISION, hideParticles = true)
	player.clearEffect(Effects.SPEED)
	player.clearAllEffects()
}
Kotlin
Function Description
giveEffect Give a timed effect with optional amp
giveInfiniteEffect Give an infinite-duration effect
clearEffect Remove a specific effect
clearAllEffects Remove all effects
effects { ... } Builder block for multiple operations

See also

  • Items – Reuse item stacks with giveItem, replaceItem, or summon-based reward flows.
  • Events – Attach gameplay reactions directly to the entity and player handles you define here.
  • Spawners – Pair selectors and entity utilities with reusable spawning entry points.