Entities from Lua
Properties, effects, attributes, equipment, movement, mob goals and state, and the events of mobs, projectiles and vehicles.
An entity object is what world:entities(), world:entity(id), the entity field of an event and world:spawn(...)
give you. Players answer to the same object through world:entity(player_entity_id), for the subset that applies to
them. Dropped items (minecraft:item) are listed by world:entities() too and answer to nbt, nbt_value,
nbt_set, merge_nbt, push, teleport and velocity.
local zombie = world:spawn_as("minecraft:zombie", 0, 64, 0, 90, "plugin")
zombie.max_health = 40
zombie.health = 40
zombie:add_effect("minecraft:speed", 600, 1)
zombie:set_equipment("head", helmet_nbt)
zombie:move_to(10, 64, 10, 1.2)Properties#
Read them as fields; the ones marked rw can be assigned.
| Field | Type | Access | Meaning |
|---|---|---|---|
health, max_health, absorption |
number | rw | Health is clamped to 0 to max_health (use kill to die); the max_health setter changes the base value |
fire_ticks, frozen_ticks, air |
integer | rw | Ticks on fire, TicksFrozen, air supply |
max_air |
integer | r | 300, or 4800 for dolphins |
fall_distance |
number | rw | Accumulated fall distance |
no_gravity, invulnerable, glowing, silent, invisible |
boolean | rw | The vanilla flags |
custom_name, custom_name_visible |
string or nil, boolean | rw | Plain custom name; nil or empty clears it |
persistent |
boolean | rw | Never despawns |
ticks_lived |
integer | rw | Ticks since creation |
tags |
list of strings | rw | Scoreboard tags; assigning a table replaces them all |
vehicle, passengers |
integer, list | r | Id of what it rides (-1 for none) and the ids of its riders |
no_ai, can_pick_up_loot, left_handed |
boolean | rw | Mob switches |
target |
integer | rw | Id of the attack target, -1 for none |
last_damage, no_damage_ticks |
number, integer | rw | The invulnerability window compares against them |
last_damage_cause, last_hurt_by_player |
string, string or nil | r | Damage type of the last hit, and the uuid of the player that hurt it recently |
arrows_in_body |
integer | rw | Stuck arrows |
sleeping |
boolean | r | Asleep |
leash_holder |
integer | rw | Id holding the lead, -1 for none |
breed_age, love_ticks, love_cause |
integer, integer, string or nil | rw | Growth age (negative is a baby), in love ticks, uuid that fed it |
owner, sitting, tamed_horse |
string or nil, boolean, boolean | rw | Taming state |
cube_size |
integer | rw | Slime and magma cube size; health and attributes follow |
fuse, powered, swell |
integer, boolean, integer | rw | Primed tnt fuse, charged creeper, creeper fuse progress |
profession, villager_level, villager_experience |
string, integer, integer | rw | Villager state; level is 1 to 5 |
owner_id, critical, arrow_pickup, pierce_level, explosion_power |
mixed | rw | Projectile state; arrow_pickup is 0 disallowed, 1 allowed, 2 creative only |
category |
string | r | Mob category: monster, creature, ambient, water_creature... |
display_text |
string or nil | rw | Text of a text display, in MiniMessage; clients that already see it get the change |
object_data |
integer | rw | Spawn data, such as the block state id of a falling block |
bolt_visual_only, bolt_life, bolt_flashes, bolt_cause |
boolean, integer, integer, integer | rw | Lightning bolt state; bolt_cause is the entity id that caused it, -1 for none |
gliding, swimming, crouching, sprinting |
boolean | rw | Forces the shared flag clients see, and the matching pose |
pose |
integer | rw | Forces a pose by ordinal (0 standing to 17 inhaling); -1 or any other value clears it |
visual_fire |
integer | rw | -1 follows the real fire, 0 never shows fire, 1 always |
freeze_locked, jumping, no_physics, riptiding, collidable, visible_by_default |
boolean | rw | Frost count lock, jump input, ignores collisions, spin attack, pushing, and false to hide the entity until shown per player |
portal_cooldown, no_action_time, max_no_damage_ticks, max_air |
integer | rw | Ticks before the next portal, idle ticks (despawn timer), hurt cooldown length (20 by default) and air ceiling |
bee_stingers, bee_stinger_cooldown, arrow_cooldown |
integer | rw | Stuck stingers and arrows and their removal timers |
last_hurt_by_player |
string or nil | rw | Uuid credited as killer; empty clears it |
hurt_direction |
number | rw | Yaw offset of the last hit |
spawn_reason, sound_volume |
string, number | r | Why the mob spawned (natural, plugin, event...) and its voice volume |
move_forward, move_sideways, move_up |
number | rw | Current movement input of the mob controller |
nav_pass_doors, nav_can_float |
boolean | rw | Ground navigation may path through doors (false also stops door opening, true by default), and may cross water at the surface instead of routing around (false by default) |
trading_player |
integer | r | Entity id of the player trading with a villager, -1 for none |
active_slot, active_ticks, active_used |
integer | r, rw, rw | Hand of an item in use (0 main, 1 off, -1 none), remaining and elapsed ticks |
e:get(name) and e:set(name, value) reach any property by name, including the ones that are not fields:
loot_table (string) and loot_seed (integer). e:call(operation, args...) runs an operation by name, such as
is_breed_item(item), which tells whether an item is the animal's breeding food.
Damage and death#
e:damage(6, "minecraft:magic", attacker.id) -- through armour, the invulnerability window and events
e:kill() -- the death sequence
e:knockback(0.5, attacker.x, attacker.z) -- away from (x, z)
e:push(0, 1, 0) -- adds to the velocitydamage(amount, cause?, attacker_id?) takes a vanilla damage type path (generic by default). All of them return
whether they did something.
Effects and attributes#
| Call | Returns |
|---|---|
e:add_effect(effect, ticks, amplifier, ambient?, particles?, icon?) |
boolean; -1 ticks is infinite |
e:remove_effect(effect), e:clear_effects(), e:has_effect(effect) |
boolean |
e:effects() |
List of { effect, duration, amplifier, ambient, particles, icon }, values as strings |
e:attribute(id), e:attribute_base(id), e:attribute_default(id) |
Value with modifiers, base value, default for the type |
e:set_attribute_base(id, value), e:has_attribute(id) |
boolean |
e:attribute_modifiers(id) |
List of { id, amount, operation } |
e:add_attribute_modifier(attribute, id, amount, operation) |
boolean; operation is add_value, add_multiplied_base or add_multiplied_total |
e:remove_attribute_modifier(attribute, id) |
boolean |
Equipment and riding#
e:equipment(slot) returns the stack as NBT bytes (or nil) and e:set_equipment(slot, stack_nbt) writes it, nil
clearing the slot. Slots are mainhand, offhand, feet, legs, chest, head, body and saddle.
e:drop_chance(slot) and e:set_drop_chance(slot, chance) read and set the chance it drops.
e:mount(vehicle_id) rides another entity, e:dismount() gets off and e:eject() throws every rider off.
Movement of mobs#
| Call | Does |
|---|---|
e:look_at(x, y, z, yaw_speed?, pitch_speed?) |
Turns the head towards a point, through the mob look control |
e:move_to(x, y, z, speed?) |
Starts walking a path to the point; speed is a modifier, 1.0 by default |
e:can_reach(x, y, z) |
Whether a path exists |
e:stop_path(), e:has_path() |
Stops walking, tells whether a path is being followed |
Mob goals#
A mob can carry goals a plugin owns next to the vanilla ones, in the same selector: priority, flags and interruption work as in vanilla, and a mob without plugin goals pays nothing. Mobs that run on a brain (villagers) do not run them.
| Call | Returns | Does |
|---|---|---|
e:add_goal(key, priority, flags?) |
bool | Adds a plugin goal; flags is a comma list of move look jump target |
e:remove_goal(key) |
int | Retires every goal with that key, vanilla ones by name (panic, look_at_player, bee_enter_hive...) |
e:remove_goals(flags?) |
int | Retires every goal that locks one of the flags, or all of them when none is given |
e:has_goal(key) |
bool | Whether a live goal with that key exists |
e:goals() |
list | { key, priority, running, plugin, usable, flags } for each goal; usable is whether the goal could start (or keep going while it runs) at the selector's last check |
A vanilla goal key is the vanilla goal class name in snake case without Goal; the minecraft: prefix is optional. A
running goal that is removed stops on the next AI turn. The entity.goal event drives a plugin goal.
e:add_goal("my:wave", 3, "look")
on("entity.goal", function(ev)
if ev.key == "my:wave" and ev.phase == "can_use" then ev.result = true end
end)Mob state#
Vindicators named Johnny attack any living thing, evokers cast the wololo spell on blue sheep, fish schools follow a
leader, witches drink helpful potions by themselves, and players shear sheep, mooshrooms, snow golems, bogged and copper
golems, as in vanilla.
These properties are read with e:get(name) and written with e:set(name, value). A read answers nil, and a write
false, on an entity the property does not apply to. Nothing here changes what a mob does by default.
Four more fields are plain properties: age_locked (an animal's age no longer moves), burns_in_day,
despawn_in_peaceful (-1 default, 0 never, 1 despawns in peaceful) and nav_open_doors. aggressive (the
arms-up flag) is also a field, and melee goals raise it while they attack, so zombies hold their arms up.
| Group | Names |
|---|---|
| Mobs | conversion_countdown (-1 for none: zombie to drowned, husk to zombie, skeleton to stray, zombie villager cure), conversion_clock, immune_to_zombification, charging (r), spell (r, 0 none to 5 blindness), neutral_anger_end (game tick, -1 calm), despawn_delay, wander_target, moistness, got_fish, dolphin_treasure, puff_state (0 to 2), bat_resting (r), axolotl_playing_dead, skeleton_trap, skeleton_trap_time, wolf_interested |
| Fishing bobber | hook_min_wait, hook_max_wait, hook_min_lure, hook_max_lure, hook_min_angle, hook_max_angle, hook_apply_lure, hook_rain_influenced, hook_sky_influenced, hook_bite_chance, hook_wait, hook_bite_in, hook_open_water (r), hook_phase (r), hook_hooked (r) |
| Minecarts | cart_max_speed, cart_slow_when_empty, cart_friction, cart_flying_x/y/z, cart_derailed_x/y/z, cart_fuel, cart_push_x, cart_push_z, cart_explosion_speed, vehicle_damage |
| Boats | boat_status (r), boat_max_speed, boat_occupied_deceleration, boat_unoccupied_deceleration, boat_work_on_land |
| Animals and monsters | villager_restocks, horse_eating, horse_mouth_open, horse_rearing, horse_dashing, horse_max_temper, llama_caravan_head (r), llama_caravan_tail (r), bee_sting_age, bee_rolling (r), bee_rolling_override, allay_dancing, allay_jukebox (r), allay_duplication_cooldown, armadillo_state (r), creaking_active, creaking_home (r), copper_weather, copper_pose, copper_weathering_tick, sniffer_state (r), warden_highest_anger, warden_angry_at (r), dragon_phase, dragon_death_ticks (r), dragon_podium, guardian_laser_ticks, guardian_laser_target (r), shulker_peek (r), shulker_face, bullet_steps, bullet_target, bullet_direction, bullet_delta_x/y/z, frog_tongue_target, enderman_stared_at, piglin_cannot_hunt, piglin_dancing, piglin_charging, fox_flags, panda_flags, panda_unhappy, panda_sneeze, panda_eat, cat_lying, cat_head_up (r) |
| Raiders | raid_wave, raid_can_join, raid_ticks_outside, raid_celebrating (r), raid_id (r), patrol_leader, patrol_target |
hook_bite_in starts the luring phase when written, as the bobber would. hook_phase is 0 flying, 1 hooked entity, 2
bobbing, and hook_hooked is the hooked entity id or -1. boat_status runs from 0 in water to 4 in air.
fox_flags uses the bits 4 crouching, 8 interested, 16 pouncing, 64 faceplanted and 128 defending; panda_flags uses 2
sneeze, 4 roll, 8 sit and 16 on back. copper_weathering_tick is -2 waxed, -1 unset, else a game tick.
A second set of mob properties: creeper_ignited, creeper_igniter (id, -1 none), evoker_wololo (id of the sheep, -1
none), polar_standing, strider_shivering, turtle_laying_egg, turtle_going_home, parrot_dancing,
wither_portals, cube_wander (false: a slime, magma cube or sulfur cube never hops by itself), boost_total and
boost_time (pig and strider item boost), boost_active (r), witch_drinking (r), witch_use_ticks, bat_target
("x,y,z" or nil), guardian_moving (r) and cart_detonate (w, the speed squared a tnt minecart blows up with).
Sulfur cubes have a fuse (integer, rw): the ticks left on the lit fuse, -1 when it is not primed. When it runs out the
cube explodes with power 3, breaking blocks only with mob_griefing and requiring tnt_explodes. Fire, an explosion,
flint and steel, a fire charge or a powered position light it, and a cube holding an item shrugs off plain hits. Turtles
lay eggs, go home and travel in water with the vanilla goals: has_egg and home_pos are set with nbt_set ("bool"
and "pos" as "x,y,z"). A wandering trader stops drinking its invisibility potion or milk when Paper.CanDrinkPotionDisabled
or Paper.CanDrinkMilkDisabled is true. Non-player entities in a nether portal frame travel at once and rest 300 ticks;
the wither does not unless wither_portals is true.
Operations go through e:call(name, args...).
| Call | Returns | Does |
|---|---|---|
ambient_sound(), xp_reward() |
string or nil, int | The sound the mob would make now; the experience a kill would give |
ranged_attack(x, y, z, charge?) |
bool | Skeleton family, wither and llama shoot at a point |
converting() |
bool | A piglin or hoglin is turning |
set_charging(bool), set_sleeping(bool), bat_awake(bool), cat_lying(bool), cat_head_up(bool), set_spell(n) |
bool | State changes the clients see |
raider_celebrate(bool) |
bool | Starts or stops celebrating |
guardian_laser(bool) |
bool | Beam on the current target, or off; false without a target |
enderman_teleport(towards, x, eye_y, z) |
bool | 0 teleports at random, 1 away from the point as vanilla does |
llama_join_caravan(head_id), llama_leave_caravan() |
bool | Caravan membership |
shulker_set_peek(raw) |
bool | Opens the lid, 0 to 100, with its sound |
hook_reset(), hook_pull() |
bool | Resets the fishing timers; pulls the hooked entity toward the owner |
allay_duplicate() |
int | Spawns a copy and returns its entity id, or -1 |
armadillo_roll_up(), armadillo_roll_out() |
bool | Rolls |
creaking_activate(player_id), creaking_deactivate() |
bool | |
sniffer_explored(), sniffer_explore(x, y, z, remove?) |
list | The places it has dug as x,y,z; adds or removes one |
warden_anger(id), warden_set_anger(id, n), warden_increase_anger(id, n), warden_clear_anger(id), warden_disturb(x, y, z) |
The anger book of a warden, keyed by entity id | |
villager_restock(), villager_update_demand(), villager_reset_offers(), villager_add_trades(n), villager_shake_head(), villager_sleep(x, y, z), villager_wake() |
Trading and bed; villager_add_trades(0) only makes sure the offers exist |
|
retype(type) |
int | Turns the entity into another type keeping its saved data, uuid and riders; the new entity id, or -1 |
goat_ram(id) |
bool | The goat rams the entity at once |
sniffer_set_state(n), sniffer_can_dig(), sniffer_dig_spot() |
bool, bool, string or nil | Moves the sniffer to a state (0 idling to 6 rising) with its sound; tells whether it can dig; a diggable spot as x,y,z |
piglin_items(kind), piglin_item_edit(kind, item, add) |
list, bool | The barter or interest item ids of a piglin; adds or removes one |
piglin_dance(on, ticks) |
bool | Starts or stops the dance; ticks -1 dances until stopped |
held_get(kind, slot), held_set(kind, slot, nbt) |
bytes, bool | A stack in a mob's own state: kind piglin (8 slots), villager (8) or allay (1) |
school_follow(id), school_stop(), school_info() |
bool, bool, list | Fish school: follow a leader, leave, { leader id or -1, size, max size } |
shear_ready(), shear(source) |
bool | Whether the mob could be sheared; shears it (sound source index as in Sound.Source) |
wolf_wet(), witch_drink(nbt), sulfur_swallow(nbt) |
bool | In water or rain; the witch starts drinking a potion stack (nil stops it); the sulfur cube swallows the stack when it can |
dragon_parts() |
list | The eight hit boxes as minx,miny,minz,maxx,maxy,maxz |
wither_target(head), wither_set_target(head, id) |
int, bool | The targets of the three heads (0 centre, 1 left, 2 right) |
bar_info(), bar_set(field, value), bar_players(), bar_pin(id, shown) |
list, bool, list, bool | The boss bar of a wither: { title json, color, overlay, darken, music, fog, progress, visible }; bar_set takes those names; who sees it; shows it to one player or sends them away |
sulfur_can_explode() |
bool | The cube holds an explosive item (tnt), is alive and its fuse is not lit |
sulfur_prime(imminent) |
bool | Lights the fuse (120 ticks, a short random one when imminent); false when it cannot explode or tnt_explodes is off |
villager_zombify() |
int | Becomes a zombie villager and returns its id, or -1 |
villager_gossips() |
list | Six values a row: player uuid, then major negative, minor negative, minor positive, major positive, trading |
villager_set_gossip(uuid, type, value), villager_clear_gossips() |
bool | type 0 to 4 in the order above |
Projectiles, items and decorations#
Every property below reads as what vanilla does until a plugin writes it. e:get(name) and e:set(name, value) reach
them.
| Name | Type | Meaning |
|---|---|---|
bounce |
boolean | A projectile that hits a block or entity reflects its velocity (kept at 80 %) instead of landing |
incendiary |
boolean | An explosive or fireball sets fires; true for fireballs and small fireballs, false elsewhere |
arrow_knockback |
integer | Arrow punch in levels (0.6 of push per level); reads the weapon's punch until set |
arrow_life |
integer | Ticks an arrow has spent in the ground; it despawns at 1200 |
fired_from |
string or nil | Item id of the weapon that fired the arrow; minecraft:crossbow plays the crossbow hit sound |
wither_charged |
boolean | Blue (dangerous) wither skull |
trident_glint |
boolean | Enchantment glint on a thrown trident |
attached_to |
integer | Entity id a firework rocket boosts, -1 for none |
eye_despawn, eye_drops |
integer, boolean | Ticks an eye of ender has flown (it ends at 80), and whether it drops as an item instead of shattering |
| Call | Returns | Does |
|---|---|---|
e:hit_entity(id) |
bool | The projectile hits that entity on its next tick, through the code of a real hit |
e:land() |
bool | A thrown potion splashes or a wind charge bursts where it is, on the next tick |
e:hook_retrieve(off_hand) |
int | The hook's owner reels in with the rod in that hand; the rod wear, -1 when there is nothing to reel |
e:hook_own(player_id) |
bool | Registers a hook spawned by a plugin as that player's own bobber, so it fishes and can be reeled in |
e:eye_target() |
list | The x, y, z an eye of ender flies towards, empty when it has none |
e:set_eye_target(x, y, z, reset) |
bool | Aims the eye; reset restarts its flight timer |
Item entities take these keys through nbt_set: CanMobPickup and CanPlayerPickup (short 0 or 1; 0 stops mobs that
gather items, or players, from picking it up) and FrictionState (1 removes ground friction). An armor stand takes
BasaltNoMove and BasaltNoTick (true stops it from moving, or from ticking at all), and a falling block that lives
over 600 ticks drops as an item unless BasaltNoExpire is true. Experience orbs keep SpawnReason, SourceEntity and
TriggerEntity, and interactions keep attack and interaction as {player, timestamp}.
Ghast fireballs set fires where they explode when mob_griefing is on, arrow punch from the weapon pushes mobs and
players, and primed TNT honours its explosion_power (4 by default).
Entity NBT#
e:nbt(path?) returns the whole entity NBT, or the compound at a dotted path. e:nbt_value(path) returns one scalar.
e:nbt_set(path, type, value) writes into the extra data (type is bool, byte, short, int, long, float,
double, string, uuid or pos) and e:merge_nbt(nbt) merges a compound: live fields are updated and the rest is kept as extra
data. A uuid value is a uuid string, saved as four ints; a pos value is "x,y,z", saved as three ints.
e:call("nbt_remove", path) removes a key at a dotted path and returns whether it did. Every change to the saved data
is sent again to the players who can see the entity, and a bee takes its saved fields back into its live state.
World calls#
| Call | Does |
|---|---|
w:spawn_as(type, x, y, z, yaw?, reason?) |
Spawns with a facing and the reason the spawn event reports (plugin by default) |
w:drop_item(item, x, y, z, vx?, vy?, vz?) |
Puts an item on the ground; item is as in inventory:set |
w:explode(x, y, z, power, break_blocks?, source_id?, fire?) |
An explosion; blocks are spared when break_blocks is false, and fires are set when fire is true |
Events#
The events of mobs, projectiles and vehicles (entity.damage, entity.drops, entity.target, entity.goal,
entity.move, vehicle.damage...) are listed with their fields in the
entity, item and inventory events.
on("entity.drops", function(e)
e.exp = e.exp * 2
end)