Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 selectItem(name)
- for i=15, 1, -1 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- local function countItem(name)
- num = 0
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- num = num + itemDetail.count
- end
- end
- return num
- end
- local function waitForItem(name, amount)
- if countItem(name) < amount then
- print("Please provide more " .. name)
- while countItem(name) < amount do
- sleep(0.5)
- end
- print("Received sufficient " .. name .. ". Continuing...")
- end
- selectItem(name)
- 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 waitForDropUp()
- if turtle.getItemCount() > 0 and not turtle.dropUp() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.dropUp() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function containerRefuel(amount)
- turtle.select(16)
- waitForDropUp() -- Edit this line to when changing refuel direction
- turtle.suckUp() -- Edit this line to when changing refuel direction
- if not refuel(amount) then
- print("Waiting for fuel...")
- sleep(0.5)
- while not refuel(amount) do
- sleep(0.5)
- waitForDropUp() -- Edit this line to when changing refuel direction
- turtle.suckUp() -- Edit this line to when changing refuel direction
- end
- end
- end
- local function getBlock()
- local hasBlock, data = turtle.inspect()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockDown()
- local hasBlock, data = turtle.inspectDown()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockUp()
- local hasBlock, data = turtle.inspectUp()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function tryForward()
- waitForFuel(1)
- while not turtle.forward() do
- if getBlock() == "minecraft:glass_pane" 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 getBlockDown() == "minecraft:sugar_cane" then
- turtle.digDown()
- end
- return true
- end
- local function repeatForward(amount)
- for i=1, amount do
- fastFail(tryForward())
- end
- end
- local function recenter()
- while getBlockUp() ~= "minecraft:barrel" do
- if not tryForward() then
- turtle.turnLeft()
- end
- end
- while turtle.detect() and getBlock() ~= "minecraft:sugar_cane" do
- turtle.turnLeft()
- end
- end
- local function deposit()
- for i=1, 15 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- waitForDropDown() -- Edit this line to when changing deposit direction
- end
- end
- turtle.select(16)
- if not turtle.refuel(0) then
- waitForDropDown() -- Edit this line to when changing deposit direction
- end
- end
- while true do
- recenter()
- deposit()
- for i=1, 20*60 do
- if getBlock() ~= "minecraft:sugar_cane" then
- sleep(1)
- else
- break
- end
- end
- containerRefuel(1024)
- for i=0, 14 do
- if i%3 == 0 then
- fastFail(tryForward())
- turtle.turnRight()
- repeatForward(15)
- turtle.turnLeft()
- elseif i % 3 == 1 then
- fastFail(tryForward())
- else
- fastFail(tryForward())
- turtle.turnLeft()
- repeatForward(15)
- turtle.turnRight()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment