kreezxil

turtle cobblegen miner for computercraft

Sep 22nd, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | Gaming | 0 0
  1. -- MineCobbleStationary.lua
  2. -- This script makes a stationary Turtle mine cobblestone from a cobble generator
  3. -- until its inventory is full, then pause and wait until the inventory is emptied.
  4.  
  5. -- Function to check if the Turtle's inventory is full
  6. local function isInventoryFull()
  7.     for slot = 1, 16 do
  8.         local itemCount = turtle.getItemCount(slot)
  9.         if itemCount == 0 then
  10.             -- Empty slot found
  11.             return false
  12.         else
  13.             -- Get item details to ensure it's cobblestone
  14.             local itemDetail = turtle.getItemDetail(slot)
  15.             if itemDetail and itemDetail.name == "minecraft:cobblestone" and itemCount < 64 then
  16.                 -- Slot has cobblestone but isn't full
  17.                 return false
  18.             end
  19.         end
  20.     end
  21.     -- All slots are either full with cobblestone or contain other items
  22.     return true
  23. end
  24.  
  25. -- Function to wait until the inventory has space
  26. local function waitForInventorySpace()
  27.     print("Inventory full. Please empty the inventory. Waiting...")
  28.     while isInventoryFull() do
  29.         os.sleep(10) -- Wait for 10 seconds before checking again
  30.     end
  31.     print("Inventory has space. Resuming mining.")
  32. end
  33.  
  34. -- Function to ensure the Turtle can dig forward, handling any obstacles
  35. local function ensureDigForward()
  36.     while not turtle.dig() do
  37.         print("Failed to dig. Retrying in 1 second...")
  38.         os.sleep(1) -- Wait for 1 second before trying again
  39.     end
  40. end
  41.  
  42. -- Function to collect items after digging
  43. local function collectItems()
  44.     while turtle.suck() do
  45.         -- Keep sucking until no more items can be collected
  46.     end
  47. end
  48.  
  49. -- Main mining loop
  50. local function mineCobble()
  51.     print("Starting mining operation...")
  52.     while true do
  53.         if isInventoryFull() then
  54.             waitForInventorySpace()
  55.         end
  56.  
  57.         -- Attempt to dig forward
  58.         ensureDigForward()
  59.  
  60.         -- Collect the mined cobblestone
  61.         collectItems()
  62.  
  63.         -- Optional: Wait a short duration to prevent overwhelming the generator
  64.         os.sleep(0.5) -- Wait half a second before the next dig
  65.     end
  66. end
  67.  
  68. -- Start the mining operation
  69. mineCobble()
  70.  
Add Comment
Please, Sign In to add comment