850d397a97
change the way some functions are declared.
47 lines
938 B
Lua
47 lines
938 B
Lua
blockgame.vector = blockgame.vector or {}
|
|
local api = blockgame.vector
|
|
|
|
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
|
|
|
|
local function get_keys (tab)
|
|
local keyset = {}
|
|
local n = 0
|
|
for key, value in pairs(tab) do
|
|
n = n + 1
|
|
keyset[n] = key
|
|
end
|
|
return keyset
|
|
end
|
|
|
|
local function random_element (tab)
|
|
local keys = get_keys(tab)
|
|
return tab[keys[math.random(#keys)]]
|
|
end
|
|
|
|
function api.random_dir ()
|
|
return random_element(api.dirs)
|
|
end
|
|
|
|
function api.random_side ()
|
|
return random_element(api.sides)
|
|
end
|
|
|
|
function api.get_below (pos)
|
|
return pos + api.dirs.down
|
|
end
|