Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dim = { ... }
- if #dim ~= 3 then
- print("Usage: stripmine <width> <height> <depth>")
- return
- end
- width = tonumber(dim[1])
- height = tonumber(dim[2])
- depth = tonumber(dim[3])
- if width < 1 or height < 1 or depth < 1 then
- print("Please ensure all parameters are positive")
- return
- end
- if height * depth > 750 then
- print("Please select smaller bounds")
- return
- end
- function moveTo(x, y, z)
- while loc[3] < z do
- if direct ~= 1 then
- redirect(1) end
- if turtle.forward() then
- loc[3] = loc[3] + 1
- else turtle.dig() end
- end
- while loc[3] > z do
- if direct ~= 3 then
- redirect(3) end
- if turtle.forward() then
- loc[3] = loc[3] - 1
- else turtle.dig() end
- end
- while loc[1] < x do
- if direct ~= 2 then
- redirect(2) end
- if turtle.forward() then
- loc[1] = loc[1] + 1
- else turtle.dig() end
- end
- while loc[1] > x do
- if direct ~= 4 then
- redirect(4) end
- if turtle.forward() then
- loc[1] = loc[1] - 1
- else turtle.dig() end
- end
- while loc[2] < y do
- success = turtle.up()
- if success then
- loc[2] = loc[2] + 1
- else turtle.digUp() end
- end
- while loc[2] > y do
- if turtle.down() then
- loc[2] = loc[2] - 1
- else turtle.digDown() end
- end
- end
- function redirect(newD)
- if newD > 4 then newD = newD - 4 end
- while direct ~= newD do
- if newD - direct == 1 or (direct == 4 and newD == 1) then
- turtle.turnRight()
- direct = direct + 1
- else
- turtle.turnLeft()
- direct = direct - 1
- end
- if direct > 4 then
- direct = direct - 4 end
- if direct == 0 then
- direct = 4 end
- end
- end
- function isFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return false end
- end
- return true
- end
- function dump()
- local current = {}
- current[1] = loc[1]
- current[2] = loc[2]
- current[3] = loc[3]
- moveTo(1, 1, 1)
- redirect(3)
- foundFuel = false
- for i = 1,16 do
- turtle.select(i)
- if not turtle.refuel(0) then
- turtle.drop()
- else
- if foundFuel then
- turtle.drop()
- else foundFuel = true end
- end
- if i == 16 and isFull() then
- i = 1 end
- end
- moveTo(current[1], current[2], current[3])
- end
- function digStrip(forward)
- if forward then
- while loc[3] <= depth do
- if loc[3] % 10 == 0 then
- print(string.format("Current depth: %d", loc[3])) end
- moveTo(loc[1], loc[2], loc[3] + 1)
- if isFull() then dump() end
- if loc[2] == 1 then
- moveTo(loc[1], height, loc[3])
- else
- moveTo(loc[1], 1, loc[3])
- end
- end
- else
- while loc[3] > 1 do
- if loc[3] % 10 == 0 then
- print(string.format("Current depth: %d", loc[3])) end
- moveTo(loc[1], loc[2], loc[3] - 1)
- if isFull() then dump() end
- if loc[2] == 1 then
- moveTo(loc[1], height, loc[3])
- else
- moveTo(loc[1], 1, loc[3])
- end
- end
- end
- end
- --Main:
- loc = {}
- loc[1] = 1
- loc[2] = 1
- loc[3] = 1
- direct = 1
- if width % 3 ~= 1 then
- while width % 3 ~= 1 do
- width = width - 1
- end
- print(string.format("Width truncated to %d", width))
- end
- forward = true
- while true do
- if turtle.getFuelLevel() < 1000 then
- refueled = false
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(16) then
- select(1)
- refueled = true
- break end
- end
- if not refueled then
- moveTo(1, 1, 1)
- redirect(1)
- print("No additional fuel stored")
- print("Opperation cancelled")
- print(string.format("Type \"stripmine %d %d %d\" to resume", width, height, depth))
- return
- end
- else print(string.format("Current fuel: %d", turtle.getFuelLevel()))
- end
- digStrip(forward)
- forward = not forward
- if (loc[1] == width) then
- moveTo(1, 1, 1)
- dump()
- redirect(1)
- return
- end
- for i = 1,3 do
- if loc[2] == 1 then
- moveTo(loc[1] + 1, height, loc[3])
- else
- moveTo(loc[1] + 1, 1, loc[3])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement