Guide 1 Docs 2 Reference 3
24

EntitySpec type

A kind of entity a pack makes up. base is the last argument of every hook: call it and you extended, don't and you replaced.

Functions 7

entitySpec.on_spawn((e: EntityHandle) -> ()) → ?

Told when one of this kind is spawned; nothing waits on it and its answer is not read.

entitySpec.on_load((e: EntityHandle) -> ()) → ?

Told when one that already existed comes back: a saved chunk loaded it or a reload rebound it.

entitySpec.on_steer((e: EntityHandle, base: () -> ()) -> ()) → ?

Runs before the physics each tick to decide where it goes; call base(e) to extend, leave it out to replace.

entitySpec.on_tick((e: EntityHandle, base: () -> ()) -> ()) → ?

Runs after the physics each tick to react to where it ended up; call base(e) to extend.

entitySpec.on_think((b: Think) -> ()) → ?

define only. The brain: one call for all due bodies of the kind, with their numbers in columns. The engine never waits for it; the answer lands on the next tick it is there, and is never dropped.

entitySpec.on_damage((e: EntityHandle, amount: number, by: Player?) -> ("take" | "ignore")?) → ?

Asked when a player hits it: answer "take" or "ignore". Nil or a missed deadline is "take". by is the player who hit.

entitySpec.on_remove((e: EntityHandle, why: string?) -> ()) → ?

Told when it goes; why is "removed", "settled", "killed" or "unloaded". Not called when the pack goes away.

Fields 17

entitySpec.name: string

Your own word for the kind, lower case, digits and underscores; the pack's namespace is added for you ("rocket" is "rave:rocket").

entitySpec.looks: Looks | Model

A shape the client draws, or a model from models.new.

entitySpec.physics: Physics?

Which order of operations moves it: "living", "falling", "item", "none", or "vehicle" to drive by seat 1's keys.

entitySpec.size: (number | { number })?

One number, or { width, height }. An entity is as deep as it is wide.

entitySpec.persist: Persist?

"save" brings it back with its chunk, data and all; "despawn", the default, is gone when the chunk goes.

entitySpec.seats: { Vec3 }?

A model's: where riders sit (model units, seat 1 drives), its size, and what a client older than 1.21.4 sees.

entitySpec.scale: number?

A model's size; 1 by default.

entitySpec.fallback: string?

What a client older than 1.21.4 sees in place of the model, such as "minecart".

entitySpec.speed: number?

How fast it goes, in blocks a second. A vehicle's top speed; a living body's walk at forward = 1, the game's own mob walk by default.

entitySpec.max_health: number?

physics = "living" only: the most health it has, and what it starts with. 1 to 1024; 20 by default.

entitySpec.drops: ({ { [string]: any } } | false)?

physics = "living" only: what it leaves when it dies. Each row is { item = "stick", count = 2 }, count = { least, most } for a random count, chance = 0.05 for a row that comes from one death in twenty, or a pack item. false or nil: nothing.

entitySpec.sounds: ({ hurt: string?, death: string?, ambient: string? } | false)?

physics = "living" only: sound names for its hurt, its death and its idle sound, vanilla or "<pack>.<file>". false or nil: silent.

entitySpec.can_fly: boolean?

physics = "living" only: it may fly when its pack sets e.flying = true, and it takes no fall damage.

entitySpec.turn: number?

physics = "vehicle" only: degrees a second it turns at speed; 90 by default.

entitySpec.accel: number?

physics = "vehicle" only: seconds from standing to top speed; 1 by default.

entitySpec.step: number?

physics = "vehicle" only: blocks it climbs without a jump; 1 by default.

entitySpec.think_every: number?

define only. Seconds between two thinks of one body; one tick (0.05) by default, at most 60. The engine spreads the bodies over the ticks.