blockgame/mods/bg_api/util_vector.lua
trans_soup a2ab91c992 fix math.random usage.
fix usage of `math.random` in various places to provide both a minimum
and a maximum number, instead of just maximum.

also renamed some files very slightly.
2023-10-13 13:17:14 +02:00

36 lines
855 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