Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local defaultBranchLength = 60
- local branchLength = tonumber(args[1]) or defaultBranchLength
- local enderChestMode = true
- local cobblestone = 1
- local torch = 15
- local enderChest = 16
- function dig ()
- turtle.select(1)
- local tries = 0
- turtle.dig()
- while turtle.detect() and tries < 120 do
- tries = tries + 1
- turtle.dig()
- sleep(0.8)
- end
- slotsFilled()
- end
- function forward (n, digUp)
- local steps = n or 1
- for i = 1, steps do
- dig()
- while not turtle.forward() do
- dig()
- sleep(0.8)
- end
- if digUp then
- local tries = 0
- turtle.digUp()
- while turtle.detectUp and tries < 120 do
- tries = tries + 1
- turtle.digUp()
- end
- end
- end
- end
- function up ()
- turtle.digUp()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.8)
- end
- end
- function placeTorch ()
- if turtle.getItemCount(torch) > 1 then
- turtle.select(torch)
- if not turtle.place() and turtle.getItemCount(cobblestone) > 1 then
- forward()
- turtle.select(cobblestone)
- turtle.place()
- turtle.back()
- turtle.select(torch)
- turtle.place()
- end
- end
- end
- function emptyInventory()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.select(enderChest)
- while turtle.getItemCount(enderChest) == 0 do
- print("No chest found, press Enter to continue")
- repeat
- event, key = os.pullEvent("key")
- until key == keys.enter
- end
- turtle.place()
- for slot = 2, 14 do
- if turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- turtle.drop()
- end
- end
- turtle.select(enderChest)
- if enderChestMode then
- turtle.dig()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function floor ()
- if not turtle.detectDown() and turtle.getItemCount(cobblestone) > 1 then
- turtle.select(cobblestone)
- turtle.placeDown()
- end
- end
- function ceiling ()
- if not turtle.detectUp() and turtle.getItemCount(cobblestone) > 1 then
- turtle.select(cobblestone)
- turtle.placeUp()
- end
- end
- function dig1x3 (i)
- turtle.turnLeft()
- dig()
- turtle.turnRight()
- turtle.turnRight()
- dig()
- if i and i % 7 == 1 then
- placeTorch()
- end
- turtle.turnLeft()
- end
- function dig2x3 (i)
- forward()
- floor()
- up()
- dig1x3(i)
- ceiling()
- turtle.down()
- dig1x3()
- end
- function slotsFilled ()
- local filled = true
- for slot = 2, 14 do
- if turtle.getItemCount(slot) == 0 then
- filled = false
- break
- end
- end
- if filled then
- emptyInventory()
- end
- end
- function nextBranch (n)
- local odd = n % 2 == 1
- local turn = nil
- if odd then
- turn = turtle.turnRight
- else
- turn = turtle.turnLeft
- end
- forward(1, true)
- floor()
- turn()
- for i = 1, 5 do
- forward(1, true)
- floor()
- end
- turn()
- end
- --Main program
- print("lzStrip v0.2")
- print("(C) LayZee 2013")
- print("")
- print("Place Cobblestones in slot 1")
- print("Place Torches in slot 15")
- print("Place an Ender Chest in slot 16")
- print("Press Enter to start strip mining")
- repeat
- local event, key = os.pullEvent("key")
- until key == keys.enter
- while true do
- local branch = 1
- while turtle.getFuelLevel() >= branchLength * 2 + 12 + branchLength / 7 do
- for i = 1, branchLength do
- dig2x3(i)
- end
- branch = branch + 1
- nextBranch(branch)
- end
- print("Out of fuel")
- print("")
- print("1. Remove Cobblestones from slot 1")
- print("2. Place fuel source in slot 1")
- print("3. Press any key to refuel")
- os.pullEvent("key")
- while turtle.getFuelLevel() < branchLength * 2 + 12 do
- turtle.select(1)
- turtle.refuel()
- local timerId = os.startTimer(2)
- local event = ""
- local id = 0
- while timerId ~= id do
- event, id = os.pullEvent("timer")
- end
- end
- print("4. Place Cobblestone in slot 1")
- print("5. Press Enter to resume strip mining")
- repeat
- event, key = os.pullEvent("key")
- until key == keys.enter
- end
- print("ERROR: Broke out of main loop")
- print("Report to layzee.dk@gmail.com")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement