Advertisement
gravitowl

cobbler

Dec 10th, 2024 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local function findNeighbouringBlock(blockName)
  2.     for i=1, 4 do
  3.         local hasBlock, block = turtle.inspect();
  4.  
  5.         if block and block.name == blockName then
  6.             return true;
  7.         end
  8.  
  9.         turtle.turnRight();
  10.     end
  11.  
  12.     return false;
  13. end
  14.  
  15. local function getItemCount(itemName)
  16.     local total = 0;
  17.    
  18.     for i=1, 16 do
  19.         local itemDetail = turtle.getItemDetail(i);
  20.  
  21.         if itemDetail and itemDetail.name == itemName then
  22.             total = total + turtle.getItemCount(i);
  23.         end
  24.     end
  25.  
  26.     return total;
  27. end
  28.  
  29. local function mineCobble(amount)
  30.     while getItemCount("minecraft:cobblestone") < amount do
  31.         if turtle.detect() then
  32.             turtle.dig();
  33.         end
  34.     end
  35. end
  36.  
  37. local function depositCobble()
  38.     while getItemCount("minecraft:cobblestone") > 0 do
  39.         for i=1, 16 do
  40.             turtle.drop();
  41.         end
  42.     end
  43. end
  44.  
  45. local function main()
  46.     local foundCobble = findNeighbouringBlock("minecraft:cobblestone");
  47.  
  48.     if not foundCobble then
  49.         print("Couldn't find the cobble gen.");
  50.         return;
  51.     end
  52.  
  53.     local foundChest, _ = findNeighbouringBlock("minecraft:chest");
  54.     if not foundChest then
  55.         print("Couldn't find chest.");
  56.         return;
  57.     end
  58.  
  59.     turtle.turnLeft();
  60.     turtle.turnLeft();
  61.  
  62.     local running = true;
  63.  
  64.     while running do
  65.         mineCobble(64);
  66.         turtle.turnRight();
  67.         turtle.turnRight();
  68.         depositCobble();
  69.         turtle.turnRight();
  70.         turtle.turnRight();
  71.     end
  72. end
  73.  
  74. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement