Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TARGET_FUEL = 1000000 -- Stop refueling when this fuel level is reached
- local MAX_SLOTS = 16 -- Turtle has 16 inventory slots
- local drawerDirection = nil -- Stores the found drawer position
- -- Function to find a storage drawer and store its position
- local function findDrawer()
- local directions = {
- {action = "suck", move = function() return turtle.suck() end, turn = nil},
- {action = "suckUp", move = function() return turtle.suckUp() end, turn = nil},
- {action = "suckDown", move = function() return turtle.suckDown() end, turn = nil},
- {action = "suck", move = function() return turtle.suck() end, turn = turtle.turnLeft},
- {action = "suck", move = function() return turtle.suck() end, turn = turtle.turnRight},
- {action = "suck", move = function() return turtle.suck() end, turn = function() turtle.turnLeft(); turtle.turnLeft() end}
- }
- for _, dir in ipairs(directions) do
- if dir.turn then dir.turn() end -- Turn if needed
- if dir.move() then
- drawerDirection = dir -- Store the found direction
- print("Storage drawer found! Using " .. dir.action .. " to pull fuel.")
- return true
- end
- end
- return false -- No drawer found
- end
- -- Function to pull fuel into all slots before refueling
- local function pullFuel()
- if not drawerDirection then
- print("No storage drawer remembered!")
- return false
- end
- print("Filling inventory with fuel...")
- local pulled = false -- Track if any fuel was pulled
- for slot = 1, MAX_SLOTS do
- turtle.select(slot)
- if drawerDirection.move() then
- pulled = true -- Fuel was pulled
- end
- end
- return pulled
- end
- -- Function to refuel all fuel in inventory
- local function refuelTurtle()
- print("Refueling...")
- for slot = 1, MAX_SLOTS do
- turtle.select(slot)
- if turtle.refuel() then
- print("Refueled from slot " .. slot .. ". Current fuel level: " .. turtle.getFuelLevel())
- end
- end
- end
- -- **Stage 1: Locate and Remember Drawer (Only Runs Once)**
- if not findDrawer() then
- print("No storage drawer found! Exiting...")
- return
- end
- -- **Main Loop: Repeat Stages 2-4**
- while true do
- -- **Stage 2: Fill inventory with fuel**
- local hasFuel = pullFuel()
- if not hasFuel then
- print("No more fuel available! Exiting...")
- return
- end
- -- **Stage 3: Refuel using all slots**
- refuelTurtle()
- -- **Stage 4: Check if fuel is over 1,000,000**
- if turtle.getFuelLevel() >= TARGET_FUEL then
- break
- end
- end
- -- Final refuel to use up all remaining fuel
- refuelTurtle()
- print("Refueling complete! Final fuel level:", turtle.getFuelLevel())
Add Comment
Please, Sign In to add comment