Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xpos = -1
- local ypos = -1
- local zpos = -1
- local dir = -1
- local function fastFail(success)
- if not success then
- print("An unexpected error has occured! Aborting.")
- exit()
- end
- end
- local function refuel(amount)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- turtle.select(16)
- while turtle.getItemCount(16) > 0 and turtle.getFuelLevel() < amount do
- if not turtle.refuel(1) then
- return false
- end
- end
- if turtle.getFuelLevel() < amount then
- return false
- else
- return true
- end
- end
- local function waitForFuel(amount)
- if not refuel(amount) then
- print("Please put fuel in slot 16")
- while not refuel(amount) do
- sleep(0.5)
- end
- print("Received sufficient fuel. Continuing...")
- end
- end
- local function selectSapling()
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == "terrestria:hemlock_sapling" then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- local function countSaplings()
- num = 0
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == "terrestria:hemlock_sapling" then
- num = num + itemDetail.count
- end
- end
- return num
- end
- local function waitForSapling(amount)
- if countSaplings() < amount then
- print("Please provide more hemlock saplings")
- while countSaplings() < amount do
- sleep(0.5)
- end
- print("Received saplings. Continuing...")
- end
- selectSapling()
- end
- local function waitForDrop()
- if turtle.getItemCount() > 0 and not turtle.drop() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.drop() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function waitForDropDown()
- if turtle.getItemCount() > 0 and not turtle.dropDown() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.dropDown() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function getBlock()
- hasBlock, data = turtle.inspect()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockDown()
- hasBlock, data = turtle.inspectDown()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockUp()
- hasBlock, data = turtle.inspectUp()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function isImpermeable(name)
- if name == "minecraft:stone_bricks" or name == "minecraft:dirt" or name == "minecraft:chest" or name == "minecraft:barrel" then
- return true
- else
- return false
- end
- end
- local function tryForwards()
- waitForFuel(1)
- -- if not turtle.detect() then
- -- turtle.suck()
- -- end
- while not turtle.forward() do
- if isImpermeable(getBlock()) then
- return false
- end
- if turtle.detect() then
- if not turtle.dig() then
- return false
- end
- elseif not turtle.attack() then
- sleep(0.5)
- end
- end
- if dir == 0 then
- xpos = xpos + 1
- elseif dir == 1 then
- zpos = zpos + 1
- elseif dir == 2 then
- xpos = xpos - 1
- elseif dir == 3 then
- zpos = zpos - 1
- end
- return true
- end
- local function tryDown()
- -- if not turtle.detectDown() then
- -- turtle.suckDown()
- -- end
- waitForFuel(1)
- while not turtle.down() do
- if isImpermeable(getBlockDown()) then
- return false
- end
- if turtle.detectDown() then
- if not turtle.digDown() then
- return false
- end
- elseif not turtle.attackDown() then
- sleep(0.5)
- end
- end
- if dir >= 0 then
- ypos = ypos - 1
- end
- return true
- end
- local function tryUp()
- -- if not turtle.detectUp() then
- -- turtle.suckUp()
- -- end
- waitForFuel(1)
- while not turtle.up() do
- if isImpermeable(getBlockUp()) then
- return false
- end
- if turtle.detectUp() then
- if not turtle.digUp() then
- return false
- end
- elseif not turtle.attackUp() then
- sleep(0.5)
- end
- end
- if dir >= 0 then
- ypos = ypos + 1
- end
- return true
- end
- local function turnLeft()
- -- if not turtle.detect() then
- -- turtle.suck()
- -- end
- turtle.turnLeft()
- dir = (dir + 1) % 4
- end
- local function turnRight()
- -- if not turtle.detect() then
- -- turtle.suck()
- -- end
- turtle.turnRight()
- dir = (dir + 3) % 4
- end
- local function recenter()
- waitForFuel(128)
- while not isImpermeable(getBlockDown()) do
- tryDown()
- end
- while getBlockDown() ~= "minecraft:chest" do
- if not tryForwards() then
- turtle.turnLeft()
- end
- end
- while getBlock() ~= "minecraft:barrel" do
- turtle.turnLeft()
- end
- xpos = 2
- zpos = 0
- ypos = 0
- dir = 0
- end
- recenter()
- while true do
- -- Refuel
- turtle.select(16)
- waitForDrop()
- turtle.suck()
- if not refuel(1024) then
- print("Waiting for fuel...")
- sleep(0.5)
- while not refuel(1024) do
- sleep(0.5)
- waitForDrop()
- turtle.suck()
- end
- end
- turnLeft()
- while getBlock() == "terrestria:hemlock_sapling" do
- sleep(0.5)
- end
- fastFail(tryForwards())
- turnRight()
- for i=0, 63 do
- if turtle.detectUp() then
- for j=0, 3 do
- turtle.dig()
- turnRight()
- turtle.dig()
- turnRight()
- turnRight()
- fastFail(tryForwards())
- end
- end
- if i ~= 63 then
- fastFail(tryUp())
- end
- end
- for i=0, 61 do
- fastFail(tryDown())
- end
- waitForSapling(4)
- for j=0, 3 do
- turnLeft()
- fastFail(tryForwards())
- waitForSapling(1)
- turtle.placeDown()
- end
- turnRight()
- fastFail(tryForwards())
- turnLeft()
- fastFail(tryDown())
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name ~= "terrestria:hemlock_sapling" then
- turtle.select(i)
- waitForDropDown()
- end
- end
- for i=1, 12 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == "terrestria:hemlock_sapling" then
- turtle.select(i)
- turtle.transferTo(13)
- turtle.transferTo(14)
- turtle.transferTo(15)
- waitForDropDown()
- end
- end
- turtle.select(16)
- if not turtle.refuel(0) then
- waitForDropDown()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment