Guest User

Minecraft Modded - Mining Turtle - Refuel Max From Storage

a guest
Mar 12th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | Gaming | 0 0
  1. local TARGET_FUEL = 1000000  -- Stop refueling when this fuel level is reached
  2. local MAX_SLOTS = 16         -- Turtle has 16 inventory slots
  3. local drawerDirection = nil  -- Stores the found drawer position
  4.  
  5. -- Function to find a storage drawer and store its position
  6. local function findDrawer()
  7.     local directions = {
  8.         {action = "suck", move = function() return turtle.suck() end, turn = nil},
  9.         {action = "suckUp", move = function() return turtle.suckUp() end, turn = nil},
  10.         {action = "suckDown", move = function() return turtle.suckDown() end, turn = nil},
  11.         {action = "suck", move = function() return turtle.suck() end, turn = turtle.turnLeft},
  12.         {action = "suck", move = function() return turtle.suck() end, turn = turtle.turnRight},
  13.         {action = "suck", move = function() return turtle.suck() end, turn = function() turtle.turnLeft(); turtle.turnLeft() end}
  14.     }
  15.  
  16.     for _, dir in ipairs(directions) do
  17.         if dir.turn then dir.turn() end  -- Turn if needed
  18.  
  19.         if dir.move() then
  20.             drawerDirection = dir  -- Store the found direction
  21.             print("Storage drawer found! Using " .. dir.action .. " to pull fuel.")
  22.             return true
  23.         end
  24.     end
  25.  
  26.     return false  -- No drawer found
  27. end
  28.  
  29. -- Function to pull fuel into all slots before refueling
  30. local function pullFuel()
  31.     if not drawerDirection then
  32.         print("No storage drawer remembered!")
  33.         return false
  34.     end
  35.  
  36.     print("Filling inventory with fuel...")
  37.     local pulled = false  -- Track if any fuel was pulled
  38.     for slot = 1, MAX_SLOTS do
  39.         turtle.select(slot)
  40.         if drawerDirection.move() then
  41.             pulled = true  -- Fuel was pulled
  42.         end
  43.     end
  44.  
  45.     return pulled
  46. end
  47.  
  48. -- Function to refuel all fuel in inventory
  49. local function refuelTurtle()
  50.     print("Refueling...")
  51.     for slot = 1, MAX_SLOTS do
  52.         turtle.select(slot)
  53.         if turtle.refuel() then
  54.             print("Refueled from slot " .. slot .. ". Current fuel level: " .. turtle.getFuelLevel())
  55.         end
  56.     end
  57. end
  58.  
  59. -- **Stage 1: Locate and Remember Drawer (Only Runs Once)**
  60. if not findDrawer() then
  61.     print("No storage drawer found! Exiting...")
  62.     return
  63. end
  64.  
  65. -- **Main Loop: Repeat Stages 2-4**
  66. while true do
  67.     -- **Stage 2: Fill inventory with fuel**
  68.     local hasFuel = pullFuel()
  69.    
  70.     if not hasFuel then
  71.         print("No more fuel available! Exiting...")
  72.         return
  73.     end
  74.  
  75.     -- **Stage 3: Refuel using all slots**
  76.     refuelTurtle()
  77.  
  78.     -- **Stage 4: Check if fuel is over 1,000,000**
  79.     if turtle.getFuelLevel() >= TARGET_FUEL then
  80.         break
  81.     end
  82. end
  83.  
  84. -- Final refuel to use up all remaining fuel
  85. refuelTurtle()
  86.  
  87. print("Refueling complete! Final fuel level:", turtle.getFuelLevel())
Add Comment
Please, Sign In to add comment