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