Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- base = require "turtle_base"
- junk = { "minecraft:stone", "minecraft:cobblestone", "minecraft:dirt", "minecraft:gravel", "minecraft:netherrack", "byg:rocky_stone", "byg:scoria_cobblestone", "byg:soapstone", "minecraft:blackstone", "byg:frost_magma"}
- settings.load("settings")
- rows = settings.get("turtleRows", 0)
- columns = settings.get("turtleColumns", 0)
- startY = settings.get("turtleStartY", 0)
- -- init rows
- if rows == 0 then
- term.clear()
- term.setCursorPos(1,1)
- io.write("Rows: ")
- rows = tonumber(io.read())
- settings.set("turtleRows", rows)
- end
- -- init columns
- if columns == 0 then
- term.clear()
- term.setCursorPos(1,1)
- io.write("Columns: ")
- columns = tonumber(io.read())
- settings.set("turtleColumns", columns)
- end
- -- init startingY
- if startY == 0 then
- term.clear()
- term.setCursorPos(1,1)
- io.write("What Y layer do you want me to start on: ")
- startY = tonumber(io.read())
- settings.set("turtleStartY", startY)
- end
- oppositeCorner = base.getOffsetLocal(columns, rows)
- settings.save("settings")
- function junkStuff()
- base.sendStatus("Junking Trash")
- for i = 1, 16, 1 do
- local slotData = turtle.getItemDetail(i)
- for k,v in pairs(junk or {}) do
- if slotData and slotData.name == v then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- base.minifyStacks()
- end
- function dumpInv()
- base.sendStatus("Dumping Inventory")
- needCoal = turtle.getItemSpace(1)
- turtle.suck(needCoal)
- for i = 2, 16, 1 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function returnHome()
- junkStuff()
- base.returnHome()
- dumpInv()
- end
- function noSpaceLeft()
- returnHome()
- base.returnToWork()
- end
- function checkInv()
- -- clear any junk from inventory
- junkStuff()
- -- check inventory for any room for more items
- if not base.checkSpace() then
- noSpaceLeft()
- end
- -- attempts to fill fuel slot, returns true if enough fuel is located in the fuel slot.
- base.refuel()
- end
- -- breaks blocks on top and below current place
- function digForward()
- base.moveForward()
- base.updateWorklocation()
- while turtle.detectDown() do
- turtle.digDown()
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- -- turble rotatee
- function nextColumn(xPos)
- if xPos % 2 == 0 then
- base.rotateTo(1)
- digForward()
- base.rotateTo(2)
- else
- base.rotateTo(1)
- digForward()
- base.rotateTo(0)
- end
- end
- function nextLayer()
- base.moveToPosition(base.home.x, base.work.y, base.home.z, base.home.direction, "Next Layer")
- base.moveDown()
- base.moveDown()
- base.moveDown()
- turtle.digDown()
- end
- function digNorth()
- for zPos = base.work.z, oppositeCorner.x-2, 1 do
- if not base.checkSpace() then
- noSpaceLeft()
- end
- zPos = base.work.z
- digForward()
- base.sendStatus("Digging Blocks")
- end
- end
- function digSouth()
- for zPos = base.work.z, base.home.z, -1 do
- if not base.checkSpace() then
- noSpaceLeft()
- end
- zPos = base.work.z
- digForward()
- base.sendStatus("Digging Blocks")
- end
- end
- function mineColumn()
- for xPos = base.work.x, oppositeCorner.x-1, 1 do
- if xPos % 2 == 0 then
- digNorth()
- else
- digSouth()
- end
- checkInv()
- if base.work.x ~= columns-1 then nextColumn(xPos) end
- end
- end
- function doWork()
- for yPos = base.work.y, 3, -1 do
- mineColumn()
- nextLayer()
- yPos = base.work.y
- end
- returnHome("To finish up")
- base.sendStatus("I have finished mining")
- shell.run("reset_settings.lua")
- end
- function mine()
- checkInv()
- base.sendStatus("attempting to return to start")
- if not base.locationNil(base.work) then
- base.returnToWork()
- else
- returnHome()
- end
- base.updateWorklocation()
- while base.work.y > startY do
- base.sendStatus("Moving to start")
- base.moveDown()
- base.updateWorklocation()
- end
- turtle.digDown()
- if base.work.y < startY then turtle.digUp() end
- doWork()
- end
- base.init(true, {base.validTools.pickaxe, base.validTools.modem})
- mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement