Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, z = 0, 0
- local xdir, zdir = 0, 1
- local collect
- local refuel
- local function select(c)
- turtle.select(c)
- end
- local function forward()
- refuel()
- while not turtle.forward() do
- if turtle.dig() then
- collect()
- else
- turtle.attack()
- end
- end
- x, z = x + xdir, z + zdir
- return true
- 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)
- turtle.up()
- 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
- turtle.down()
- end
- local function dumpResources()
- local prevx, prevz, prevxd, prevzd = x, z, xdir, zdir
- 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
- print("useful item detected!")
- else
- turtle.drop()
- end
- end
- goTo(prevx, prevz, prevxd, prevzd)
- end
- function collect()
- for c=1, 16 do
- turtle.select(c)
- if turtle.getItemCount() == 0 then
- select(1)
- return
- end
- end
- dumpResources()
- print("dumping resources")
- end
- local function dig()
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.5f)
- collect()
- end
- end
- end
- local function digUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- sleep(0.5f)
- collect()
- end
- end
- end
- local function fuelCheck()
- print ("Fuel level at "..turtle.getFuelLevel())
- if turtle.getFuelLevel() < 10 then
- print ("Out of fuel!")
- for n=1, 16 do
- turtle.select(n)
- if turtle.refuel() then
- turtle.select(1)
- return true
- end
- end
- return false
- end
- return true
- end
- function refuel()
- while not fuelCheck() do
- os.pullEvent("turtle_inventory")
- 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)
- return
- end
- end
- end
- local function tunnel()
- local blockCount = 0
- for a=1, 32 do
- forward()
- platform()
- digUp()
- 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
- local function returnTunnel()
- local blockCount = 0
- turtle.up()
- for a=1, 32 do
- while not forward() do
- dig()
- end
- end
- turtle.down()
- end
- for n=1, 16 do
- digUp()
- turnLeft()
- tunnel()
- turnRight()
- turnRight()
- returnTunnel()
- tunnel()
- turnRight()
- turnRight()
- returnTunnel()
- turnRight()
- forward()
- platform()
- digUp()
- if n > 1 then
- for p=1, 16 do
- turtle.select(p)
- if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:torch" then
- turnLeft()
- turnLeft()
- turtle.place()
- turnLeft()
- turnLeft()
- turtle.select(1)
- end
- end
- end
- for a=1, 2 do
- forward()
- platform()
- digUp()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement