Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Arguments = {...}
- MineSlot = 1 -- Enderchest slot for ores
- EnderFuelSlot = 2 -- Enderchest slot for fuel
- FuelSlot = 3 -- Fuel slot
- TurnRight = true -- Tells the turtle if it has to turn left or right when digging a full line
- -- Coordinates :
- x = 1
- y = 1
- MiningSave = {} -- This table is where every function will refer to. It will store all the variables of the program and allows the turtle to progress in the mining process without being lost.
- -- Here is what every indice refers to :
- -- 1 : Length of the quarry
- -- 2 : Width of the quarry
- -- 3 : Initial height of the turtle
- -- 4,5 : Coordinates of the turtle
- -- 6 : TurnRight
- -- 7,8,9,10,11 : Respectively bedrock, stone, gravel, dirt and sand
- -- Move + Attack + Dig functions
- function MoveForward() -- Move forward + compare up and down
- while turtle.attack() do
- os.sleep(1)
- end
- Mine()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- end
- function MoveUp() -- Move up
- while turtle.attackUp() do
- os.sleep(1)
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.up()
- Fuel()
- end
- function MoveDown() -- Move down
- while turtle.attackDown() do
- os.sleep(1)
- end
- while turtle.detectDown() do
- turtle.digDown()
- end
- turtle.down()
- Fuel()
- end
- function ChangeSide() -- Determines if the turtle has to turn left or right to dig the next line
- if MiningSave[6] == true then
- turtle.turnRight()
- MoveForward()
- turtle.turnRight()
- MiningSave[6] = false
- else turtle.turnLeft()
- MoveForward()
- turtle.turnLeft()
- MiningSave[6] = true
- end
- end
- function Bedrock()
- for i=Height-1,1,-1 do
- MoveUp()
- Fuel()
- OreVerif()
- end
- Oresend()
- fs.delete("MiningFile")
- os.sleep()
- end
- -- End of moving functions
- function Mine()
- if isJunkBlock("up") == false then
- turtle.digUp()
- end
- if isJunkBlock("down") == false then
- turtle.digDown()
- end
- end
- function isJunkBlock(direction)
- for i=9,12 do
- local Success,Data
- if direction == "up" then
- Success,Data = turtle.inspectUp()
- else Success,Data = turtle.inspectDown()
- end
- if Data.name == MiningSave[i] then
- return true
- end
- end
- return false
- end
- function isBedrock()
- local MovingNumber = 0
- for i=1,3 do
- local Success,Data = turtle.inspectDown()
- if Success and Data.name == MiningSave[7] and MovingNumber < 3 then
- Bedrock()
- else MovingNumber = MovingNumber+1
- end
- MoveDown()
- end
- end
- function OreVerif() -- Detects if there are blocks in the last slot
- if turtle.getItemCount(16) >= 1 then
- if turtle.getFuelLevel() <= 4 then
- Refuel()
- end
- Oresend()
- else return true
- end
- end
- function Oresend() -- Sends ores to the enderchest
- if turtle.detectUp() then
- turtle.digUp()
- os.sleep(0.2)
- end
- MoveUp()
- if turtle.detectUp() then
- turtle.digUp()
- os.sleep(0.2)
- end
- MoveDown()
- turtle.select(MineSlot)
- turtle.placeUp()
- for i=4,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(MineSlot)
- turtle.digUp()
- end
- function Fuel() -- Detects if the fuel level is too low
- if turtle.getFuelLevel() <= 4 then
- turtle.select(FuelSlot)
- if turtle.getItemCount() <= 2 then
- Refuel()
- end
- turtle.refuel(1)
- else return true
- end
- end
- function Refuel() -- Reloads with fuel in the enderchest
- local Space=turtle.getItemSpace(FuelSlot)
- if turtle.detectUp() == true then
- turtle.digUp()
- os.sleep(0.2)
- end
- MoveUp()
- if turtle.detectUp() == true then
- turtle.digUp()
- os.sleep(0.2)
- end
- MoveDown()
- turtle.select(EnderFuelSlot)
- turtle.placeUp()
- turtle.select(FuelSlot)
- turtle.suckUp(Space)
- turtle.select(EnderFuelSlot)
- turtle.digUp()
- end
- function FsSave()
- local file = fs.open("MiningFile","w")
- file.write(textutils.serialize(MiningSave))
- file.close()
- end
- function FsLoad()
- local file = fs.open("MiningFile","r")
- local MiningData = file.readAll()
- file.close()
- MiningSave = textutils.unserialize(MiningData)
- Perimeter = 2*(MiningSave[1]+MiningSave[2])
- end
- function Recover()
- if turtle.getItemCount(1) == 0 then
- turtle.select(1)
- turtle.digUp()
- elseif turtle.getItemCount(2) == 0 then
- turtle.select(2)
- turtle.digUp()
- end
- end
- function Start()
- if #Arguments == 3 then
- Length = Arguments[1]
- Width = Arguments[2]
- Height = Arguments[3]
- else os.reboot()
- end
- if turtle.getItemCount(1) == 0 or turtle.getItemCount(2) == 0 or turtle.getItemCount(3) == 0 then
- os.reboot()
- end
- print("Excavator 2000 by Fiixii52")
- print("The turtle will dig this zone down to the bedrock.")
- print("This program only works with FLAT bedrock. Please ensure that it is your case !")
- print("Type Yes to start it.")
- local start = io.read()
- if start == "Yes" then
- term.clear()
- turtle.select(4)
- table.insert(MiningSave,Length)
- table.insert(MiningSave,Width)
- table.insert(MiningSave,Height)
- table.insert(MiningSave,x)
- table.insert(MiningSave,y)
- table.insert(MiningSave,TurnRight)
- table.insert(MiningSave,"minecraft:bedrock")
- table.insert(MiningSave,"minecraft:stone")
- table.insert(MiningSave,"minecraft:gravel")
- table.insert(MiningSave,"minecraft:dirt")
- table.insert(MiningSave,"minecraft:sand")
- for i=1,11 do
- print(MiningSave[i])
- end
- Perimeter = 2*(MiningSave[1]+MiningSave[2])
- else os.reboot()
- end
- end
- if fs.exists("MiningFile") == true then
- Recover()
- FsLoad()
- Fuel()
- OreVerif()
- else Start()
- end
- while true do
- Fuel()
- OreVerif()
- if MiningSave[4] == MiningSave[1] then
- if MiningSave[5] == MiningSave[2] then
- if MiningSave[6] == true then
- turtle.turnRight()
- turtle.turnRight()
- else turtle.turnRight()
- end
- isBedrock()
- MiningSave[4] = 1
- MiningSave[5] = 1
- if MiningSave[6] == false then -- Calculates the new width and length if the turtle finished digging the zone in the opposite direction of when he started.
- MiningSave[1] = MiningSave[2]
- MiningSave[2] = (Perimeter-2*MiningSave[1])/2 -- Calculates the new width with the perimeter which stays the same. If we would have typed MiningSave[2] = MiningSave[1], it would have taken the new value of MiningSave[1].
- MiningSave[6] = true
- end
- else Mine()
- ChangeSide()
- MiningSave[5] = MiningSave[5]+1
- MiningSave[4] = 1
- end
- else MoveForward()
- MiningSave[4] = MiningSave[4]+1
- end
- FsSave()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement