dan330

Untitled

May 7th, 2025 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. -- Mining Turtle Program for Gravel/Andesite
  2. -- Version 1.1.1 for CC: Tweaked 1.21.1
  3. -- SemVer: MAJOR.MINOR.PATCH
  4.  
  5. --[[ Changelog:
  6. v1.1.1 - Fixed fuel system to scan all slots for fuel
  7. v1.1.0 - Added proper SemVer version tracking and display
  8. v1.0.0 - Initial release with basic mining functionality
  9. ]]
  10.  
  11. -- Configuration
  12. local VERSION = "1.1.1"
  13. local START_POS = vector.new(-279, 64, -182)
  14. local MAX_Y = 70
  15. local MIN_FUEL = 100
  16. local PREFERRED_FUEL_SLOT = 16 -- Preferred slot for fuel, but will search all slots
  17.  
  18. -- Block types to mine
  19. local TARGET_BLOCKS = {
  20.     ["minecraft:gravel"] = true,
  21.     ["minecraft:andesite"] = true,
  22.     ["minecraft:diorite"] = true,
  23.     ["minecraft:granite"] = true
  24. }
  25.  
  26. -- Turtle state
  27. local pos = vector.new(START_POS.x, START_POS.y, START_POS.z)
  28. local facing = "north" -- Initial facing direction
  29. local visited = {} -- Track visited positions to prevent infinite loops
  30.  
  31. -- Direction vectors
  32. local directions = {
  33.     north = vector.new(0, 0, -1),
  34.     east = vector.new(1, 0, 0),
  35.     south = vector.new(0, 0, 1),
  36.     west = vector.new(-1, 0, 0)
  37. }
  38.  
  39. -- Helper functions
  40. local function log(message)
  41.     print(os.date("[%H:%M:%S] ") .. message)
  42. end
  43.  
  44. local function printVersion()
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.     print("==== Mining Turtle Program ====")
  48.     print("Version: " .. VERSION)
  49.     print("CC: Tweaked 1.21.1")
  50.     print("==============================")
  51.     print()
  52. end
  53.  
  54. local function findFuel()
  55.     -- First try preferred slot
  56.     turtle.select(PREFERRED_FUEL_SLOT)
  57.     if turtle.refuel(0) then -- Test if item is fuel
  58.         return PREFERRED_FUEL_SLOT
  59.     end
  60.    
  61.     -- Search all slots for fuel
  62.     for slot = 1, 16 do
  63.         if slot ~= PREFERRED_FUEL_SLOT then -- Skip already checked preferred slot
  64.             turtle.select(slot)
  65.             if turtle.refuel(0) then
  66.                 return slot
  67.             end
  68.         end
  69.     end
  70.    
  71.     return nil -- No fuel found
  72. end
  73.  
  74. local function checkFuel()
  75.     if turtle.getFuelLevel() >= MIN_FUEL then
  76.         return true
  77.     end
  78.    
  79.     log("Low fuel! Searching for fuel...")
  80.     local fuelSlot = findFuel()
  81.    
  82.     if fuelSlot then
  83.         turtle.select(fuelSlot)
  84.         local before = turtle.getFuelLevel()
  85.         if turtle.refuel(1) then
  86.             local gained = turtle.getFuelLevel() - before
  87.             log(("Refueled with slot %d (+%d fuel). Total: %d"):format(fuelSlot, gained, turtle.getFuelLevel()))
  88.             return true
  89.         end
  90.     end
  91.    
  92.     log("No fuel found in any slot!")
  93.     return false
  94. end
  95.  
  96. -- ... [rest of the functions remain the same as in v1.1.0] ...
  97.  
  98. -- Main program
  99. printVersion()
  100. log("Starting mining turtle at position " .. pos.x .. " " .. pos.y .. " " .. pos.z)
  101. log("Target blocks: gravel, andesite, diorite, granite")
  102. log("Max Y level: " .. MAX_Y)
  103.  
  104. -- Initial fuel check
  105. if not checkFuel() then
  106.     log("Initial fuel level too low and no fuel found!")
  107.     log("Please add fuel (coal, lava buckets, etc.) to any slot")
  108.     return
  109. end
  110.  
  111. -- Start mining
  112. explore()
  113.  
  114. log("Mining operation complete!")
  115. log("Final position: " .. pos.x .. " " .. pos.y .. " " .. pos.z)
  116. log("Remaining fuel: " .. turtle.getFuelLevel())
Add Comment
Please, Sign In to add comment