Experimental

An early preview: docs, the API and the dashboard may change or break.

Report a problem

types.Entity

An entity a script spawned. Calls other than alive raise once it is removed.

Signals

entity.attacked: types.Signal<types.EntityClickEvent>
#
read only

A player hit the entity. A display fires only if it was spawned with a hitbox, and a model mob only if its content.mob declares one.

entity.clicked: types.Signal<types.EntityClickEvent>
#
read only

A player right-clicked the entity. A display fires only if it was spawned with a hitbox, and a model mob only if its content.mob declares one.

Fields

entity.alive: boolean
#
read only

Whether it is still in the world.

entity.look: types.Look
#
read only

Which way it faces.

entity.position: vector
#
read only

Where it stands.

entity.type: string
#
read only

minecraft:item_display, minecraft:block_display, minecraft:text_display, minecraft:interaction, or the mob's id.

Methods

entity:follow(target: types.Entity, options: types.FollowOptions?)entity:follow(target: types.Player, options: types.FollowOptions?)
#

The host moves this entity toward the target plus offset while the target moves away, and stops when the target is removed or leaves. Following again replaces the target.

local entities = require("@ember/entities")
local players = require("@ember/players")
local types = require("@ember/types")

-- A pet that trails each player. The host moves it, so no script runs per tick. It stops following
-- when the player leaves, but stays in the world, so remove it then.
local pets: { [string]: types.Entity } = {}

players.joined:connect(function(player)
	local pet = entities.item({ at = player.position, item = "minecraft:cookie", billboard = "center" })
	pet:follow(player, { offset = vector.create(1, 1.5, 0), speed = 6 })
	pets[player.id] = pet
end)

players.left:connect(function(player)
	local pet = pets[player.id]
	if pet then
		pet:remove()
		pets[player.id] = nil
	end
end)
entity:remove()
#

Removes it from the world; its handle goes stale.

entity:teleport(to: vector, look: types.Look?)
#

Moves it to to, facing look or the way it faced.

entity:unfollow()
#

Stops following; it stays where it is.