Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Requires Specific Building Setup to understand how to organize
- --TODO: write script to have the butler build the depot that it wants to live in (to avoid human error)
- --Import Relative Location Libraries
- local tTurtle = require("TrackingTurtle")
- local myTurtle = tTurtle.create()
- local function checkJunkChest()
- myTurtle.turnLeft()
- for _ = 1, 3 do
- myTurtle.up()
- end
- for _ = 1, 6 do
- myTurtle.forward()
- end
- myTurtle.turnRight()
- for _ = 1, 2 do
- myTurtle.forward()
- end
- myTurtle.turnLeft()
- for _ = 1, 2 do
- myTurtle.forward()
- end
- myTurtle.turnRight()
- for _ = 1, 2 do
- myTurtle.drop()
- end
- end
- local function fillInventory()
- -- Check if the turtle is adjacent to a chest
- if not turtle.detect() then
- print("No chest detected.")
- return
- end
- -- Pull items from the chest until the inventory is full
- for slot = 1, 16 do
- if turtle.getItemCount(slot) == 0 then
- -- Select the current slot to store items from the chest
- turtle.select(slot)
- -- Attempt to pull items from the chest
- if turtle.suck() then
- print("Pulled items from the chest.")
- else
- -- If no items are left in the chest, stop pulling
- print("No more items in the chest.")
- break
- end
- end
- end
- end
- local function refuel()
- print("refueling")
- local function attemptRefuel(slot)
- turtle.select(slot)
- if turtle.refuel(0) then
- local initialFuelLevel = turtle.getFuelLevel()
- turtle.refuel()
- local fuelIncrease = turtle.getFuelLevel() - initialFuelLevel
- return fuelIncrease
- end
- return 0
- end
- local function burnCoalUntilFull()
- while turtle.getFuelLevel() < turtle.getFuelLimit() do
- local initialFuelLevel = turtle.getFuelLevel()
- if turtle.getItemCount(1) > 0 and turtle.getItemDetail(1).name == "minecraft:coal" then
- turtle.select(1)
- turtle.refuel()
- else
- break
- end
- if turtle.getFuelLevel() == initialFuelLevel then
- break
- end
- end
- end
- -- Attempt to consume items in inventory for refueling
- for slot = 1, 16 do
- local fuelIncrease = attemptRefuel(slot)
- if fuelIncrease > 0 then
- if fuelIncrease < 80 then -- Arbitrary threshold, assuming coal is 80 fuel
- turtle.refuel(math.floor(fuelIncrease / 80)) -- Refuel with coal until it matches consumed item
- end
- return true
- end
- end
- -- Burn coal until fuel is full
- burnCoalUntilFull()
- return turtle.getFuelLevel() == turtle.getFuelLimit() -- Return whether the turtle's fuel is full
- end
- refuel()
- checkJunkChest()
- fillInventory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement