Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function find(itemName)
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) >= 1 then
- local data = turtle.getItemDetail(curSlot)
- if data.name == itemName then
- return curSlot
- end
- end
- end
- return false
- end
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: miner <distance>" )
- return
- end
- local maxDist = tonumber( tArgs[1] )
- if maxDist < 1 then
- print( "Distance must be positive" )
- return
- end
- local function getFreeInventorySpace()
- local freeSpace = 16
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- freeSpace = freeSpace - 1
- end
- end
- return freeSpace
- end
- local function sortInventory()
- local inventory = {}
- for curSlot=1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- inventory[curSlot] = turtle.getItemDetail(curSlot)
- else
- inventory[curSlot] = "empty"
- end
- end
- for slotA=1,16 do
- if inventory[slotA] ~= "empty" then
- for slotB=1,16 do
- if inventory[slotB] ~= "empty" then
- if slotA ~= slotB then
- if (inventory[slotA].name == inventory[slotB].name) and (inventory[slotA].damage == inventory[slotB].damage) then
- if inventory[slotA].count + inventory[slotB].count <= 64 then
- turtle.select(slotB)
- turtle.transferTo(slotA)
- inventory[slotB] = "empty"
- end
- end
- end
- end
- end
- end
- end
- end
- local function digAround()
- while turtle.detectUp() do
- turtle.digUp()
- end
- if turtle.detectDown() then
- local success, data = turtle.inspectDown()
- if success then
- if not (data.name == "minecraft:cobblestone") and not (data.name == "minecraft:stone") and not (data.name == "minecraft:sand") and not (data.name == "minecraft:dirt") and not (data.name == "minecraft:gravel") and not (data.name == "chisel:marble2") and not (data.name == "chisel:limestone2") then
- turtle.digDown()
- end
- end
- end
- if find("minecraft:cobblestone") then
- turtle.select(find("minecraft:cobblestone"))
- turtle.placeDown()
- elseif find("minecraft:stone") then
- turtle.select(find("minecraft:stone"))
- turtle.placeDown()
- end
- end
- local function checkFuel(level)
- if (turtle.getFuelLevel() <= level) and (find("minecraft:coal")) then
- turtle.select(find("minecraft:coal"))
- turtle.refuel(1)
- end
- end
- local function returnToStart(travelled, continue)
- if continue then
- print("Returning to deposit items, then continuing")
- else
- print("Returning to deposit items; job done")
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for curDist=0,travelled do
- checkFuel(10)
- local success, data = turtle.inspect()
- if success then
- if data.name ~= "minecraft:chest" then
- while not turtle.forward() do
- turtle.dig()
- end
- end
- else
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- local success, data = turtle.inspect()
- if success then
- if data.name == "minecraft:chest" then
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- block = turtle.getItemDetail(curSlot)
- if (block.name ~= "minecraft:coal") and (block.name ~= "minecraft:torch") and (block.name ~= "tconstruct:stone_torch") then
- turtle.select(curSlot)
- turtle.drop()
- end
- end
- end
- end
- end
- if continue then
- turtle.turnLeft()
- turtle.turnLeft()
- for curDist=0,travelled-1 do
- checkFuel(10)
- local success, data = turtle.inspect()
- if success then
- if data.name ~= "minecraft:chest" then
- while not turtle.forward() do
- turtle.dig()
- end
- end
- else
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- end
- end
- local travelDist = 0
- while travelDist <= maxDist do
- checkFuel(10)
- if (find("minecraft:torch") == false) and (find("tconstruct:stone_torch") == false) then
- break
- end
- sortInventory()
- if getFreeInventorySpace() <= 1 then
- returnToStart(travelDist,true)
- end
- digAround()
- turtle.turnLeft()
- while not turtle.forward() do
- turtle.dig()
- end
- digAround()
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- while not turtle.forward() do
- turtle.dig()
- end
- digAround()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- if (travelDist % 6 == 0) and ((find("minecraft:torch") or (find("tconstruct:stone_torch"))) then
- if find("tconstruct:stone_torch") then
- turtle.select(find("tconstruct:stone_torch"))
- else
- turtle.select(find("minecraft:torch"))
- end
- turtle.place()
- end
- turtle.turnRight()
- if travelDist <= maxDist then
- while not turtle.forward() do
- turtle.dig()
- end
- travelDist = travelDist + 1
- end
- end
- returnToStart(travelDist,false)
Add Comment
Please, Sign In to add comment