Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Davis Cook's myExcavate (Totaly written from scratch)
- x=0 --forward
- y=0 --down
- z=0 --right (Perpendicular to "forward")
- lookdir="forward"
- function checkFuel()
- fuelLvl = turtle.getFuelLevel()
- --print("Checking Fuel Level...")
- if fuelLvl<100 then
- --print("Needs Fuel, Refueling..")
- turtle.select(16)
- turtle.refuel(2)
- else
- --print("No Fuel Needed.")
- end
- end
- function left()
- turtle.turnLeft()
- end
- function right()
- turtle.turnRight()
- end
- function lookDir(s) -- Options are "forward" "left" "right" "back" --print("Looking " .. s)
- if ((lookdir=="forward") and (s=="forward")) then
- elseif ((lookdir=="forward") and (s=="right")) then right()
- elseif ((lookdir=="forward") and (s=="left")) then left()
- elseif ((lookdir=="forward") and (s=="back")) then left() left()
- elseif ((lookdir=="right") and (s=="forward")) then left()
- elseif ((lookdir=="right") and (s=="right")) then
- elseif ((lookdir=="right") and (s=="left")) then left() left()
- elseif ((lookdir=="right") and (s=="back")) then right()
- elseif ((lookdir=="left") and (s=="forward")) then right()
- elseif ((lookdir=="left") and (s=="right")) then left() left()
- elseif ((lookdir=="left") and (s=="left")) then
- elseif ((lookdir=="left") and (s=="back")) then left()
- elseif ((lookdir=="back") and (s=="forward")) then left() left()
- elseif ((lookdir=="back") and (s=="right")) then left()
- elseif ((lookdir=="back") and (s=="left")) then right()
- elseif ((lookdir=="back") and (s=="back")) then
- end
- lookdir = s
- end
- function forward()
- checkFuel()
- while turtle.forward()==false do
- turtle.attack()
- turtle.dig()
- end
- if lookdir=="forward" then x=x+1
- elseif lookdir=="right" then z=z+1
- elseif lookdir=="left" then z=z-1
- elseif lookdir=="back" then x=x-1
- end
- end
- function up()
- checkFuel()
- while turtle.up()==false do
- turtle.attackUp()
- turtle.digUp()
- end
- y=y+1
- end
- function down()
- checkFuel()
- while turtle.down()==false do
- turtle.attackDown()
- turtle.digDown()
- end
- y=y-1
- end
- function reSupply()
- print("Re-Supplying")
- checkFuel()
- savex = x
- savey = y
- savez = z
- savedir=lookdir
- lookDir("back")
- while y~=0 do
- up()
- end
- while x~=0 do
- forward()
- end
- while z~=0 do
- lookDir("left")
- forward()
- end
- print("Grabbing Fuel...")
- while ((turtle.getItemCount(16)<10) and (turtle.getFuelLevel()<300)) do
- turtle.select(16)
- turtle.suckUp()
- end
- lookDir("back")
- print("Emptying Inventory...")
- for slot=1, 15 do
- turtle.select(slot)
- turtle.drop()
- end
- rs.setOutput("front",true)
- sleep(1)
- rs.setOutput("front",false)
- lookDir("forward")
- while x~=savex do
- forward()
- end
- while z~=savez do
- lookDir("right")
- forward()
- end
- while y~=savey do
- down()
- end
- lookDir(savedir)
- end
- function digupdown()
- turtle.digUp()
- turtle.digDown()
- end
- function needResupply()
- n=1
- for q=1,15 do
- if ((turtle.getItemCount(q)>0) or ((turtle.getFuelLevel()<100) and (turtle.getItemCount(16)<4))) then
- n=n+1
- end
- end
- if n>13 then reSupply() end
- end
- function goHome()
- print("Going Home")
- checkFuel()
- lookDir("back")
- while y~=0 do
- up()
- end
- while x~=0 do
- forward()
- end
- while z~=0 do
- lookDir("left")
- forward()
- end
- lookDir("forward")
- end
- function excavate(length,width,depth)
- checkFuel()
- down()
- down()
- for u=1,(depth/3) do
- for o=1,(width/2) do
- for i=1,(length-1) do
- needResupply()
- digupdown()
- forward()
- end
- digupdown()
- lookDir("right")
- forward()
- lookDir("back")
- for p=2,length do
- needResupply()
- digupdown()
- forward()
- end
- digupdown()
- if o~=(width/2) then
- lookDir("right")
- forward()
- lookDir("forward")
- end
- end
- lookDir("left")
- for r=2,width do
- forward()
- end
- lookDir("forward")
- if u~=(depth/3) then
- down()
- down()
- down()
- end
- end
- end
- function bedRock()
- print("At Bedrock Level.")
- print("Running Bedrock Code...")
- for h=1,(width/2) do
- for j=2,length do
- checkFuel()
- hole=0
- while turtle.down() do
- y=y-1
- turtle.digDown()
- hole=hole+1
- end
- while hole~=0 do
- up()
- hole=hole-1
- end
- if j~=length then
- forward()
- end
- end
- while turtle.down() do
- y=y-1
- turtle.digDown()
- hole=hole+1
- end
- while hole~=0 do
- up()
- hole=hole-1
- end
- lookDir("right")
- forward()
- lookDir("back")
- for b=2,length do
- checkFuel()
- hole=0
- while turtle.down() do
- y=y-1
- turtle.digDown()
- hole=hole+1
- end
- while hole~=0 do
- up()
- hole=hole-1
- end
- if b~=length then
- forward()
- end
- end
- while turtle.down() do
- y=y-1
- turtle.digDown()
- hole=hole+1
- end
- while hole~=0 do
- up()
- hole=hole-1
- end
- if h~=(width/2) then
- lookDir("right")
- forward()
- lookDir("forward")
- end
- end
- end
- print("Davis Cook's myExcavate")
- print("")
- print("Length can Be Anything above 2.")
- print("Length?")
- length= io.read()
- print("Width has to be Even and Above 2.")
- print("Width?")
- width= io.read()
- print("To Go All The Way To Bedrock, do: y_coord-5")
- print("Depth?")
- depth=io.read()
- print("Dig Bellow Bedrock? yes or no")
- decision=io.read()
- reSupply()
- excavate(length,width,(depth))
- if decision=="yes" then
- bedRock()
- end
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement