entity
you get an entity value from world.entities, or as the return value of world.spawnEntity(...). players are not included here, they're exposed separately via player values (see player) and world.players
properties
entity.uuid // "8667ba71-b85a-4004-af54-457a9734eed7" as a string
entity.type // "zombie"
entity.is_valid // true / false
entity.location // { x: 12.5, y: 64.0, z: -3.0, yaw: 90.0, pitch: 0.0 }
entity.health // 20.0, living entities only
entity.max_health // 20.0, living entities only
entity.tags // a list of scoreboard tag strings
entity.yaw // living entities only
entity.pitch // living entities only
entity.is_valid
an entity can stop existing at any point, whether it dies, despawns, etc. once that happens, every property and method below (other than is_valid and uuid) throws a runtime error instead of silently doing nothing, so check first if the entity value still exists:
val zombie = world.spawnEntity("zombie", player.location)
Katton.after(5.seconds) {
if (zombie.is_valid) {
zombie.setGlowing(true)
}
}
health / max_health / yaw / pitch only work on living entities
calling these (or setHealth, setMovementSpeed, setJumpStrength) on a non-living entity (an item display, a dropped item, etc) is a runtime error naming exactly what was wrong
methods
entity.setHealth(health)
entity.setDisplayName(text)
entity.teleport(location)
entity.setGlowing(glowing = true)
entity.addTag(tag)
entity.removeTag(tag)
entity.hasTag(tag)
entity.setMovementSpeed(speed)
entity.setJumpStrength(strength)
entity.setItem(item)
entity.setTeleportDuration(ticks)
entity.kill()
setHealth
val zombie = world.spawnEntity("zombie", player.location)
zombie.setHealth(5)
clamped between 0 and the entity's max_health
setDisplayName
zombie.setDisplayName("&c&lBOSS ZOMBIE")
supports & color codes. passing "" hides the name tag again
teleport
zombie.teleport({ "x": 0, "y": 70, "z": 0, "yaw": 0, "pitch": 0 })
same location value shape as player.teleport
setGlowing
zombie.setGlowing(true)
zombie.setGlowing(false)
addTag / removeTag / hasTag
scoreboard tags are handy for marking specific entities your script spawned so you can tell them apart from everything else in the world later:
val zombie = world.spawnEntity("zombie", player.location)
zombie.addTag("boss_fight_mob")
for (e in world.entities) {
if (e.hasTag("boss_fight_mob")) {
e.setGlowing(true)
}
}
removeTag does nothing if the tag was never there. entity.tags (the property) gives you every tag at once as a list
setMovementSpeed / setJumpStrength
zombie.setMovementSpeed(0.3) // vanilla default is 0.1
zombie.setJumpStrength(0.6) // vanilla default is 0.42
living entities only
setItem
val display = world.spawnEntity("item_display", player.location)
display.setItem(Katton.item("diamond_sword"))
only works on item display entities, it will cause a runtime error if done otherwise. see item for making items
setTeleportDuration
display.setTeleportDuration(20) // smoothly interpolate position changes over 1 second instead of snapping
only works on display entities (item display, block display, text display). clamped between 0 and 59 ticks
kill
zombie.kill()
removes the entity immediately