Minecraft (mc)

Player and world

The player, blocks, entities and inventory.

Player

mc.getPlayer()

Returns a table with your player's state, or nil when there is no player.

Fields used by the built-in libraries:

FieldMeaning
x, y, zPosition (feet)
eyeYY of the eyes
yaw, pitchWhere you are looking, in degrees
vx, vy, vzVelocity
onGroundWhether you are on the ground
slotSelected hotbar slot (0 to 8)

Other fields (health and so on) come from the native layer.

Blocks

mc.getBlock(x, y, z)

Returns information about the block at the position, or nil. Coordinates are rounded down to whole numbers. You can also pass one table: mc.getBlock(Vector3.new(10, 64, 10)).

Raises an error if a coordinate is not a finite number, if x or z is beyond 30,000,000, or if y is beyond 4096.

Entities

mc.getEntities(opts)

Returns an array of nearby entities.

OptionDefaultMeaning
range64Maximum distance in blocks
playerstrueInclude players. Pass false to leave them out
hostiletrueInclude hostile mobs. Pass false to leave them out
passivefalsePass true to include passive mobs
otherfalsePass true to include everything else

Fields used by the built-in libraries: id, name, x, y, z, distance, height.

for _, e in ipairs(mc.getEntities({ range = 20 })) do
  print(e.name, math.floor(e.distance))
end

mc.getEntity(id)

Returns the entity with that ID, or nil. id must be a signed 32-bit integer, otherwise an error is raised.

mc.distance(a, b)

Returns the 3D distance between two positions. Each can be a Vector3 or any table with x, y, z.

Inventory

mc.getInventory()

Returns every inventory slot, including each item's ID and name.

mc.getItem(slot)

Returns the item in a slot, or nil. Slots start at 0: 0 to 8 is the hotbar. Items have at least name and count.

mc.hotbar()

Returns an array of 9 entries (index 1 to 9). Each is an item table, or false for an empty slot.

for i, item in ipairs(mc.hotbar()) do
  print(i, item and item.name or "empty")
end

See also the Inv helpers.