SHOW:
|
|
- or go back to the newest paste.
1 | modem = peripheral.wrap("left") | |
2 | modem.open(403) | |
3 | ||
4 | modem.transmit(403, 403, "listening-port") | |
5 | print("listening for port") | |
6 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
7 | port = message | |
8 | modem.open(port) | |
9 | print("opened port") | |
10 | modem.close(403) | |
11 | ||
12 | modem.transmit(port, port, "listening-position") | |
13 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
14 | distanceToGo = message | |
15 | ||
16 | print(distanceToGo) | |
17 | ||
18 | fullSlotCounter = 0 | |
19 | ||
20 | ||
21 | ||
22 | function await(x) | |
23 | awaitVar = true | |
24 | while awaitVar == true do | |
25 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
26 | if message == x then | |
27 | awaitVar = false | |
28 | end | |
29 | end | |
30 | end | |
31 | ||
32 | ||
33 | function checkFuel() | |
34 | if turtle.getFuelLevel() < 401 then | |
35 | turtle.select(14) | |
36 | turtle.refuel(8) | |
37 | turtle.select(1) | |
38 | end | |
39 | end | |
40 | ||
41 | function enderChests() | |
42 | -- Unload slot 1 - 13 | |
43 | turtle.dig() | |
44 | turtle.select(15) | |
45 | turtle.place() | |
46 | for i = 1, 13 , 1 do | |
47 | turtle.select(i) | |
48 | turtle.drop() | |
49 | end | |
50 | turtle.select(15) | |
51 | turtle.dig() | |
52 | ||
53 | -- Load Slot 14 with coal | |
54 | turtle.select(16) | |
55 | turtle.place() | |
56 | ||
57 | if turtle.getItemCount(14) < 64 then | |
58 | turtle.select(14) | |
59 | turtle.suck(64 - turtle.getItemCount(14)) | |
60 | end | |
61 | ||
62 | turtle.select(16) | |
63 | turtle.dig() | |
64 | end | |
65 | ||
66 | ||
67 | function checkInv() | |
68 | if turtle.getItemCount(14) < 2 then | |
69 | enderChests() | |
70 | else | |
71 | for i = 1, 13, 1 do | |
72 | if turtle.getItemCount(i) > 0 then | |
73 | fullSlotCounter = fullSlotCounter + 1 | |
74 | end | |
75 | end | |
76 | if fullSlotCounter > 10 then | |
77 | enderChests() | |
78 | end | |
79 | end | |
80 | fullSlotCounter = 0 | |
81 | ||
82 | checkFuel() | |
83 | end | |
84 | ||
85 | ||
86 | function getInPostion() | |
87 | for i = 1, distanceToGo, 1 do | |
88 | while turtle.detect() do | |
89 | turtle.dig() | |
90 | end | |
91 | turtle.forward() | |
92 | print(i) | |
93 | end | |
94 | turtle.turnLeft() | |
95 | print("aqquired position") | |
96 | end | |
97 | ||
98 | ||
99 | function acceptOrder() | |
100 | print("ready for parameters") | |
101 | ||
102 | await("values-incoming") | |
103 | ||
104 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
105 | width = message | |
106 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
107 | height = message | |
108 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message") | |
109 | depth = message | |
110 | end | |
111 | ||
112 | ||
113 | function executeOrder() | |
114 | checkInv() | |
115 | ||
116 | for z = 1, depth, 1 do | |
117 | - | if z % 2 == 0 then |
117 | + | turtle.turnRight() |
118 | for y = 1, height, 1 do | |
119 | checkInv() | |
120 | - | for y = 1, height, 1 do |
120 | + | for x = 1, width - 1, 1 do |
121 | - | turtle.digUp() |
121 | + | while turtle.detect() do |
122 | - | turtle.up() |
122 | + | turtle.dig() |
123 | - | checkInv() |
123 | + | end |
124 | turtle.forward() | |
125 | end | |
126 | if y < height then | |
127 | while turtle.detectUp() do | |
128 | turtle.digUp() | |
129 | end | |
130 | - | for i = 1, height, 1 do |
130 | + | turtle.turnLeft() |
131 | - | turtle.digDown() |
131 | + | turtle.turnLeft() |
132 | - | turtle.down() |
132 | + | turtle.up() |
133 | - | checkInv() |
133 | + | |
134 | end | |
135 | ||
136 | for i = 1, height - 1, 1 do | |
137 | turtle.digDown() | |
138 | turtle.down() | |
139 | end | |
140 | if (depth % 2) == 1 then | |
141 | turtle.turnRight() | |
142 | turtle.turnRight() | |
143 | for i = 1, width - 1, 1 do | |
144 | turtle.forward() | |
145 | end | |
146 | end | |
147 | ||
148 | if z == depth then | |
149 | turtle.turnRight() | |
150 | turtle.turnRight() | |
151 | turtle.turnRight() | |
152 | turtle.dig() | |
153 | enderChests() | |
154 | else | |
155 | turtle.turnRight() | |
156 | turtle.dig() | |
157 | turtle.forward() | |
158 | end | |
159 | end | |
160 | end | |
161 | ||
162 | ||
163 | function goHome() | |
164 | for i = 1, depth - 1, 1 do | |
165 | checkInv() | |
166 | turtle.dig() | |
167 | turtle.forward() | |
168 | end | |
169 | turtle.turnLeft() | |
170 | modem.transmit(port, port, "arrived-home") | |
171 | end | |
172 | ||
173 | ||
174 | -- Actual program | |
175 | turtle.turnLeft() | |
176 | checkInv() | |
177 | turtle.turnRight() | |
178 | ||
179 | getInPostion() | |
180 | acceptOrder() | |
181 | executeOrder() | |
182 | ||
183 | goHome() |