Skip to main content

Players and Entities

The functions on this page accept entity handles returned by player, an entity query, or an event. Test for null before reading a handle that might be missing.

Find an entity​

Call under mc.entitiesResult
player()The app's player or the player executing the command. If neither exists, it looks for the nearest living player.
player(name)An online player by name, or null.
player("all")All online players across dimensions as an array.
player("*"), player("survival"), player("creative"), player("spectating")A player array filtered in the current dimension. "survival" includes Adventure mode.
entity_id(idOrUuid)Looks up a loaded entity by numeric ID or UUID in the current dimension.
entity_list(descriptor)Loaded entities that match a type or descriptor such as "minecraft:cow" or "living".
entity_area(descriptor, center, range)Entities in a box expanded by [dx, dy, dz] around a position or entity.
entity_selector(selector)An array that matches a Minecraft selector using the current command context.
entity_types([descriptor])Registered types matching a descriptor. Omitting it lists all types.
function onlinePositions() {
return mc.entities.player("all").map(player => ({
name: mc.entities.query(player, "name"),
pos: mc.entities.query(player, "pos"),
dimension: mc.entities.query(player, "dimension")
}));
}

Read, change, or spawn​

Call under mc.entitiesUse
query(entity, property, ...args)Reads a property. Common keys include name, uuid, id, type, pos, motion, dimension, health, yaw, and pitch.
modify(entity, property, ...args)Changes a supported property and returns the entity handle. Common writable keys include pos, motion, yaw, pitch, health, and custom_name.
spawn(type, pos[, nbt])Spawns a summonable entity in the current dimension. Optional NBT can be SNBT text or an NBT handle. Returns an entity handle or null if the spawn fails.
entity_event(entity, name, callback, ...args)Watches one entity. Pass null to remove the callback. See entity event arguments.
entity_load_handler(descriptor, callback, ...args)Watches an entity type as its entities are added to the world. The callback receives (entity, created) before any bound arguments. Pass null to remove the handler.

Position and motion values are arrays. For example, mc.entities.modify(entity, "motion", [0, 0.3, 0]) sets vertical velocity. health is meaningful for living entities.