1
+ command_block_X = - 8
2
+ command_block_Y = 4
3
+ command_block_Z = - 17
4
+
5
+ def command_block (cmd : str , Number : int ):
6
+ row_length = 16
7
+ layer_size = row_length * row_length
8
+
9
+ layer = Number // layer_size
10
+ num_in_layer = Number % layer_size
11
+
12
+ reverse_x = layer % 2 == 1
13
+ turn_facing = "east" if layer % 2 == 0 else "west"
14
+
15
+ pair_index = num_in_layer // (2 * row_length )
16
+ offset_in_pair = num_in_layer % (2 * row_length )
17
+
18
+ # 计算 base_x/z 起点
19
+ def last_block_pos (layer_idx ):
20
+ prev_reverse = layer_idx % 2 == 1
21
+ pair_index = (layer_size - 1 ) // (2 * row_length )
22
+ offset_in_pair = (layer_size - 1 ) % (2 * row_length )
23
+
24
+ x = command_block_X + pair_index * 2
25
+ if offset_in_pair >= row_length :
26
+ x += 1
27
+ if prev_reverse :
28
+ x = command_block_X + (row_length - 1 ) - (x - command_block_X )
29
+
30
+ if offset_in_pair < row_length :
31
+ z = command_block_Z - offset_in_pair
32
+ else :
33
+ z = command_block_Z - (row_length - 1 ) + (offset_in_pair - row_length )
34
+
35
+ return x , z
36
+
37
+ if layer == 0 :
38
+ base_x , base_z = command_block_X , command_block_Z
39
+ else :
40
+ base_x , base_z = last_block_pos (layer - 1 )
41
+
42
+ x_offset = pair_index * 2 + (1 if offset_in_pair >= row_length else 0 )
43
+ x = base_x + x_offset if not reverse_x else base_x - x_offset
44
+
45
+ if offset_in_pair < row_length :
46
+ z = base_z - offset_in_pair
47
+ facing = "north"
48
+ else :
49
+ z = base_z - (row_length - 1 ) + (offset_in_pair - row_length )
50
+ facing = "south"
51
+
52
+ # 行尾:换方向(east/west 交替)
53
+ if offset_in_pair in [row_length - 1 , 2 * row_length - 1 ]:
54
+ facing = turn_facing
55
+
56
+ # 最后一格:朝向 up
57
+ if num_in_layer == layer_size - 1 :
58
+ facing = "up"
59
+
60
+ y = command_block_Y + layer
61
+
62
+ # 设置方块类型
63
+ if Number == 0 :
64
+ block_id = "command_block"
65
+ else :
66
+ block_id = "chain_command_block"
67
+ block_id = "command_block"
68
+ # chain 的 NBT:auto=1b 保持开启
69
+ #nbt_auto = ",auto:1b" if block_id == "chain_command_block" else ""
70
+ nbt_auto = ""
71
+
72
+ return f'setblock { x } { y } { z } minecraft:{ block_id } [facing={ facing } ]{{Command:"{ cmd } "{ nbt_auto } }} replace'
73
+
74
+
75
+
76
+ with open ('commands.mcfunction' , 'w' ) as f :
77
+ for i in range (0 , 1 ):
78
+ f .write (f'{ command_block (f"particleex image minecraft:end_rod -10 5 20 { i } .png 0.1 0 0 0 horizontally 10 0 0 0 1" ,i )} \n ' )
0 commit comments