Skip to content

Entity

The entity wrapper provides access to any Minecraft entity. Player entities extend this wrapper — see Player API.

Metatable name: "entity"

type: string

UUID string. Read-only.

type: string

Entity type (e.g. "minecraft:zombie"). Read-only.

type: string

Entity name. Read-only.

type: string

Display name. Read-only.

type: string or nil

Custom name. Assign to set.

type: World

The world the entity is in. Read-only.

type: table ({x, y, z})

Position. Assign to teleport.

type: table ({x, y, z})

Look direction. Read-only.

type: table ({x, y, z})

Body direction. Read-only.

type: boolean

Sneaking state. Assign to set.

type: boolean

Sprinting state. Assign to set.

type: number

Current fall distance. Assign to set.

type: boolean

Whether the entity has been removed. Read-only.

type: number

Current health. Assign to set.

type: number

Maximum health. Assign to set base value; clamps current health.

type: number

Remaining air. Assign to set.

type: number

Maximum air. Read-only.

type: number

Remaining fire ticks. -1 means not on fire. Assign to set.

type: boolean

Glowing effect state. Assign to set.

type: boolean

Invulnerability state. Assign to set.

type: ItemStack or nil

Main hand item. Assign to set equipped item.

type: ItemStack or nil

Off hand item. Assign to set equipped item.

type: ItemStack or nil

Helmet item. Assign to set equipped item.

type: ItemStack or nil

Chestplate item. Assign to set equipped item.

type: ItemStack or nil

Leggings item. Assign to set equipped item.

type: ItemStack or nil

Boots item. Assign to set equipped item.

All attributes are read/write. Assign to set the base value.

type: number

Movement speed.

type: number

Armor value.

type: number

Armor toughness.

type: number

Attack damage.

type: number

Attack speed.

type: number

Knockback resistance.

type: number

Luck attribute.

type: number

Step height.

type: number

Block break speed.

type: number

Gravity multiplier.

type: number

Entity scale.

type: number

Safe fall distance.

type: number

Flying speed.

type: table

Scoreboard tags proxy table. Read to iterate; assign boolean values to add (true) or remove (false) tags.

for _, tag in ipairs(entity.tags) do
print(tag)
end
entity.tags["my_tag"] = true -- add
entity.tags["old_tag"] = false -- remove

Deals damage to the entity.

  • amount (number) — Damage amount
  • source (Entity, optional) — Attacking entity
entity:damage(10)
entity:damage(5, attacker)

Performs a raycast from the entity’s eyes.

  • range (number) — Max distance
  • includeFluids (boolean, optional) — Include fluid blocks

Returns a hit result or nil.

local hit = entity:raycast(10)
if hit then
-- hit.pos, hit.entity, hit.block
end

entity:addEffect(effectId, duration, amplifier?, particles?, icon?)

Section titled “entity:addEffect(effectId, duration, amplifier?, particles?, icon?)”

Adds a potion effect.

ParamTypeDefaultDescription
effectIdnumberEffect type ID (1 = Speed, 5 = Strength)
durationnumberDuration in ticks
amplifiernumber0Effect amplifier
particlesbooleantrueShow particles
iconbooleantrueShow effect icon
entity:addEffect(1, 600, 1, true, true) -- Speed II, 30s

Removes a potion effect.

  • effectId (number) — Effect type ID
entity:removeEffect(1)

Checks if an effect is active.

  • effectId (number) — Effect type ID

Returns true or false.

Sets the entity on fire for a duration.

  • ticks (number) — Duration in ticks
entity:setOnFireFor(100) -- 5 seconds

Returns the entity’s NBT data as a Lua table.

Writes NBT data from a Lua table. Lua types are converted:

Lua valueNBT type
numberDouble (whole numbers in int range stored as Int)
stringString
booleanByte (0/1)
table (string keys)Compound
table (1-indexed numeric)List
nilKey deletion

Text components must be passed as JSON strings ('{"text":"Bob"}'), not as Lua tables.

  • data (table) — NBT data
entity:writeNbt({ CustomName = '{"text":"Bob"}', Health = 40.0 })

Note: writeNbt modifies the entity on the server, but may not sync to clients immediately. Use with entity-specific tags that Minecraft re-reads each tick (health, custom name). Changes to visual-only tags may require re-spawning the entity.