44 lines
1,002 B
Lua
44 lines
1,002 B
Lua
blockgame.vector = blockgame.vector or {}
|
|
local api = blockgame.vector
|
|
|
|
-- TODO: replace direct sharing of api variables such as `sides` with functions that return them, to prevent other mods from mutating the shared data.
|
|
|
|
api.horizontal_directions = {
|
|
west = vector.new(-1, 0, 0),
|
|
east = vector.new(1, 0, 0),
|
|
south = vector.new(0, 0, -1),
|
|
north = vector.new(0, 0, 1),
|
|
}
|
|
api.sides = api.horizontal_directions
|
|
|
|
api.directions = {
|
|
west = vector.new(-1, 0, 0),
|
|
east = vector.new(1, 0, 0),
|
|
down = vector.new(0, -1, 0),
|
|
up = vector.new(0, 1, 0),
|
|
south = vector.new(0, 0, -1),
|
|
north = vector.new(0, 0, 1),
|
|
}
|
|
api.dirs = api.directions
|
|
|
|
|
|
|
|
function api.random_dir ()
|
|
return blockgame.random_element(api.dirs)
|
|
end
|
|
|
|
function api.random_side ()
|
|
return blockgame.random_element(api.sides)
|
|
end
|
|
|
|
function api.get_below (pos)
|
|
return pos + api.dirs.down
|
|
end
|
|
|
|
function api.get_sides_of (pos)
|
|
local result = {}
|
|
for _, side in pairs(api.sides) do
|
|
table.insert(result, pos + side)
|
|
end
|
|
return result
|
|
end
|