View difference between Paste ID: pNEtNz5e and ZismgCi5
SHOW: | | - or go back to the newest paste.
1
heading = 1
2
rHeading = 1
3
4
pos = vector.new(0,0,0)
5
lPos = vector.new(0,0,0)
6
7
tgted = false
8
unloading = false
9
tgt = vector.new(0,0,0)
10
11
waypoints = {}
12
waypoints['dockUnl'] = vector.new(-2,0,2)
13
waypoints['unload'] = vector.new(-2,0,1)
14-
function moveToTgt() 
14+
waypoints['retP'] = vector.new(0,0,1) 
15-
 if pos.x > tgt.x then
15+
16-
  
16+
function chkInv()
17
if unloading ~= true then
18
19
itmQ = 0
20-
function move(Int, Bool)
20+
 for a = 2, 16 do
21-
 if (Int == 1) then
21+
  itmQ = itmQ + turtle.getItemCount(a) 
22-
   
22+
23
print(' item count = ', itmQ)
24
 if itmQ > 600 then
25
  print('  returning to unload')
26
  lPos = vector.new(pos.x, pos.y, pos.z)
27
  rHeading = heading
28
  unloadTime()
29
 end 
30
end
31
end
32
33
function unloadTime()
34
 unloading = true
35
 moveToTgt(waypoints['dockUnl'])
36
 moveToTgt(waypoints['unload'])
37
 for a = 2, 16 do
38
  turtle.select(a) 
39
  turtle.drop()
40
 end
41
 moveToTgt(waypoints['dockUnl'])
42-
 while Int ~= heading do
42+
  print('returning to ', lPos.x, "x",lPos.y, "x",lPos.z)
43
 moveToTgt(lPos)
44
 rot(rHeading)
45
 unloading = false
46
end
47
48
function moveToTgt(Vector) 
49
 tgt = Vector
50
 tgted = true
51
 while (pos.x ~= tgt.x) or (pos.y ~= tgt.y) or (pos.z ~= tgt.z) do
52
  if pos.x > tgt.x then
53
   move(4)
54
  elseif pos.x < tgt.x then
55
   move(2)
56
  end
57
  if pos.y > tgt.y then
58
   move(5)
59
  elseif pos.y < tgt.y then
60
   move(6)
61
  end
62
  if pos.z > tgt.z then
63
   move(3)
64
  elseif pos.z < tgt.z then
65
   move(1)
66
  end
67-
    pos.z = pos.z - 1
67+
68
end
69
70
function move(Int)
71
 
72
 if (Int > 0) and (Int < 5) then
73
  rot(Int)
74
  Fwd(1)
75
 elseif Int == 5 then
76
  chkInv()
77
  ChkFuel()
78
  turtle.digDown()
79
  turtle.down()
80
  chngCoord(5)
81
 elseif Int == 6 then
82
  chkInv()
83
  ChkFuel()
84
  turtle.digUp()
85
  turtle.up()
86
  chngCoord(6)
87
 end
88
end
89
90-
   turtle.forward()
90+
91
 if Bool then
92-
   print('moving ',pos.x, "x",pos.y, "x",pos.z)
92+
93
  heading = heading + 1
94
 else 
95
  turtle.turnLeft()
96
  heading = heading - 1
97
 end
98
 if heading > 4 then
99
   heading = 1
100
  elseif heading < 1 then
101
   heading = 4
102
  end
103
end
104
105
function rot(Int)
106
a = heading - 1
107
 if a < 1 then
108
   a = 4
109
  end
110
if a == int then
111-
 turtle.digDown()
111+
 turtle.turnLeft()
112-
 turtle.down()
112+
 heading = heading - 1
113
end
114
a = heading + 1
115
 if a > 4 then
116
   a = 1
117
  end
118
if a == int then
119
 turtle.turnRight()
120
 heading = heading + 1
121
end
122
  if heading > 4 then
123
   heading = 1
124
  elseif heading < 1 then
125
   heading = 4
126
  end
127
while Int ~= heading do
128
  turtle.turnRight()
129
  heading = heading + 1
130
  if heading > 4 then
131
   heading = 1
132-
 turtle.digUp()
132+
133-
 turtle.up()
133+
134
  end
135
 end
136
end
137
138
function swapBool(Bool)
139
 if Bool then 
140
  return false
141
 else
142
  return true
143
 end
144
end
145
146
function chngCoord(Int)
147
 if Int == 1 then
148
   pos.z = pos.z + 1
149
 elseif Int == 2 then
150
   pos.x = pos.x + 1
151
 elseif Int == 3 then
152
   pos.z = pos.z - 1
153
 elseif Int == 4 then
154
   pos.x = pos.x - 1
155
 elseif Int == 5 then 
156
   pos.y = pos.y - 1
157
 elseif Int == 6 then
158
   pos.y = pos.y + 1
159
 end
160
end
161
162
function ChkFuel()
163
 if turtle.getFuelLevel() == 0 then 
164
  turtle.select(1)
165-
   chngCoord(6)
165+
166
   print('Dozapravke na ',pos.x, "x",pos.y, "x",pos.z)
167
  end
168
 end
169
end
170
171
function Fwd(Int)
172
  for a = 1, Int  do
173
   chkInv()
174
   turtle.dig()
175
   ChkFuel()
176
   if turtle.forward() then
177
    chngCoord(heading)
178
   end
179
  end
180
end
181
182
function Turn(Bool)
183
  if Bool then
184
   rotB(true)
185
  Fwd(1)
186
   rotB(true)
187
  return false
188
 else
189
   rotB(false)
190
  Fwd(1)
191
   rotB(false)
192
  return true 
193
  end
194
end
195
196
function down()
197
 move(5)
198
 rotB(false)
199
 rotB(false)
200
end
201
202
print('Vvedite Shiriny')
203
mX = tonumber(read())
204
print('Vvedite glubinu')
205
mY = tonumber(read())
206
207
print('  Starting at ',pos.x, "x",pos.y, "x",pos.z)
208
209
Fwd(1)
210
 rotB(false)
211
Fwd(mX/2)
212
 rotB(true)
213
214
for c=1, 2 do
215
 move(6)
216
end
217
218
print('  Dig down at ',pos.x, "x",pos.y, "x",pos.z)
219
220
turn = true
221
222
for y = 1, mY+3 do
223
 if y > 1 then
224
  down()
225
 end
226
  for x = 1,  mX do
227
   if mX > 1 then
228
    Fwd(mX - 1)
229
   else
230
    Fwd(mX)
231
   end
232
   if x ~= mX then
233
    turn = Turn(turn) 
234
   end 
235
  end
236
 end
237
238
print('Begin dig up, steps up = ', mY, "\n   ", pos.x, "x",pos.y, "x",pos.z)
239
240
241
for b=1, mY do
242
 move(6)
243
end
244
unloadTime()
245
moveToTgt(waypoints['retP'])
246
moveToTgt(vector.new(0,0,0))
247
print('Ending operation ', pos.x, "x",pos.y, "x",pos.z)