-
Notifications
You must be signed in to change notification settings - Fork 4
/
cart.py
82 lines (70 loc) · 2.77 KB
/
cart.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
import sands
import nbtencoder as nbt
from classes import Command, FakeCommand
from wireutils import color_print, format, ansi_colors
def ride(entities, have_id=True):
bottommost = entities[0]
bottommost["Passengers"] = entities[1:]
if not have_id: del bottommost["id"]
return bottommost
def cart(command):
return {
"id": nbt.noquote_str("commandblock_minecart"),
"Command": command
}
def cart_block(offset, block, damage=0, data={}):
cmd = format("setblock ~ ~{offset} ~ {block} {dmg} replace", block=block, dmg=damage)
if offset: cmd = format(cmd, offset=offset)
else: cmd = format(cmd, offset="")
if data: cmd = nbt.cmd(cmd, data, True)
return cart(cmd)
def cart_command_block(offset, command_obj, direction=0, mode='i'):
if isinstance(command_obj, FakeCommand):
return cart_block(offset, command_obj.block, command_obj.data)
tag = {
"Command": str(command_obj),
"TrackOutput": nbt.int_b(0)
}
if command_obj.block == "chain_command_block" or (mode == 'i' and command_obj.block == "repeating_command_block"):
tag["auto"] = 1
data = direction+8 if command_obj.cond else direction
return cart_block(offset, command_obj.block, data, tag)
def gen_cart_stack(init_commands, clock_commands, mode, loud=False):
final_command_obj = None
if clock_commands or init_commands:
entities = []
entities.append(sands.normal_sand("activator_rail"))
for command in init_commands:
if hasattr(command, "cmd"):
if loud:
color_print(command.prettystr())
entities.append(cart(command.cmd))
offset = 1
for command in clock_commands:
if offset == 1:
command.block = "repeating_command_block"
if loud:
color_print(command.prettystr())
entities.append(cart_command_block(offset, command, 1, mode))
offset += 1
filloffset = offset+1
offset += 2
entities.append(cart_command_block(offset, Command(format("clone ~ ~-2 ~ ~ ~-{o1} ~ ~ ~-{o2} ~ replace move", o1=offset-1,o2=offset+2))))
offset += 1
entities.append(cart_command_block(offset, Command(format("fill ~ ~-{o1} ~ ~ ~-{o2} ~ air", o1=offset,o2=offset+2))))
offset += 1
activatesand = sands.normal_sand("command_block")
activatesand["TileEntityData"] = {"auto": 1}
entities.append(cart_block(offset, "air"))
entities.append(cart(nbt.cmd(format("summon falling_block ~ ~{o} ~ ", o=offset), activatesand, True)))
entities.append(cart_command_block(filloffset, Command(format("fill ~ ~ ~ ~ ~{o} ~ air", o=offset-filloffset))))
entities.append(cart("kill @e[r=1,type=commandblock_minecart]"))
stack = ride(entities)
final_stack = sands.ride([
stack,
sands.normal_sand("redstone_block"),
sands.normal_sand("barrier")
], False)
final_command_obj = nbt.cmd("summon falling_block ~ ~1 ~ ", final_stack)
final_command = nbt.JSON2Command(final_command_obj)
return final_command