Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- though this was written to dig up, it isn't going down far enough to need to...adding more depth between passes to utilize that.
- -- WIP!! there's also a quadrant error I haven't located yet.
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- turtle.down()
- local tArgs = {...}
- local size = tonumber(tArgs[1])
- local meter = tonumber(tArgs[2])
- local stepSize = size - 1
- local area = size * size
- local diggedLevel = 0
- function frwd(steps)
- for i = 1, steps do
- local success,blockInfo = turtle.inspectUp()
- if success then
- local blockName=blockInfo.name
- if blockName~="minecraft:stone" and blockName~="minecraft:dirt" then
- turtle.digUp()
- end
- end
- local success,blockInfo = turtle.inspectDown()
- if success then
- local blockName=blockInfo.name
- if blockName~="minecraft:stone" and blockName~="minecraft:dirt" then
- turtle.digDown()
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- function turnRight()
- turtle.turnRight()
- frwd(1)
- turtle.turnRight()
- end
- function turnLeft()
- turtle.turnLeft()
- frwd(1)
- turtle.turnLeft()
- end
- function refuel(limit)
- local fuel = turtle.getFuelLevel()
- local refueled = false
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getFuelLevel() <= limit and turtle.refuel(0) then
- local fuelNeeded = limit - turtle.getFuelLevel()
- local fuelAmount = math.min(fuelNeeded, turtle.getItemCount(i))
- turtle.refuel(fuelAmount)
- print("Turtle> Fuel: " .. turtle.getFuelLevel())
- if turtle.getFuelLevel() >= limit then
- refueled = true
- break
- end
- end
- end
- turtle.select(1)
- return refueled
- end
- function ejectUnwantedItems()
- local unwantedItems = {
- "minecraft:cobblestone",
- "minecraft:gravel",
- "minecraft:dirt"
- }
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- local itemDetail = turtle.getItemDetail()
- itemName = itemDetail.name
- for _, unwantedItem in ipairs(unwantedItems) do
- if itemName == unwantedItem then
- turtle.dropUp()
- break
- end
- end
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- end
- function emptySlots()
- local empty = 16
- for i = 1, 16 do
- if turtle.getItemCount(i) ~= 0 then
- empty = empty - 1
- end
- end
- return empty
- end
- function mineLevel()
- for i = 1, size do
- frwd(stepSize)
- if i == size then
- -- turtle.turnRight()
- -- turtle.turnRight()
- ejectUnwantedItems()
- -- turtle.turnRight()
- -- turtle.turnRight()
- end
- -- end of first row, output 1 error("Checkpiont: diggedLevel%2.."..diggedLevel % 2)
- if diggedLevel % 2 ~= 0 then
- if i ~= size then
- if i % 2 == 0 then
- turnRight()
- else
- turnLeft()
- end
- end
- else
- if i ~= size then
- if i % 2 == 0 then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- end
- end
- -- Main program
- refuel(6)
- -- Main loop
- while diggedLevel < meter do
- local startLevel = diggedLevel
- levelsToDig=meter -- this doesn't seem to make sense to me... local levelsToDig = math.min(2, meter - startLevel)
- for level = 1, levelsToDig do
- diggedLevel = diggedLevel + 1
- mineLevel()
- turtle.digUp()
- if level ~= levelsToDig then
- -- turtle.digUp()
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- turtle.down()
- end
- -- error("checkpoint")
- if diggedLevel %2 ~= 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.turnRight()
- -- error("level.."..level..", levelsToDig"..levelsToDig)
- end
- end
- -- turtle.turnRight()
- -- turtle.turnRight()
- turtle.digUp()
- turtle.digDown()
- if emptySlots() == 0 then
- print("\nTurtle> Inventory full! Ejecting unwanted items.")
- ejectUnwantedItems()
- else
- refuel(area + 3)
- end
- print("\nTurtle> Dug: " .. diggedLevel .. " / " .. meter .. " levels")
- end
- print("\nTurtle> Mining complete! Terminating!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement