-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainTrax3U_Core.sk
195 lines (152 loc) · 7.71 KB
/
TrainTrax3U_Core.sk
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
options:
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# TrainTrax3U Train Tracker Assistant #
# // Core - Point Zero and Mile Dump #
# #
# Author: MinecraftSBC, blackon108 (Algorithm) #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
build: A17Y14R12
license: Copyright © 2017 SBCRET <[email protected]> under DBAD v1.1 as published by Philip Sturgeon.
function FindTrain(x: integer, y: integer, z: integer, dir: string, itin: integer) :: string:
# Sample Dump >> S,2097;43,mmmmmmmmmmmmmmmmmmmmmm;1414,mmmmmmmmmmmmmmmmmmmmmm
# Explanation: SIGKILL Exit, 2097m Scanned; Mile 43: 22 x minecart; Mile 1414: 22 x minecart
# Turning Info
set {_turn::e} to "s,e,e,e,s,n,e,s,n,e"
set {_turn::s} to "s,w,w,e,s,s,s,s,w,e"
set {_turn::w} to "s,w,w,w,s,n,s,w,w,n"
set {_turn::n} to "n,w,w,e,n,n,e,w,n,n"
# Location Init
set {_loc} to location({_x},{_y},{_z},world "world")
set {_cdir} to {_dir}
# Train Config Init
set {_train_config} to ""
# Output Init.
set {_trains} to ""
loop {_itin} times:
# Items to check
set {_has_rail} to false
set {_has_train} to false
loop blocks between block 3 blocks above {_loc} and block 3 blocks below {_loc}:
if loop-block is powered rail or detector rail or rail or pressure plate:
# Continuous Track
set {_has_rail} to true
set {_loc} to location of loop-block
# Cart check
loop entities in radius 1.5 of {_loc}:
# Linking trains
if loop-entity is minecart:
set {_has_train} to true
# Train occuping half block or more
if distance between loop-entity and {_loc} <= 0.665:
if loop-entity is chest minecart:
set {_train_config} to "%{_train_config}%c"
stop this section
else if loop-entity is hopper minecart:
set {_train_config} to "%{_train_config}%h"
stop this section
else if loop-entity is furnace minecart:
set {_train_config} to "%{_train_config}%f"
stop this section
else if loop-entity is TNT minecart:
set {_train_config} to "%{_train_config}%t"
stop this section
else if loop-entity is minecart:
set {_train_config} to "%{_train_config}%m"
stop this section
# Move Prep
if loop-block is (powered rail or detector rail or pressure plate):
set {_next_dir} to {_cdir}
else:
set {_t::*} to {_turn::%{_cdir}%} split at ","
set {_next_dir} to {_t::%data value of loop-block + 1%}
stop this section
# Train disconnected
if {_has_train} = false:
if length of {_train_config} > 0:
replace all "<none>" with "" in {_trains}
replace all "<none>" with "" in {_train_config}
set {_trains} to "%{_trains}%;%loop-number - 1%,%{_train_config}%"
set {_train_config} to ""
# Duploc Exit
if loop-number > 2:
if distance between location({_x},{_y},{_z},world "world") and {_loc} <= 1.25:
return "D,%loop-number%%{_trains}%"
# EOL Exit
if {_has_rail} = false:
return "E,%loop-number%%{_trains}%"
# Move
if {_next_dir} = "e":
set {_loc} to location 1 meter east of {_loc}
else if {_next_dir} = "s":
set {_loc} to location 1 meter south of {_loc}
else if {_next_dir} = "w":
set {_loc} to location 1 meter west of {_loc}
else if {_next_dir} = "n":
set {_loc} to location 1 meter north of {_loc}
set {_cdir} to {_next_dir}
# SIGKILL Exit
return "S,%{_itin}%%{_trains}%"
function FindMile(x: integer, y: integer, z: integer, dir: string, itin: integer) :: string:
# Sample Dump >> S,2;1,179,43,697,n,r,0;2,179,43,696,n,r,0
# Explanation: SIGKILL Exit, 2 m scanned; Mile 1 - Loc(179,43,697) [N] rail:0; Mile 2 - Loc(179,43,696) [N] rail:0
# Turning Info
set {_turn::e} to "s,e,e,e,s,n,e,s,n,e"
set {_turn::s} to "s,w,w,e,s,s,s,s,w,e"
set {_turn::w} to "s,w,w,w,s,n,s,w,w,n"
set {_turn::n} to "n,w,w,e,n,n,e,w,n,n"
# Location Init
set {_loc} to location({_x},{_y},{_z},world "world")
set {_cdir} to {_dir}
# Output Init
set {_output} to ""
loop {_itin} times:
# Items to check
set {_has_rail} to false
loop blocks between block 3 blocks above {_loc} and block 3 blocks below {_loc}:
if loop-block is powered rail or detector rail or rail or pressure plate:
# Continuous Track
set {_has_rail} to true
set {_loc} to location of loop-block
# Check Rail Type
if loop-block is powered rail:
set {_rail_type} to "p"
else if loop-block is detector rail:
set {_rail_type} to "d"
else if loop-block is pressure plate:
set {_rail_type} to "s"
else:
set {_rail_type} to "r"
# Write to output
set {_output} to "%{_output}%;%loop-number%,%x coordinate of {_loc}%,%y coordinate of {_loc}%,%z coordinate of {_loc}%,%{_cdir}%,%{_rail_type}%,%data value of loop-block%"
# Move Prep
if loop-block is (powered rail or detector rail or pressure plate):
set {_next_dir} to {_cdir}
else:
set {_t::*} to {_turn::%{_cdir}%} split at ","
set {_next_dir} to {_t::%data value of loop-block + 1%}
stop this section
# Duploc Exit
if loop-number > 2:
if distance between location({_x},{_y},{_z},world "world") and {_loc} <= 1.25:
return "D,%loop-number%%{_output}%"
# EOL Exit
if {_has_rail} = false:
return "E,%loop-number%%{_output}%"
# Move
if {_next_dir} = "e":
set {_loc} to location 1 meter east of {_loc}
else if {_next_dir} = "s":
set {_loc} to location 1 meter south of {_loc}
else if {_next_dir} = "w":
set {_loc} to location 1 meter west of {_loc}
else if {_next_dir} = "n":
set {_loc} to location 1 meter north of {_loc}
set {_cdir} to {_next_dir}
# SIGKILL Exit
return "S,%{_itin}%%{_output}%"
function FindTrainS(x: string) :: string:
set {_args::*} to {_x} split at " "
if size of {_args::*} = 5:
return FindTrain({_args::1} parsed as integer, {_args::2} parsed as integer, {_args::3} parsed as integer, {_args::4}, {_args::5} parsed as integer)
else:
return ""