View difference between Paste ID: qTyHf99T and 9bMt4rgA
SHOW: | | - or go back to the newest paste.
1
print("ok")
2
local origin = {0,0,0}
3
local max = {72,2,144}
4
local dir = 1;
5
local modX = {0,1,0,-1}
6
local modZ = {-1,0,1,0}
7
local location = {0,0,0}
8
9
function turnAround()
10
right()
11
right()
12
end
13
14
function right()
15
  dir = dir + 1 % 5
16
end
17
18
19
20
function left()
21
  dir = dir - 1
22
  if dir < 1 then
23
    dir = 1
24
  end
25
end
26
27
function down(dig)
28
  while true do
29
    if turtle.down() then
30
      break
31
    end
32
    if turtle.detectDown() then
33
      if dig then
34
        turtle.digDown()
35
      end
36
    end
37
    sleep(0)
38
  end
39
  location[1]=location[1]-1
40
end
41
42
function up(dig)
43
  while true do
44
    if turtle.up() then
45
      break
46
    end
47
    if dig then
48
      if turtle.detectUp() then
49
        turtle.digUp()
50
      end
51
    end
52
  sleep(0)
53
  end
54
  location[2] = location[2] + 1
55
end
56
function forward(dig)
57
  while true do
58
    if turtle.forward() then
59
      break
60
    end
61
    if turtle.detect() then
62
      if dig then
63
        turtle.dig()
64
      end
65
    end
66
    sleep(0)
67
  end
68
  print(dir);
69
  location[1] = location[1] + modX[dir];
70
  location[3] = location[3] + modZ[dir];
71
end
72
73
function back(dig)
74
  while true do
75
    if turtle.back() then
76
      break
77
    end
78
    if dig then
79
      turnAround()
80
      if turlte.detect() then
81
        turtle.dig()
82
      end
83
      turnAround()
84
    end
85
    sleep(0)
86
  end
87
  location[1] = location[1]+modX[dir];
88
  location[3] = location[3]+modZ[dir]; 
89
end
90
91
function getLocCopy()
92
  local copy = {}
93
  for i,n in ipairs(location) do
94
    copy[i]=n
95
  end
96
  return copy;
97
end
98
99
function checkInventory()
100
  if turtle.getItemCount(9) > 0 then
101
    return true
102
   end
103
   return false
104
end
105
106
function dropOff(x,y,z)
107
  local org = getLocCopy()
108
  if z%2 == 1 then
109
    left()
110
    forward(false)
111
    right()
112
  end
113
  while dir~=2 do
114
    left()
115
    sleep(0)
116
  end
117
  while location[3] ~= origin[3] do
118
    forward(false)
119
    sleep(0)
120
  end
121
  if location[1] ~= origin[1] then
122
    local left = false
123
    if location[1] <0 then
124
      left()
125
      left = true
126
    elseif location[1]>0 then
127
      right()
128
    end
129
    while location[1] ~= origin[1] do
130
      forward(false)
131
      sleep(0)
132
    end
133
134
    if left then
135
     right()
136
    else
137
      left()
138
    end
139
140
  end
141
  forward(false)
142
  forward(false)
143
  dropAll()
144
  turnAround()
145
  forward(false)
146
  forward(false)
147
  
148
  if left then
149
    left()
150
  else
151
    right()
152
  end
153
  while location[1] ~= org[1] do
154
      forward(false)
155
      sleep(0)
156
  end
157
	
158
  if left then
159
    right()
160
  else
161
    left()
162
  end
163
  if org[3] % 2 == 1 then
164
    right()
165
	forward(false)
166
	left()
167
  end
168
  while location[3]~=org[3] do
169
    forward(false)
170
	sleep(0)
171
  end
172
  if org[3]%2==1 then
173
    left()
174
	forward(true)
175
	right()
176
	
177
  end
178
  
179
end
180
181
function dropAll()
182
  for i=1,9,1 do
183
    turtle.select(i)
184
    if turtle.getItemCount(i) >0 then
185
      turtle.drop(turtle.getItemCount(i));
186
    end
187
  end
188
189
end
190
191
local input = ""
192
while input ~= "start" do
193
  input = io.read()
194
  sleep(0)
195
end
196
197
local location = {0,0,0}
198
199
  for x=0,max[1],1 do
200
    for z=0,max[3],1 do
201
      for y=1,max[2]-1,1 do
202
        
203-
        up(true);
203+
        while turtle.detectUp() do
204
		  turtle.digUp()
205
		  sleep(0)
206
		end
207
        checkInventory()
208
        down(false);
209
		print(tostring(x).."/"..tostring(y).."/"..tostring(z))
210-
	    dropOff()
210+
211
      forward(true);
212
      if checkInventory() then
213
	    dropOff(x,y,z)
214
      end
215
    end
216
    left()
217
    forward(true)
218
    left()
219
    back(true)
220
  end