-
Notifications
You must be signed in to change notification settings - Fork 2
/
World_gen.py
165 lines (153 loc) · 5.4 KB
/
World_gen.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import os.path, data
from random import randint
def main(WORLD):
level = []
ch = None
rand = 0
crand = 0
gravel_rand = 0
coal_rand = 0
iron_rand = 0
gold_rand = 0
diamond_rand = 0
# Hotbar coords
hot = data.hot
def tree(x, y, trand):
if trand == 1:
ch.append([x,y,100])
ch.append([x,y-1,100])
ch.append([x+1,y-1,101])
ch.append([x-1,y-1,101])
ch.append([x+2,y-1,101])
ch.append([x-2,y-1,101])
ch.append([x,y-2,101])
ch.append([x+1,y-2,101])
ch.append([x-1,y-2,101])
ch.append([x,y-3,101])
elif trand == 2:
ch.append([x,y,100])
ch.append([x,y-1,100])
ch.append([x,y-2,100])
ch.append([x+1,y-2,101])
ch.append([x-1,y-2,101])
ch.append([x+2,y-2,101])
ch.append([x-2,y-2,101])
ch.append([x,y-3,101])
ch.append([x+1,y-3,101])
ch.append([x-1,y-3,101])
ch.append([x,y-4,101])
print("Generating")
for x in range(-128, 128 + 1):
# Start new chunk
if ch == None:
ch = [round(x / 16)]
if x % 16 == 0:
print(round(x / 16))
level.append(ch)
ch = [round(x / 16)]
# World borders
if x == -128 or x == 127:
print(x)
for y in range(48):
ch.append([x,y,4])
ch.append([x,49,5])
ch.append([x,50,5])
else:
# Underground
for y in range(29, 48):
if crand == 0:
crand = randint(1, 1000)
if crand > 50:
if gravel_rand == 0:
gravel_rand = randint(1, 200)
if coal_rand == 0:
coal_rand = randint(1, 200)
if iron_rand == 0:
iorn_rand = randint(1, 100)
if gold_rand == 0:
gold_rand = randint(1, 200)
if diamond_rand == 0:
diamond_rand = randint(1, 300)
if gravel_rand < 10:
ch.append([x,y,19])
elif coal_rand < 10:
ch.append([x,y,6])
elif iorn_rand < 10:
ch.append([x,y,7])
elif gold_rand < 5 and y > 40:
ch.append([x,y,8])
elif diamond_rand < 5 and y > 44:
ch.append([x,y,9])
else:
ch.append([x,y,3])
gravel_rand -= 1
coal_rand -= 1
iorn_rand -= 1
gold_rand -= 1
diamond_rand -= 1
else:
ch.append([x,y,115])
crand -= 1
# Bedrock
if randint(1, 2) == 1:
ch.append([x,48,3])
else:
ch.append([x,48,5])
ch.append([x,49,5])
ch.append([x,50,5])
if x > 120 or x < -120:
if randint(1, 2) == 1:
ch.append([x,28,3])
else:
ch.append([x,28,16])
ch.append([x,27,16])
ch.append([x,26,16])
ch.append([x,25,16])
else:
# Ground level
if rand == 0:
rand = randint(1, 10)
# High
if rand > 4:
ch.append([x,28,3])
if randint(1, 2) == 1:
ch.append([x,27,3])
else:
ch.append([x,27,2])
ch.append([x,26,2])
ch.append([x,25,2])
ch.append([x,24,1])
# Vegitation
trand = randint(1, 50)
if trand < 3:
tree(x, 23, trand)
elif randint(1, 5) == 1:
ch.append([x,23,102])
elif randint(1, 7) == 1:
ch.append([x,23,103])
elif randint(1, 7) == 1:
ch.append([x,23,104])
# Low
else:
if randint(1, 2) == 1:
ch.append([x,28,3])
else:
ch.append([x,28,2])
ch.append([x,27,2])
ch.append([x,26,2])
ch.append([x,25,1])
# Vegitation
trand = randint(1, 50)
if trand < 3:
tree(x, 24, trand)
elif randint(1, 5) == 1:
ch.append([x,24,102])
elif randint(1, 7) == 1:
ch.append([x,24,103])
elif randint(1, 7) == 1:
ch.append([x,24,104])
rand -= 1
# Save
with open(os.path.join("Worlds", WORLD), "w") as f:
f.write('{"Level":' + str(level[1:]) + ', \n"WS":0, "VS":-2000, "X":0, "Y":200, \n"Hot":' + str(hot) + ', \n"Health":10' + '}')
print("Finished")