Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- make_safe = 0
- l = 0
- if #args == 0 then
- print("*Usage: mine <length> <make_safe(default:0)>")
- exit()
- else
- length = math.abs(tonumber(args[1]))
- if not args[2] == nil then
- make_safe = math.abs(tonumber(args[2]))
- end
- print("length: "..length)
- end
- if os.getComputerLabel() == nil then
- oldName = nil
- else
- oldName = os.getComputerLabel()
- end
- os.setComputerLabel("miner_"..math.random(9999999))
- print("temporarily changed label to "..os.getComputerLabel())
- function select(name)
- for i = 16, 1, -1 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if turtle.getItemCount() > 0 then
- print(item.name)
- if item.name == name then
- turtle.select(i)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- function checkSpace()
- slotsFull = 0
- for i = 16, 1, -1 do
- if turtle.getItemCount(i) > 0 then
- slotsFull = slotsFull + 1
- end
- end
- if slotsFull == 16 then
- if select("minecraft:chest") then
- turtle.turnRight()
- turtle.down()
- turtle.place()
- for i = 16, 1, -1 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then
- local item = turtle.getItemDetail(i)
- if item.name == "minecraft:torch" or item.name == "minecraft:chest" then
- else
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- turtle.up()
- turtle.turnLeft()
- end
- end
- end
- function throwAwayCobble()
- cobbles = 0
- for i = 16, 1, -1 do
- if turtle.getItemCount(i) > 0 then
- item = turtle.getItemDetail(i)
- if item.name == "minecraft:cobblestone" then
- cobbles = cobbles + 1
- end
- end
- end
- if cobbles > 1 then
- for i = 1, cobbles - 1, 1 do
- select("minecraft:cobblestone")
- turtle.dropDown()
- end
- end
- end
- function fuel()
- if turtle.getFuelLevel() < 12 then
- for i = 16, 1, -1 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then
- local item = turtle.getItemDetail(i)
- if item.name == "minecraft:torch" or item.name == "minecraft:chest" then
- else
- turtle.refuel()
- end
- end
- end
- turtle.select(1)
- end
- end
- function makeSafe()
- select("minecraft:cobblestone")
- turtle.down()
- local success, block = turtle.inspectDown()
- if success then
- if not block.name == "minecraft:stone" and not block.name == "minecraft:dirt" and not block.name == "minecraft:cobblestone" then
- turtle.digDown()
- turtle.placeDown()
- end
- end
- turtle.up()
- end
- function make3by3()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.back()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.back()
- turtle.turnRight()
- end
- torchDistance = 7
- while l <= length do
- l = l + 1
- fuel()
- make3by3()
- if make_safe == 1 then
- makeSafe()
- end
- if torchDistance == 7 then
- if select("minecraft:torch") then
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- turtle.select(1)
- else
- print("no torches found")
- end
- torchDistance = 0
- end
- torchDistance = torchDistance + 1
- turtle.select(1)
- checkSpace()
- turtle.select(1)
- throwAwayCobble()
- turtle.select(1)
- end
- if not oldName == nil then
- os.setComputerLabel(oldName)
- else
- os.setComputerLabel("turtle_"..math.random(9999999))
- end
Advertisement
Add Comment
Please, Sign In to add comment