forked from vlapsley/australia
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.lua
executable file
·50 lines (41 loc) · 941 Bytes
/
functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- mods/australia/functions.lua
-- Create and initialize a table for a schematic.
function aus.schematic_array(width, height, depth)
-- Dimensions of data array.
local s = {size={x=width, y=height, z=depth}}
s.data = {}
for z = 0,depth-1 do
for y = 0,height-1 do
for x = 0,width-1 do
local i = z*width*height + y*width + x + 1
s.data[i] = {}
s.data[i].name = "air"
s.data[i].param1 = 000
end
end
end
s.yslice_prob = {}
return s
end
-- Push an element onto a stack (table).
function push(t, x)
t[#t+1] = x
end
-- Check if the table contains an element.
function table.contains(table, element)
for key, value in pairs(table) do
if value == element then
if key then
return key
else
return true
end
end
end
return false
end
-- Round a number to the given decimal places
function math.round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end