Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuelThreshold = turtle.getFuelLimit() / 2
- local function fastFail(success)
- if not success then
- print("An unexpected error has occured! Aborting.")
- exit()
- 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 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 getItemName(slot)
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail then
- return itemDetail.name
- else
- return "minecraft:air"
- end
- end
- local function refuel(amount)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- if turtle.getFuelLevel() >= amount then
- return true
- elseif getItemName(1) == "minecraft:lava_bucket" then
- turtle.select(1)
- if not turtle.refuel(1) then
- return false
- end
- elseif getBlockUp() == "minecraft:lava_cauldron" then
- turtle.select(1)
- turtle.placeUp()
- 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)
- refuel(fuelThreshold)
- while turtle.getFuelLevel() < amount do
- sleep(1)
- refuel(fuelThreshold)
- end
- end
- local function tryForward()
- waitForFuel(1)
- local success = turtle.forward()
- if getBlockDown() == "minecraft:obsidian" then
- turtle.digDown()
- end
- if not turtle.detectDown() then
- if getItemName(1) == "minecraft:lava_bucket" then
- refuel(fuelThreshold)
- if getItemName(1) == "minecraft:lava_bucket" then
- turtle.select(1)
- turtle.placeDown()
- if not turtle.detectDown() then
- sleep(0.5)
- end
- turtle.digDown()
- end
- end
- if getBlockUp() == "minecraft:lava_cauldron" and getItemName(1) == "minecraft:bucket" then
- turtle.select(1)
- turtle.placeUp()
- refuel(fuelThreshold)
- if getItemName(1) == "minecraft:lava_bucket" then
- turtle.select(1)
- turtle.placeDown()
- if not turtle.detectDown() then
- sleep(0.5)
- end
- turtle.digDown()
- end
- end
- elseif getBlockUp() == "minecraft:lava_cauldron" and getItemName(1) == "minecraft:bucket" then
- turtle.select(1)
- turtle.placeUp()
- end
- return success
- end
- local function repeatForward(amount)
- for i=1, amount do
- fastFail(tryForward())
- end
- end
- local function recenter()
- while getBlockDown() ~= "minecraft:barrel" do
- waitForFuel(1)
- if not turtle.forward() then
- turtle.turnLeft()
- end
- end
- while turtle.detect() do
- turtle.turnLeft()
- end
- end
- local function deposit()
- for i=2, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- waitForDropDown() -- Edit this line to when changing deposit direction
- end
- end
- end
- while true do
- recenter()
- deposit()
- for i=1, 10*60 do
- if getBlockUp() ~= "minecraft:lava_cauldron" then
- sleep(1)
- else
- break
- end
- end
- waitForFuel(1024)
- for i=0, 7 do
- if i == 0 then
- fastFail(tryForward())
- else
- fastFail(tryForward())
- turtle.turnRight()
- end
- repeatForward(14)
- turtle.turnLeft()
- fastFail(tryForward())
- turtle.turnLeft()
- repeatForward(14)
- if i ~= 7 then
- turtle.turnRight()
- end
- end
- fastFail(tryForward())
- turtle.turnLeft()
- repeatForward(15)
- end
Advertisement
Add Comment
Please, Sign In to add comment