49 lines
1.1 KiB
Lua
49 lines
1.1 KiB
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_neighbors (pos, neighborhood)
|
|
neighborhood = neighborhood or blockgame.vector.dirs
|
|
local neighbors = {}
|
|
for _, dir in pairs(neighborhood) do
|
|
table.insert(neighbors, pos + dir)
|
|
end
|
|
return neighbors
|
|
end
|
|
|
|
function api.get_sides_of (pos)
|
|
return api.get_neighbors(pos, api.sides)
|
|
end
|