/
common.lua
52 lines (47 loc) · 952 Bytes
/
common.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
49
50
51
52
-- Modes
MENU = 1
GENERATING = 2
PLAY = 3
-- Block codes
AIR = 0
STONE = 1
GRASS = 2
DIRT = 3
COBBLESTONE = 4
COAL_ORE = 16
WOOD = 17
LEAVES = 18
UNGENERATED = 255
durability = {}
durability[STONE] = 2
durability[GRASS] = 1
durability[DIRT] = 1
durability[COBBLESTONE] = 2
durability[COAL_ORE] = 3
durability[WOOD] = 1.5
durability[LEAVES] = 0.3
breakGive = {}
breakGive[STONE] = COBBLESTONE
breakGive[GRASS] = DIRT
breakGive[DIRT] = DIRT
breakGive[COBBLESTONE] = COBBLESTONE
breakGive[COAL_ORE] = COAL_ORE
breakGive[WOOD] = WOOD
breakGive[LEAVES] = nil
-- Random number engine
rand = {mySeed = 1, lastN = -1}
function rand:get(seed, n)
if n <= 0 then n = -2 * n
else n = 2 * n - 1
end
if seed ~= self.mySeed or self.lastN < 0 or n <= self.lastN then
self.mySeed = seed
math.randomseed(seed)
self.lastN = -1
end
while self.lastN < n do
num = math.random()
self.lastN = self.lastN + 1
end
return num - 0.5
end