-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbig_tree.py
More file actions
166 lines (147 loc) · 4.61 KB
/
big_tree.py
File metadata and controls
166 lines (147 loc) · 4.61 KB
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
166
import os
import random
import amulet
from amulet.api.block import Block
from amulet.api.chunk import Chunk
os.system("clear")
# load the level
# this will automatically find the wrapper that can open the world and set everything up for you.
level = amulet.load_level(
"/Users/john/Library/Application Support/minecraft/saves/New Adventure!!"
)
game_version = ("java", (1, 19, 3)) # the version that we want the block data in.
tree_x_offset = 40
tree_y_offset = 70
tree_z_offset = -40
# define the size of the column
tree_width = 14
height = 290
# get the jungle log block
jungle_log = Block("minecraft", "jungle_log")
jungle_stairs = Block("minecraft", "jungle_stairs")
air = Block("minecraft", "air")
stair_lookup = [
[[3, 0], [2, 0]],
[[3, -1], [2, -1]],
[[3, -2], [2, -2], [2, -3]],
[[1, -2], [1, -3]],
[[0, -2], [0, -3]],
[[-1, -2], [-1, -3]],
[[-2, -2], [-2, -3], [-3, -2]],
[[-2, -1], [-3, -1]],
[[-2, 0], [-3, 0]],
[[-2, 1], [-3, 1]],
[[-2, 2], [-2, 3], [-3, 2]],
[[-1, 2], [-1, 3]],
[[0, 2], [0, 3]],
[[1, 2], [1, 3]],
[[2, 2], [2, 3], [3, 2]],
[[2, 1], [3, 1]],
]
probLookup = {
32: 0.95,
34: 0.9,
36: 0.9,
37: 0.5,
40: 0.2,
41: 0.1,
45: 0.05,
49: 0.05,
}
def make_trunk():
stair_counter = 0
# place the jungle logs in a column
for y in range(tree_y_offset, height):
for x in range(-tree_width // 2, tree_width // 2):
for z in range(-tree_width // 2, tree_width // 2):
hypotSq = x**2 + z**2
if abs(x) == 3 and abs(z) == 3:
level.set_version_block(
x + tree_x_offset,
y,
z + tree_z_offset,
"minecraft:overworld", # dimension
game_version,
jungle_log,
)
elif abs(x) <= 3 and abs(z) <= 3:
level.set_version_block(
x + tree_x_offset,
y,
z + tree_z_offset,
"minecraft:overworld", # dimension
game_version,
air,
)
elif hypotSq < 30:
level.set_version_block(
x + tree_x_offset,
y,
z + tree_z_offset,
"minecraft:overworld", # dimension
game_version,
jungle_log,
)
else:
if random.random() < probLookup.get(hypotSq, 0):
level.set_version_block(
x + tree_x_offset,
y,
z + tree_z_offset,
"minecraft:overworld", # dimension
game_version,
jungle_log,
)
# staircase block
for p in stair_lookup[stair_counter % len(stair_lookup)]:
level.set_version_block(
tree_x_offset + p[0],
y,
tree_z_offset + p[1],
"minecraft:overworld", # dimension
game_version,
jungle_log,
)
stair_counter += 1
# # save the changes to the world
make_trunk()
level.save()
level.close()
# make branch
def branch_slice(axis, x_origin, y_origin, z_origin):
is_x = axis == "x"
for p in [[0, -2], [-1, -1], [-2, 0], [-1, 1], [0, 2], [1, 1], [2, 0], [1, -1]]:
level.set_version_block(
x_origin + (p[0] if is_x else 0),
y_origin + p[1],
z_origin + (0 if is_x else p[0]),
"minecraft:overworld", # dimension
game_version,
jungle_log,
)
def make_branch(axis, direction, startX, startY, startZ, height):
is_x = axis == "x"
# NB slice axis is orthogonal to branch axis
slice_axis = "z" if is_x else "x"
for ix in range(height):
delta = direction * ix
x = startX + delta if is_x else startX
z = startZ if is_x else startZ + delta
branch_slice(
slice_axis,
x,
startY + ix,
z,
)
# for i in range(18):
# make_branch(
# random.choice(["z", "x"]),
# random.choice([1, -1]),
# tree_x_offset,
# tree_y_offset + random.randint(40, 260),
# tree_z_offset,
# random.randint(15, 70),
# )
# # # save the changes to the world
# level.save()
# level.close()