Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x = 0
- local z = 0
- local xdir = 0
- local zdir = 1
- local tryDig
- local function forward()
- while not turtle.forward() do
- tryDig()
- end
- x = x + xdir
- z = z + zdir
- end
- local function turnLeft()
- turtle.turnLeft()
- xdir, zdir = -zdir, xdir
- end
- local function turnRight()
- turtle.turnRight()
- xdir, zdir = zdir, -xdir
- end
- local function goTo(xpos, zpos, xface, zface)
- if x < xpos then
- while xdir ~= 1 do
- turnRight()
- end
- while x < xpos do
- forward()
- end
- end
- if x > xpos then
- while xdir ~= -1 do
- turnRight()
- end
- while x > xpos do
- forward()
- end
- end
- if z > zpos then
- while zdir ~= -1 do
- turnRight()
- end
- while z > zpos do
- forward()
- end
- end
- if z < zpos then
- print("z is less than zero. Something is probably wrong!")
- while zdir ~= 1 do
- turnRight()
- end
- while z < zpos do
- forward()
- end
- end
- while xdir ~= xface or zdir ~= zface do
- turnRight()
- end
- end
- local function collect()
- local prevx, prevz, prevxd, prevzd = x, z, xdir, zdir
- local bUnload = false
- for c=1, 16 do
- select(c)
- if turtle.getItemCount() == 0 then
- bUnload = false
- return
- end
- end
- if bUnload == true then
- goTo(0, 0, 0, -1)
- for c=1, 16 do
- turtle.select(c)
- if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:torch" or turtle.refuel(0) then
- break
- end
- turtle.drop()
- end
- goTo(prevx, prevz, prevxd, prevzd)
- end
- end
- function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.1f)
- -- collect()
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- sleep(0.1f)
- -- collect()
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- sleep(0.1f)
- collect()
- else
- return false
- end
- end
- return true
- end
- local function fuelCheck()
- print("Fuel level at "..turtle.getFuelLevel())
- if turtle.getFuelLevel() < 1 then
- for n=1, 16 do
- turtle.select(n)
- if turtle.refuel() then
- turtle.select(1)
- return true
- end
- end
- print("Please Supply Fuel")
- return false
- end
- return true
- end
- local function refuel()
- while not fuelCheck() do
- os.pullEvent("turtle_inventory")
- end
- end
- local function dig()
- refuel()
- while not forward() do
- if turtle.detect() then
- tryDig()
- print("trydig loop!")
- end
- end
- end
- local function digUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- tryDigUp()
- end
- end
- end
- local function platform()
- for a=1, 16 do
- turtle.select(a)
- if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:cobblestone" then
- turtle.placeDown()
- turtle.select(1)
- break
- end
- end
- end
- local function tunnel()
- print("Beginning tunnel!")
- for a=1, 32 do
- dig()
- platform()
- tryDigUp()
- end
- end
- local function returnTunnel()
- print("Ending tunnel!")
- local blockCount = 0
- for a=1, 32 do
- refuel()
- while not forward() do
- tryDig()
- end
- blockCount = blockCount + 1
- if blockCount == 8 then
- for a=1, 16 do
- turtle.select(a)
- if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:torch" then
- if turtle.getItemCount() > 1 then
- blockCount = 0
- turnLeft()
- turnLeft()
- turtle.place()
- turnLeft()
- turnLeft()
- turtle.select(1)
- break
- end
- end
- end
- end
- end
- end
- for n=1, 16 do
- tryDigUp()
- turnLeft()
- tunnel()
- turnRight()
- turnRight()
- returnTunnel()
- tunnel()
- turnLeft()
- turnLeft()
- returnTunnel()
- turnRight()
- for a=1, 3 do
- dig()
- tryDigUp()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement