Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("persistence")
- currentFace = persistence.pull("currentFace")
- currentRadius = persistence.pull("currentRadius")
- endRadius = persistence.pull("endRadius")
- currentX = persistence.pull("currentX")
- currentZ = persistence.pull("currentZ")
- digCount = persistence.pull("digCount")
- --functions
- function get()
- term.clear()
- term.setCursorPos(1,1)
- print("currentFace: "..persistence.pull("currentFace"))
- print("currentRadius: "..persistence.pull("currentRadius"))
- print("endRadius: "..persistence.pull("endRadius"))
- print("currentX: "..persistence.pull("currentX"))
- print("currentZ: "..persistence.pull("currentZ"))
- print("digCount: "..persistence.pull("digCount"))
- print("fuelLevel: "..turtle.getFuelLevel())
- end
- function left()
- turtle.turnLeft()
- currentFace = persistence.pull("currentFace")
- if currentFace == 0 then
- currentFace = persistence.store("currentFace",3)
- return
- end
- if currentFace == 1 then
- currentFace = persistence.store("currentFace",0)
- return
- end
- if currentFace == 2 then
- currentFace = persistence.store("currentFace",1)
- return
- end
- if currentFace == 3 then
- currentFace = persistence.store("currentFace",2)
- return
- end
- end
- function right()
- currentFace = persistence.pull("currentFace")
- turtle.turnRight()
- if currentFace == 0 then
- currentFace = persistence.store("currentFace",1)
- return
- end
- if currentFace == 1 then
- currentFace = persistence.store("currentFace",2)
- return
- end
- if currentFace == 2 then
- currentFace = persistence.store("currentFace",3)
- return
- end
- if currentFace == 3 then
- currentFace = persistence.store("currentFace",0)
- return
- end
- end
- function face0()
- call()
- if currentFace == 1 then
- left()
- return
- end
- if currentFace == 2 then
- left()
- left()
- return
- end
- if currentFace == 3 then
- right()
- return
- end
- end
- function face1()
- call()
- if currentFace == 2 then
- left()
- return
- end
- if currentFace == 3 then
- left()
- left()
- return
- end
- if currentFace == 0 then
- right()
- return
- end
- end
- function face2()
- call()
- if currentFace == 3 then
- left()
- return
- end
- if currentFace == 0 then
- left()
- left()
- return
- end
- if currentFace == 1 then
- right()
- return
- end
- end
- function face3()
- call()
- if currentFace == 0 then
- left()
- return
- end
- if currentFace == 1 then
- left()
- left()
- return
- end
- if currentFace == 2 then
- right()
- return
- end
- end
- function forward()
- currentFace = persistence.pull("currentFace")
- get()
- checkFuel()
- checkInv()
- while not turtle.forward() do
- checkInv()
- if turtle.dig() then
- digCount = persistence.pull("digCount")
- digCount = persistence.store("digCount",tonumber(digCount)+1)
- elseif not turtle.attack() then
- print("Something is blocking me")
- sleep(10)
- end
- end
- currentX = persistence.pull("currentX")
- currentZ = persistence.pull("currentZ")
- if currentFace == 0 then
- currentZ = persistence.store("currentZ",currentZ+1)
- end
- if currentFace == 1 then
- currentX = persistence.store("currentX",currentX-1)
- end
- if currentFace == 2 then
- currentZ = persistence.store("currentZ",currentZ-1)
- end
- if currentFace == 3 then
- currentX = persistence.store("currentX",currentX+1)
- end
- get()
- end
- function dig()
- digCount = persistence.pull("digCount")
- checkInv()
- if turtle.digDown() then
- digCount = persistence.store("digCount", digCount+1)
- end
- while turtle.detectUp() do
- digCount = persistence.pull("digCount")
- checkInv()
- if turtle.digUp() then
- digCount = persistence.store("digCount",digCount+1)
- sleep(0.8)
- else
- print("I can't dig up")
- sleep(10)
- end
- end
- end
- function checkFuel()
- if turtle.getFuelLevel() < 10 then
- refuel()
- end
- end
- function checkInv()
- if turtle.getItemCount(15) < 1 then --checks to see if refuel chest is present
- refuel()
- end
- if turtle.getItemCount(16) < 1 then --checks to see if unload chest is present
- unload()
- end
- for i=13,14 do
- if turtle.getItemCount(i) > 0 then -- checks slots 13 and 14 for items
- unload()
- end
- end
- end
- function unload()
- if turtle.getItemCount(16) > 0 then --if the unload chest is present
- if turtle.detectDown() then
- digCount = persistence.pull("digCount")
- while not turtle.digDown() and turtle.detectDown() do
- term.clear()
- term.setCursorPos(1,1)
- print("I can't dig down")
- sleep(10)
- end
- digCount = persistence.store("digCount",digCount+1)
- end
- end
- if turtle.getItemCount(16) < 1 then --if unload chest is missing
- if not turtle.detectDown() then --the chest isn't in inv or below
- print("I'VE LOST MY CHEST!!!")
- while turtle.getItemCount(16) < 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("please put an unload chest in slot(16)...")
- sleep(10)
- end
- end
- if turtle.detectDown() then --the chest is below the turtle
- turtle.select(16)
- turtle.digDown()
- turtle.select(1)
- end
- end
- turtle.select(16)
- turtle.placeDown()
- for i=1,14 do
- while turtle.getItemCount(i) > 0 do
- turtle.select(i)
- if not turtle.dropDown() then
- sleep(10) -- waiting for space in chest
- end
- end
- end
- turtle.select(16)
- turtle.digDown()
- turtle.select(1)
- end
- function refuel()
- unload()
- if turtle.getItemCount(15) > 0 then --Refuel chest is present
- if turtle.detectUp() then
- digCount = persistence.pull("digCount")
- while not turtle.digUp() and turtle.detectUp() do
- term.clear()
- term.setCursorPos(1,1)
- print("I can't dig up for some reason")
- sleep(10)
- end
- digCount = persistence.store("digCount",digCount+1)
- end
- end
- if turtle.getItemCount(15) < 1 then --if refuel chest isn't in Inv
- if not turtle.detectUp() then
- term.clear()
- term.setCursorPos(1,1)
- print("I've lost my refuel chest")
- while turtle.getItemCount(15) < 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("please put refuel chest in slot(15)")
- sleep(10)
- end
- end
- if turtle.detectUp() then
- turtle.select(15)
- turtle.digUp()
- end
- end
- turtle.select(15)
- turtle.placeUp()
- while turtle.getFuelLevel() < 500 do
- turtle.select(1)
- if not turtle.suckUp() then
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for more fuel in refuel chest")
- sleep(10)
- end
- if turtle.getItemCount(1) > 0 then
- turtle.refuel(turtle.getItemCount(1))
- end
- end
- turtle.select(15)
- turtle.digUp()
- turtle.select(1)
- end
- function call()
- currentX = persistence.pull("currentX")
- currentZ = persistence.pull("currentZ")
- currenFace = persistence.pull("currentFace")
- digCount = persistence.pull("digCount")
- currentRadius = persistence.pull("currentRadius")
- endRadius = persistence.pull("endRadius")
- end
- function spiral()
- call()
- if currentX==0 and currentZ==0 then
- if currentFace ~= 0 then
- face0()
- end
- print("at start")
- dig()
- forward()
- left()
- dig()
- currentRadius = persistence.store("currentRadius",currentRadius+1)
- call()
- get()
- return
- elseif math.abs(currentX) == math.abs(currentZ) then
- if currentZ > 0 and currentX < 0 then
- if currentFace==0 then
- dig()
- forward()
- face3()
- dig()
- forward()
- currentRadius = persistence.store("currentRadius",currentRadius+1)
- call()
- get()
- return
- else
- face3()
- dig()
- forward()
- return
- end
- elseif currentX>0 and currentZ>0 then
- face2()
- dig()
- forward()
- return
- elseif currentX>0 and currentZ<0 then
- face1()
- dig()
- forward()
- return
- elseif currentX<0 and currentZ<0 then
- face0()
- dig()
- forward()
- return
- end
- else
- dig()
- forward()
- return
- end
- end
- function spiralMine()
- call()
- while tonumber(currentRadius) < tonumber(endRadius) do
- spiral()
- end
- end
- spiralMine()
Advertisement
Add Comment
Please, Sign In to add comment