Skip to content

Entity

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

Metatable name: "entity"

All properties are read/write unless noted as read-only.

type: string (read-only)

type: string (read-only)

Entity type (e.g. "minecraft:zombie").

type: string (read-only)

type: string (read-only)

type: string or nil

type: World (read-only)

type: Vector

type: Vector

The direction of the head.

type: Vector

type: boolean

type: boolean

type: number

Idk what it means, but it exists.

type: boolean (read-only)

type: number

type: number

type: number

type: number (read-only)

type: number

-1 means not on fire.

type: boolean

type: boolean

type: ItemStack or nil

type: ItemStack or nil

type: ItemStack or nil

type: ItemStack or nil

type: ItemStack or nil

type: ItemStack or nil

All attributes are read/write (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. 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)

entity:raycast(range, includeFluids?, includeEntities?)

Section titled “entity:raycast(range, includeFluids?, includeEntities?)”

Performs a raycast from the entity’s eyes.

  • range (number) — Max distance
  • includeFluids (boolean, optional) — Include fluid blocks
  • includeEntities (boolean, optional, default true) — Include entity hits

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
effectIdstringEffect type ID (e.g. "minecraft:speed")
durationnumberDuration in ticks
amplifiernumber0Effect amplifier
particlesbooleantrueShow particles
iconbooleantrueShow effect icon
entity:addEffect("minecraft:speed", 600, 1, true, true) -- Speed II, 30s

Removes a potion effect.

  • effectId (string) — Effect type ID (e.g. "minecraft:speed")
entity:removeEffect("minecraft:speed")

Checks if an effect is active.

  • effectId (string) — Effect type ID (e.g. "minecraft:speed")

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.