Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arg = {...}
- width = nil
- length = nil
- compareSlots = 3
- fuelSlots = 1
- if arg[1] ~= nil and arg[2] ~= nil then
- width = arg[1]
- length = arg[2]
- else
- term.setTextColor(colors.red)
- print("Usage: quarry <width> <length>")
- return
- end
- x = 0
- z = 0
- y = 0
- facing = 0
- function empty()
- turtle.select(1)
- while turtle.detect() do
- turtle.dig()
- end
- turtle.place()
- c = peripheral.wrap("front")
- for slot = 2+compareSlots,16-fuelSlots do
- emptySpace = false
- while not emptySpace do
- itemsNb = #c.getAllStacks()
- invSize = c.getInventorySize()
- if itemsNb < invSize then
- emptySpace = true
- end
- sleep(1)
- end
- turtle.select(slot)
- turtle.drop()
- end
- c = nil
- turtle.dig()
- end
- function mineMinerals()
- shouldDigUp = true
- shouldDigDown = true
- for slot = 2, 1+compareSlots do
- turtle.select(slot)
- if turtle.compareUp() and shouldDigUp then
- shouldDigUp = false
- else
- end
- if turtle.compareDown() and shouldDigDown then
- shouldDigDown = false
- end
- end
- if shouldDigDown then digDown() end
- if shouldDigUp then digUp() end
- end
- function quarry()
- while down() do end
- up()
- mineLayer()
- while nextLayer() do
- mineLayer()
- end
- empty()
- end
- function printInfo()
- term.setCursorPos(1,1)
- term.clear()
- print("x: "..x.." y: "..y.." z: "..z.." f: "..facing)
- end
- function nextLayer()
- next = true
- if width % 2 == 0 then
- turnRight()
- while x > 0 do step() end
- else
- turnLeft()
- while x > 0 do step() end
- turnLeft()
- while z > 0 do step() end
- end
- lastLayer = y
- while y < lastLayer + 3 do
- if y < 0 then
- up()
- end
- end
- while facing ~= 0 do
- if width % 2 == 0 then
- turnRight()
- else
- turnLeft()
- end
- end
- if y == 0 then next = false end
- return next
- end
- function refuel()
- if turtle.getFuelLevel() < 5 then
- for slot = 16-fuelSlots, 16 do
- if turtle.getItemCount(slot) > 1 then
- turtle.select(slot)
- turtle.refuel(1)
- return true
- end
- end
- end
- return false
- end
- function step()
- printInfo()
- mineMinerals()
- while not turtle.forward() do
- if not refuel() then
- if turtle.detect() then
- dig()
- else
- turtle.attack()
- end
- end
- end
- if facing == 0 then z = z + 1 end
- if facing == 2 then z = z - 1 end
- if facing == 1 then x = x + 1 end
- if facing == 3 then x = x - 1 end
- end
- function up()
- printInfo()
- while not turtle.up() do
- if not refuel() then
- if turtle.detectUp() then
- digUp()
- else
- turtle.attackUp()
- end
- end
- end
- y = y + 1
- end
- function down()
- printInfo()
- done = false
- while not done do
- done = turtle.down()
- if done then
- y = y - 1
- return true
- end
- if not refuel() then
- if turtle.detectDown() then
- if digDown() then
- turtle.down()
- y = y - 1
- return true
- else return false end
- else
- turtle.attackDown()
- end
- end
- end
- end
- function turnLeft()
- printInfo()
- turtle.turnLeft()
- facing = facing - 1
- if facing < 0 then facing = 3 end
- end
- function turnRight()
- printInfo()
- turtle.turnRight()
- facing = facing + 1
- if facing > 3 then facing = 0 end
- end
- function turnAround()
- if z == length-1 then
- turn = function() turnRight() end
- elseif z == 0 then
- turn = function() turnLeft() end
- end
- turn()
- step()
- turn()
- end
- function mineLayer()
- for i = 1,width do
- for j = 1,length-1 do
- step()
- end
- if x ~= width - 1 then
- turnAround()
- end
- end
- end
- function shouldEmpty()
- if turtle.getItemCount(16 - fuelSlots - 1) > 0 then
- empty()
- end
- end
- function dig()
- shouldEmpty()
- return turtle.dig()
- end
- function digDown()
- shouldEmpty()
- return turtle.digDown()
- end
- function digUp()
- shouldEmpty()
- return turtle.digUp()
- end
- quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement