Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Expected slot assignment/content
- Slot 1: 64 Torches
- Slot 2: 1 Cobble (reserved for cobble compare)
- Slot 3: Enderchest
- --]]
- -- Parameters
- local torchSlot = 1 -- Inventory slot of torches
- local cobbleSlot = 2 -- Inventory slot of atleast one cobble
- local enderChestSlot = 3 -- Inventory slot of enderchest to be used for offloading
- local frequencyOfCobbleRemoval = 30 -- Remove cobble every n blocks mined
- local enderDumpInterval = 100 -- Dump content into an enderchest every 100 blocks mined
- -- Variables
- local doProcessContent = false
- local depth = 0
- local collected = 0
- -- Process commandline
- local tArgs = { ... }
- if #tArgs < 2 then
- print( "Usage: Area <length> <width> [Process]" )
- print( "======================================" )
- print( "Process If true, content -> Enderchest")
- print( "")
- print( "Expected content in inventory of turtle:" )
- print( "Slot 1: Torches" )
- print( "Slot 2: Cobble (at least 1)")
- print( "Slot 3: Enderchest (only if Process=true)")
- return
- end
- local length = tonumber( tArgs[1] )
- if length < 1 then
- print( "Area length must be 1+" )
- return
- end
- local width = 1
- if #tArgs > 1 then
- width = tonumber( tArgs[2] )
- if width < 1 then
- print( "Area width must be 1+" )
- return
- end
- if #tArgs > 2 then
- doProcessContent = tArgs[3]:lower()=="true"
- end
- end
- local function checkSlot(slotNr,description)
- if turtle.getItemCount(slotNr)==0 then
- print("Expected item '"..description.."' in slot "..slotNr..".")
- return false
- end
- return true
- end
- -- Check slots
- if not checkSlot(torchSlot,"torches") then return end
- if not checkSlot(cobbleSlot,"cobbleStone (atleast 1)") then return end
- if doProcessContent then
- if not checkSlot(enderChestSlot,"enderChest") then return end
- end
- -- Main Code
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." items." )
- end
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming Tunnel." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- if not tryDigDown() then
- return false
- end
- elseif turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function dropCobbleWhenNecessary(x)
- if math.fmod(collected,frequencyOfCobbleRemoval)==0 then
- for n=3,16 do
- turtle.select(n)
- if turtle.compareTo(cobbleSlot) then
- turtle.drop()
- end
- end
- end
- end
- local function placeTorchWhenNecessary(x,y)
- if math.fmod(x,8)==1 and math.fmod(y,8)==1 then
- turtle.select(1)
- if (turtle.getItemCount(torchSlot)==0) then
- print("Out of torches, please resupply!")
- return false
- else
- turtle.placeDown()
- end
- end
- return true
- end
- local function processContent()
- if not doProcessContent then
- return
- end
- if (turtle.getItemCount(torchSlot)==0) then
- print("No enderchest found Out of torches, please resupply!")
- return false
- end
- -- place chest
- turtle.select(enderChestSlot)
- turtle.placeDown()
- --
- print("1")
- for slot=3,16 do
- print("2:"..slot)
- turtle.select(slot)
- print("3")
- if turtle.compareTo(cobbleSlot) then
- print("4a")
- turtle.drop()
- else
- print("4b")
- turtle.dropDown()
- end
- print("5")
- end
- print("6")
- --retrieve chest
- turtle.select(enderChestSlot)
- print("7")
- turtle.digDown()
- print("8")
- end
- local function mine()
- print( "Tunneling..." )
- local rotation=0
- for m=1,width do
- for n=1,length-1 do
- tryDigUp()
- tryDigDown()
- if (math.fmod(collected+1,enderDumpInterval)==0) then
- processContent()
- end
- dropCobbleWhenNecessary(n)
- placeTorchWhenNecessary(n,m)
- tryDig()
- if not tryForward() then
- return false
- end
- end
- tryDigUp()
- tryDigDown()
- if m < width then
- if rotation==0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- tryDig()
- if not tryForward() then
- return false
- end
- if rotation==0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- rotation = 1 - rotation
- end
- end
- processContent()
- return true
- end
- if mine() then
- print( "Tunnel complete." )
- else
- print( "Tunnel aborted prematurely.")
- end
- print( "Mined "..collected.." blocks total." )
Advertisement
Add Comment
Please, Sign In to add comment