Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- lzStrip Turtle program
- Strip mine while chunk loaded
- Dependencies:
- - LAMA: https://github.com/fnuecke/lama
- @copyright (C) LayZee 2014
- --]]
- --[[
- os.loadAPI('lz')
- lz.load('turtle', 't')
- --]]
- local DEFAULT_BRANCH_LENGTH = 60
- local DEFAULT_ENDER_CHEST_MODE = true
- local config = {}
- local arguments = {...}
- -- Declare functions
- local branchMine, buildCeiling, buildCeilingAndFloor, buildFloor, dig1x3,
- dig2x3, digDown, digForward, digMoveDown, digMoveForward, digMoveUp,
- digToNextBranch, digUp, displayGuide, emptyInventory, emptyInventoryIfFull,
- handleLowFuel, initializeConfig, initializeLama, moveBack, moveForward,
- placeTorch, waitForFallingBlocks
- branchMine = function()
- local branch = 1
- while turtle.getFuelLevel() >= config.branchLength * 2 + 12 + config.branchLength / 7 do
- for step = 1, config.branchLength do
- dig2x3(step)
- end
- branch = branch + 1
- digToNextBranch(branch)
- end
- handleLowFuel()
- end
- buildCeiling = function()
- if not turtle.detectUp() and turtle.getItemCount(config.cobblestoneSlot) > 1 then
- turtle.select(config.cobblestoneSlot)
- turtle.placeUp()
- end
- end
- buildCeilingAndFloor = function()
- if lama.getY() == 1 then
- buildCeiling()
- digMoveDown()
- buildFloor()
- else
- buildFloor()
- digMoveUp()
- buildCeiling()
- end
- end
- buildFloor = function()
- if not turtle.detectDown() and turtle.getItemCount(config.cobblestoneSlot) > 1 then
- turtle.select(config.cobblestoneSlot)
- turtle.placeUp()
- end
- end
- dig1x3 = function(step)
- -- Face left block
- lama.turnLeft()
- digForward()
- -- Face right block
- lama.turnAround()
- digForward()
- -- Place torch every 7 steps, starting at first step
- if step % 7 == 1 and lama.getY() == 1 then
- placeTorch()
- end
- -- Face forward
- lama.turnLeft()
- -- Build ceiling or floor
- if lama.getY() == 1 then
- buildCeiling()
- else
- buildFloor()
- end
- end
- dig2x3 = function(step)
- emptyInventoryIfFull()
- digMoveForward()
- dig1x3(step)
- if lama.getY() == 1 then
- digMoveDown()
- else
- digMoveUp()
- end
- dig1x3(step)
- end
- digDown = function()
- for try = 1, 120 do
- local isBlocked = turtle.detectDown()
- if not isBlocked then
- break
- end
- turtle.digDown()
- waitForFallingBlocks()
- end
- local tries = 0
- end
- digForward = function()
- for try = 1, 120 do
- local isBlocked = turtle.detect()
- if not isBlocked then
- break
- end
- turtle.dig()
- waitForFallingBlocks()
- end
- local tries = 0
- end
- digMoveDown = function()
- turtle.select(1)
- lama.down(120, true)
- end
- digMoveForward = function()
- turtle.select(1)
- lama.forward(120, true)
- end
- digMoveUp = function()
- turtle.select(1)
- lama.up(120, true)
- end
- digToNextBranch = function(branch)
- local isOddBranch = branch % 2 == 1
- local turnAction
- if isOddBranch then
- turnAction = lama.turnRight
- else
- turnAction = lama.turnLeft
- end
- digMoveForward()
- buildCeilingAndFloor()
- turnAction()
- for step = 1, 5 do
- digMoveForward()
- buildCeilingAndFloor()
- end
- turnAction()
- end
- digUp = function()
- for try = 1, 120 do
- local isBlocked = turtle.detectUp()
- if not isBlocked then
- break
- end
- turtle.digUp()
- waitForFallingBlocks()
- end
- local tries = 0
- end
- displayGuide = function()
- local chestString
- if config.enderChestMode then
- chestString = 'an Ender Chest'
- else
- chestString = 'Chests'
- end
- print("lzStrip v0.3")
- print("(C) LayZee 2014")
- print("")
- print("Place Cobblestones in slot 1")
- print("Place Torches in slot 15")
- print("Place " .. chestString .. " in slot 16")
- print("Press Enter when ready")
- local _, key
- repeat
- _, key = os.pullEvent("key")
- until key == keys.enter
- print 'Starting...'
- end
- emptyInventory = function()
- lama.turnAround()
- digForward()
- turtle.select(config.chestSlot)
- local chestString
- if config.enderChestMode then
- chestString = 'Ender Chest'
- else
- chestString = 'Chest'
- end
- while turtle.getItemCount(config.chestSlot) == 0 do
- print('No ', chestString, ' in slot ', config.chestSlot, '. Press Enter when ready')
- repeat
- local _, 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(config.chestSlot)
- if config.enderChestMode then
- digForward()
- end
- lama.turnAround()
- end
- emptyInventoryIfFull = function()
- local inventoryIsFull = true
- for slot = 2, 14 do
- if turtle.getItemCount(slot) == 0 then
- inventoryIsFull = false
- break
- end
- end
- if inventoryIsFull then
- emptyInventory()
- end
- end
- handleLowFuel = function()
- 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)
- lama.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
- initializeConfig = function()
- local branchLength = tonumber(arguments[1])
- branchLength = branchLength or DEFAULT_BRANCH_LENGTH
- local enderChestMode = tostring(arguments[2])
- if enderChestMode == nil then
- enderChestMode = DEFAULT_ENDER_CHEST_MODE
- elseif enderChestMode:lower() == 'enderchest' then
- enderChestMode = true
- elseif enderChestMode:lower() == 'chest' then
- enderChestMode = false
- end
- config.branchLength = branchLength
- config.enderChestMode = enderChestMode
- config.chestSlot = 16
- config.cobblestoneSlot = 1
- config.fuelSlot = 1
- config.torchSlot = 15
- end
- initializeLama = function()
- print 'calling lama.init'
- --lama.init()
- print 'setting lama pos'
- lama.set(0, 0, 0, lama.side.north)
- print 'lama done'
- end
- moveBack = function()
- lama.back(120)
- end
- moveForward = function()
- lama.forward(120, true)
- end
- placeTorch = function()
- if turtle.getItemCount(config.torchSlot) > 1 then
- turtle.select(config.torchSlot)
- if not turtle.place() and turtle.getItemCount(config.cobblestoneSlot) > 1 then
- moveForward()
- turtle.select(config.cobblestoneSlot)
- turtle.place()
- moveBack()
- turtle.select(config.torchSlot)
- turtle.place()
- end
- end
- end
- waitForFallingBlocks = function()
- local timerId = os.startTimer(0.8)
- repeat
- local _, id = os.pullEvent('timer')
- until id == timerId
- end
- -- Program entry point
- (function()
- os.loadAPI('apis/lama')
- initializeConfig()
- displayGuide()
- print 'Initializing Lama...'
- initializeLama()
- print 'Initialized Lama'
- while true do
- branchMine()
- end
- end)()
Advertisement
Add Comment
Please, Sign In to add comment