-
Notifications
You must be signed in to change notification settings - Fork 4
/
sands.py
109 lines (94 loc) · 3.36 KB
/
sands.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
from classes import Command, FakeCommand
from wireutils import color_print, format, ansi_colors
import nbtencoder as nbt
def ride(entities, have_id=True):
bottommost = None
absoluteBottommost = None
for entity in entities[::-1]:
if bottommost == None:
absoluteBottommost = entity
else:
bottommost["Passengers"] = [entity]
bottommost = entity
if not have_id: del absoluteBottommost["id"]
return absoluteBottommost
def generate_sand(command_obj, direction):
if isinstance(command_obj, FakeCommand):
return normal_sand(command_obj.block, command_obj.data)
tag = {
"Block": nbt.noquote_str(command_obj.block),
"TileEntityData": {
"Command": str(command_obj),
"TrackOutput": nbt.int_b(0)
},
"DropItem":0,
"Time": 1,
"id": nbt.noquote_str("falling_block")
}
data = direction+8 if command_obj.cond else direction
if data:
tag["Data"] = data
return tag
def normal_sand(block, data=0):
tag = {
"Block": nbt.noquote_str(block),
"Time": 1,
"DropItem":0,
"id": nbt.noquote_str("falling_block")
}
if data:
tag["Data"] = data
return tag
def gen_stack(init_commands, clock_commands, mode, loud=False):
final_command_obj = None
if clock_commands or init_commands:
command_sands = []
repeatoffsets = []
if mode == 'i':
if clock_commands and isinstance(clock_commands[0], Command):
repeatoffsets.append(len(clock_commands) + 2)
for command in clock_commands:
if command.block == "repeating_command_block" and not command.cond and command is not clock_commands[0]:
repeatoffsets.append(len(clock_commands) - clock_commands.index(command) + 2 + len(repeatoffsets))
filloffset = len(init_commands) + len(repeatoffsets)
if filloffset: filloffset += 1
if filloffset:
if loud:
color_print("minecraft:command_block:0\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True)
sand = normal_sand("command_block")
if mode == 'i':
sand["TileEntityData"] = {
"auto": 1
}
command_sands.append(sand)
for command in init_commands:
if loud:
color_print(command.prettystr(), allow_repeat=True)
command_sands.append(generate_sand(command, 0))
for offset in repeatoffsets[::-1]:
blockdata = Command(format("blockdata ~ ~-{offset} ~ {auto:1b}", offset = offset), init=True)
if loud:
color_print(blockdata.prettystr(), allow_repeat=True)
sand = generate_sand(blockdata, 0)
command_sands.append(sand)
if filloffset:
fill = Command(format("fill ~ ~-1 ~ ~ ~{offset} ~ air", offset = filloffset), init=True)
if loud:
color_print(fill.prettystr(), allow_repeat=True)
color_print("minecraft:barrier\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True)
command_sands.append(generate_sand(fill, 0))
command_sands.append(normal_sand("barrier"))
for command in clock_commands[::-1]:
if command is clock_commands[0] and isinstance(command, Command):
command.block = "repeating_command_block"
command_sands.append(generate_sand(command, 1))
else:
sand = generate_sand(command, 1)
if command.block == "repeating_command_block" and command.cond:
sand["TileEntityData"]["auto"] = 1
command_sands.append(sand)
if loud:
color_print(command.prettystr(), allow_repeat=True)
final_command_obj = nbt.cmd("summon falling_block ~ ~1 ~ ", ride(command_sands, False))
final_command = nbt.JSON2Command(final_command_obj)
return final_command