Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local checkItems = {
- "minecraft:dirt",
- "minecraft:stone",
- "minecraft:gravel",
- "minecraft:chest",
- "minecraft:flowing_lava"
- }
- local cDir = "north"
- local cX = 0
- local cY = 0
- local cZ = 0
- local home
- local workingY
- local status
- local workingRow
- local turns = 0
- local special = "none"
- local preMoveFuel
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --saves data to file
- function saveCor()
- local fileHandle = fs.open("path","w")
- fileHandle.writeLine(cX)
- fileHandle.writeLine(cY)
- fileHandle.writeLine(cZ)
- fileHandle.writeLine(cDir)
- fileHandle.writeLine(workingY)
- fileHandle.writeLine(size)
- fileHandle.writeLine(toY)
- fileHandle.writeLine(home)
- fileHandle.writeLine(status)
- fileHandle.writeLine(turns)
- fileHandle.writeLine(special)
- fileHandle.writeLine(preMoveFuel)
- fileHandle.close()
- end
- --deletes the file
- function deleteFiles()
- fs.delete("path")
- end
- --overide of turtle.turnRightfucntion
- function turnRight()
- if cDir == "north" then
- cDir = "east"
- elseif cDir == "east" then
- cDir = "south"
- elseif cDir == "south" then
- cDir = "west"
- elseif cDir == "west" then
- cDir = "north"
- else
- print("Error!!")
- error()
- end
- turtle.turnRight()
- end
- --overide of turtle.turnLeft fucntion
- function turnLeft()
- if cDir == "north" then
- cDir = "west"
- elseif cDir == "east" then
- cDir = "north"
- elseif cDir == "south" then
- cDir = "east"
- elseif cDir == "west" then
- cDir = "south"
- else
- print("Error!!")
- error()
- end
- turtle.turnLeft()
- end
- --turns to specified direction
- function turnTo(dir)
- if cDir ~= dir then
- repeat
- turnRight()
- until cDir == dir
- end
- end
- --overide of turtle.moveForward fucntion
- function moveForward()
- local succes, data = turtle.inspect()
- if succes then
- if data.name == checkItems[4] then
- for i = 1, 27 do
- turtle.suck()
- end
- end
- end
- if cDir == "north" then
- cZ = cZ-1
- elseif cDir == "east" then
- cX = cX+1
- elseif cDir == "south" then
- cZ = cZ+1
- elseif cDir == "west" then
- cX = cX-1
- else
- print("Error!!")
- error()
- end
- while turtle.detect() do
- turtle.dig()
- end
- status = "forward"
- preMoveFuel = turtle.getFuelLevel()
- saveCor()
- while not turtle.forward() do
- turtle.dig()
- end
- status = "none"
- saveCor()
- end
- --overide of turtle.moveUp fucntion
- function moveUp()
- cY = cY+1
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.1)
- end
- status = "up"
- preMoveFuel = turtle.getFuelLevel()
- saveCor()
- while not turtle.up() do
- turtle.digUp()
- end
- status = "none"
- saveCor()
- end
- --overide of turtle.movedown fucntion
- function moveDown()
- cY = cY-1
- while turtle.detectDown() do
- turtle.digDown()
- end
- status = "down"
- preMoveFuel = turtle.getFuelLevel()
- saveCor()
- while not turtle.down() do
- turtle.digDown()
- end
- status = "none"
- saveCor()
- end
- --move to specific y
- function moveToX(x)
- if cX < x then
- turnTo("east")
- repeat
- moveForward()
- until cX == x
- elseif cX > x then
- turnTo("west")
- repeat
- moveForward()
- until cX == x
- else
- --print("already there")
- end
- end
- --move to specific z
- function moveToZ(z)
- if cZ < z then
- turnTo("south")
- repeat
- moveForward()
- until cZ == z
- elseif cZ > z then
- turnTo("north")
- repeat
- moveForward()
- until cZ == z
- else
- --print("already there")
- end
- end
- --move to specific y
- function moveToY(y)
- if cY < y then
- repeat
- moveUp()
- until cY == y
- elseif cY > y then
- repeat
- moveDown()
- until cY == y
- else
- --print("already there")
- end
- end
- --goes to a specific place
- function goTo(x, y, z)
- moveToX(x)
- moveToY(y)
- moveToZ(z)
- turnTo("north")
- end
- --if there is space in his inventory
- function checkInventory()
- if turtle.getItemDetail(13) == nil then
- else
- dropItems()
- end
- end
- --drops its items in his enderchest
- function dropItems()
- special = "drop items"
- saveCor()
- turnRight()
- turnRight()
- turtle.select(16)
- while not turtle.place() do
- turtle.dig()
- end
- for i = 1, 14 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(16)
- turtle.dig()
- turtle.select(1)
- turnRight()
- turnRight()
- special = "none"
- saveCor()
- end
- --Needed for checkDown()
- function lavaDown()
- local data = turtle.getItemDetail(15)
- if data.name == "minecraft:bucket" then
- turtle.select(15)
- turtle.placeDown()
- turtle.refuel()
- turtle.select(1)
- elseif data == nil then
- else
- turtle.select(15)
- turtle.placeDown()
- turtle.select(1)
- end
- end
- --needed for checkUp()
- function lavaUp()
- local data = turtle.getItemDetail(15)
- if data.name == "minecraft:bucket" then
- turtle.select(15)
- turtle.placeUp()
- turtle.refuel()
- turtle.select(1)
- elseif data == nil then
- else
- turtle.select(15)
- turtle.placeUp()
- turtle.select(1)
- end
- end
- --checks block down
- function checkDown()
- local succes, data = turtle.inspectDown()
- if succes then
- if data.name == checkItems[1] then
- elseif data.name == checkItems[2] then
- elseif data.name == checkItems[3] then
- elseif data.name == checkItems[4] then
- for i = 1, 27 do
- turtle.suckDown()
- end
- turtle.digDown()
- elseif data.name == checkItems[5] then
- lavaDown()
- else
- turtle.digDown()
- end
- end
- end
- --checks block up
- function checkUp()
- local succes, data = turtle.inspectUp()
- if succes then
- if data.name == checkItems[1] then
- elseif data.name == checkItems[2] then
- elseif data.name == checkItems[4] then
- for i = 1, 27 do
- turtle.suckUp()
- end
- turtle.digUp()
- elseif data.name== checkItems[5] then
- lavaUp()
- else
- turtle.digUp()
- end
- end
- end
- --Checks the blocks above and below
- function checkBlocks()
- checkUp()
- checkDown()
- checkInventory()
- end
- --part of square
- function row()
- checkBlocks()
- for i = 1, size-1 do
- moveForward()
- checkBlocks()
- end
- end
- --Does one layer of mining
- function square()
- workingY = cY
- saveCor()
- print("Layer: "..workingY)
- local count = 1
- for i = 1, size do
- row()
- if count ~= size then
- if turns == 0 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- count = count+1
- end
- end
- end
- --goes to the next layer
- function nextLayer()
- special = "Next_layer"
- saveCor()
- for i = 1,3 do
- moveUp()
- end
- turnRight()
- turnRight()
- special = "none"
- saveCor()
- end
- --main mining program
- function Bedrock()
- square()
- while cY ~= toY do
- if cY == toY-1 then
- break
- elseif cY == toY-2 then
- moveUp()
- moveUp()
- turnRight()
- turnRight()
- square()
- else
- nextLayer()
- square()
- end
- end
- end
- --calculates the energy needed
- function calcEnergy()
- eNeeded = size*size*(cY/3)+cY*2
- end
- --starting program part 1
- function startProg()
- print("---------------------------------------")
- print("Advanced ore mining quarry")
- print("Made by: Cing")
- print("---------------------------------------")
- print("Please put first coal in slot 1...")
- print("a bucket or filling blocks in slot 15..")
- print("and a enderchest in slot 16.")
- print("And don't forget to chunkload the area.")
- os.pullEvent()
- while turtle.getItemDetail(16) == nil do
- print("Please put a enderchest in slot 16.")
- os.pullEvent()
- end
- write("What is the YLevel: ")
- cY = tonumber(read())
- home = cY
- workingY = 2
- write("What size do you want: ")
- size = tonumber(read())
- write("Until what Y should I dig: ")
- toY = tonumber(read())
- turtle.select(1)
- turtle.refuel()
- calcEnergy()
- while eNeeded > turtle.getFuelLevel() do
- print("Please put more coal in slot 1")
- os.pullEvent()
- turtle.refuel()
- end
- saveCor()
- end
- --starting program part 2
- function working()
- special = "going down"
- saveCor()
- while cY ~= 2 do
- moveDown()
- end
- special = "none"
- saveCor()
- clear()
- print("Digging!")
- Bedrock()
- special = "going up"
- saveCor()
- goTo(0,home,0)
- dropItems()
- deleteFiles()
- end
- --check if the turtle has moved or not
- function checkMove()
- sleep(1)
- if status == "forward" then
- if preMoveFuel == turtle.getFuelLevel() then
- if cDir == "north" then
- cZ = cZ+1
- elseif cDir == "east" then
- cX = cX-1
- elseif cDir == "south" then
- cZ = cZ-1
- elseif cDir == "west" then
- cX = cX+1
- else
- print("There went something wrong!")
- error()
- end
- status = "none"
- saveCor()
- elseif preMoveFuel == turtle.getFuelLevel()-1 then
- status = "none"
- saveCor()
- else
- print("There went something wrong!")
- error()
- end
- elseif status == "up" then
- if preMoveFuel == turtle.getFuelLevel() then
- cY = cY-1
- status = "none"
- saveCor()
- elseif preMoveFuel == turtle.getFuelLevel()-1 then
- status = "none"
- saveCor()
- else
- print("There went something wrong!")
- error()
- end
- elseif status == "down" then
- if preMoveFuel == turtle.getFuelLevel() then
- cY = cY+1
- status = "none"
- saveCor()
- elseif preMoveFuel == turtle.getFuelLevel()-1 then
- status = "none"
- saveCor()
- else
- print("There went something wrong!")
- error()
- end
- elseif status == "none" then
- else
- print("There went something wrong!")
- error()
- end
- end
- --code for resuming after shutdown
- function resume()
- if cDir == "east" or cDir == "west" or special == "Next_layer" then
- goTo(0,workingY,0)
- turns = 0
- else
- if cDir == "north" then
- while (cZ*-1)+1 ~= size do
- moveForward()
- checkBlocks()
- end
- if turns == 0 then
- if cX ~= size-1 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- end
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- elseif cDir == "south" then
- while cZ ~= 0 do
- moveForward()
- checkBlocks()
- end
- if turns == 1 then
- if cX ~= size-1 then
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- else
- if cX ~= 0 then
- turnRight()
- moveForward()
- turnLeft()
- turns = 1
- end
- end
- end
- if cDir == "north" and turns == 0 then
- print("Layer Positief")
- if cX+1 ~= size then
- for i = 1, (size-(cX+1)) do
- row()
- if cX ~= size-1 then
- if turns == 0 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- end
- end
- row()
- end
- elseif cDir == "south" and turns == 1 then
- print("Layer Positief")
- if cX+1 ~= size then
- for i = 1, (size-(cX+1)) do
- row()
- if cX ~= size-1 then
- if turns == 0 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- end
- end
- row()
- end
- elseif cDir == "north" and turns == 1 then
- print("Layer Negetiaf")
- if cX ~= 0 then
- for i = 1, cX+1 do
- row()
- if cX ~= 0 then
- if turns == 0 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- end
- end
- row()
- end
- elseif cDir == "south" and turns == 0 then
- print("Layer Negetiaf")
- if cX ~= 0 then
- for i = 1, cX+1 do
- row()
- if cX ~= 0 then
- if turns == 0 then
- turnRight()
- moveForward()
- turnRight()
- turns = 1
- else
- turnLeft()
- moveForward()
- turnLeft()
- turns = 0
- end
- end
- end
- row()
- end
- else
- print("There went something wrong!")
- error()
- end
- if cY == toY then
- goTo(0,cY,0)
- turns = 0
- saveCor()
- elseif cY == toY-1 then
- goTo(0,cY,0)
- turns = 0
- saveCor()
- elseif cY == toY-2 then
- goTo(0,(cY+2),0)
- turns = 0
- saveCor()
- else
- nextLayer()
- goTo(0,cY,0)
- turns = 0
- saveCor()
- end
- end
- end
- --Main program
- if fs.exists("path") then
- local file = fs.open("path","r")
- cX = tonumber(file.readLine())
- cY = tonumber(file.readLine())
- cZ = tonumber(file.readLine())
- cDir = file.readLine()
- workingY = tonumber(file.readLine())
- size = tonumber(file.readLine())
- toY = tonumber(file.readLine())
- home = tonumber(file.readLine())
- status = file.readLine()
- turns = tonumber(file.readLine())
- special = file.readLine()
- preMoveFuel = tonumber(file.readLine())
- file.close()
- checkMove()
- if special == "drop items" then
- if turtle.getItemCount(16) == 0 then
- print("No enderchest")
- error()
- else
- goTo(0,workingY,0)
- turns = 0
- special = "none"
- saveCor()
- end
- elseif special == "going down" then
- goTo(0,2,0)
- turns = 0
- elseif special == "going up" then
- goTo(0,home,0)
- dropItems()
- deleteFiles()
- clear()
- print("Done!!")
- error()
- else
- resume()
- end
- Bedrock()
- goTo(0,home,0)
- dropItems()
- deleteFiles()
- clear()
- print("Done!!!")
- else
- startProg()
- working()
- clear()
- print("Done!!!")
- end
Add Comment
Please, Sign In to add comment