Advertisement
Spytox

Cobble

Jan 20th, 2025 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | Gaming | 0 0
  1. -- Turtle program for farming cobblestone in a cobblestone generator
  2.  
  3. -- Function to check if there's a cobblestone block in front
  4. local function isCobble()
  5.     local success, data = turtle.inspect()
  6.     if success and data.name == "minecraft:cobblestone" then
  7.         return true
  8.     end
  9.     return false
  10. end
  11.  
  12. -- Function to check if there's space in the chest behind
  13. local function hasChestSpace()
  14.     turtle.select(1) -- Ensure a slot is selected
  15.     local detail = turtle.getItemDetail()
  16.     if detail then
  17.         -- Check if the chest can accept this item
  18.         return turtle.dropUp() -- Drop directly into the chest behind
  19.     else
  20.         -- If no items in slot, assume chest has space
  21.         return true
  22.     end
  23. end
  24.  
  25. -- Function to wait until the chest has space
  26. local function waitForChestSpace()
  27.     while not hasChestSpace() do
  28.         print("Waiting for chest space...")
  29.         os.sleep(1)
  30.     end
  31. end
  32.  
  33. -- Main loop
  34. while true do
  35.     if isCobble() then
  36.         -- Mine the cobblestone
  37.         turtle.dig()
  38.  
  39.         -- Check if there's space and deposit cobblestone
  40.         if hasChestSpace() then
  41.             -- Successfully dropped the cobblestone
  42.         else
  43.             -- Wait until the chest has space
  44.             waitForChestSpace()
  45.             turtle.dropUp() -- Deposit once there's space
  46.         end
  47.     end
  48.  
  49.     -- Wait a short time before checking again to avoid overloading the system
  50.     os.sleep(0.5)
  51. end
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement