World

getBlock(x, y, z)

Gets information about a block by coordinates.

Parameters:

  • x (number) - X cordinate.

  • y (number) - Y cordinate.

  • z (number) - Z cordinate.

Returns:

Example Usage:

-- Example code showing how to use the function
local blockInfo = world.getBlock(1, 1, 1)

setBlock(x, y, z, id)

Sets the block to the desired coordinates.

Parameters:

  • x (number) - X cordinate.

  • y (number) - Y cordinate.

  • z (number) - Z cordinate.

  • id (number) - Raw block id.

Example Usage:

-- Example code showing how to use the function
world.setBlock(1, 1, 1, 1) -- Set stone to 1, 1, 1

getEntities()

Returns a list of entities.

Returns:

Example Usage:

-- Example code showing how to use the function
local entities = world.getEntities()

for index, entity in ipairs(entities) do
    if entity ~= nil then
        local entityName = entity.name
        local entityId = entity.id
        
        print(string.format("Entity %d: %s", 
              index, entityName))
    end
end

getLivingEntities()

Returns a list of entities.

Returns:

Example Usage:

-- Example code showing how to use the function
local entities = world.getLivingEntities()

for index, entity in ipairs(entities) do
    if entity ~= nil then
        local entityName = entity.name
        local entityId = entity.id
        
        print(string.format("Entity %d: %s", 
              index, entityName))
    end
end

getEntityById(id)

Returns a list of entities.

Parameters:

  • id (number) - Entity id.

Returns:

Example Usage:

-- Example code showing how to use the function
local entity = world.getEntityById(0)
if entity then
    local entityName = entity.name
    local entityId = entity.id
        
    print(string.format("Entity %d: %s", 
          index, entityName))
end

getRotation(x, y, z)

Get yaw and pitch for 3d cordinates.

Parameters:

  • x (number) - X cordinate.

  • y (number) - Y cordinate.

  • z (number) - Z cordinate.

Returns:

  • (table) Return table (yaw, pitch)

Example Usage:

-- Example code showing how to use the function
local rotation = world.getRotation(1, 1, 1)
player.setRotation(rotation.yaw, rotation.pitch)

raycast(obj)

Return raycast result.

Parameters:

  • obj (table).

Returns:

  • (table) Return table

Example Usage:

-- Example code showing how to use the function
local eyePos = player.getEyePosition()
local targetX, targetY, targetZ = 0, 0, 0
local raycastResult = world.raycast({
    startX = eyePos.x,
    startY = eyePos.y, 
    startZ = eyePos.z,
    endX = targetX + 0.5,
    endY = targetY + 0.5,
    endZ = targetZ + 0.5
})

if raycastResult ~= nil then
    if raycastResult.type == "block" then
        local block = world.getBlock(raycastResult.blockPos.x, raycastResult.blockPos.y, raycastResult.blockPos.z)
        player.addMessage("Block: " .. raycastResult.blockPos.x .. ", " .. raycastResult.blockPos.y .. ", " .. raycastResult.blockPos.z .. " | " .. block.name)
    elseif raycastResult.type == "entity" then
        player.addMessage("Entity: " .. raycastResult.data.name)
    elseif raycastResult.type == "miss" then
        player.addMessage("Miss")
    end
end

Last updated