Advertisement
gravitowl

Cobbler 2.0

Dec 14th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. local args = { ... };
  2.  
  3. local function help()
  4.     print("How to use:");
  5.     print("Place the turtle in front of a cobble generator. It will dig 64 cobble, before trying to deposit them downwards.");
  6. end
  7.  
  8. local function getItemCount(item)
  9.     local totalItemCount = 0;
  10.  
  11.     for i=1, 16 do
  12.         local details = turtle.getItemDetail(i);
  13.  
  14.         if details then
  15.             for key, value in pairs(item) do
  16.                 if not details[key] or details[key] ~= value then
  17.                     break;
  18.                 end
  19.             end
  20.  
  21.             totalItemCount = totalItemCount + turtle.getItemCount(i);
  22.         end
  23.     end
  24.  
  25.     return totalItemCount;
  26. end
  27.  
  28. local function mineCobble(amountToMine)
  29.     while getItemCount({ name = "minecraft:cobblestone" }) < amountToMine do
  30.         turtle.dig();
  31.     end
  32. end
  33.  
  34. local function depositCobble()
  35.     while getItemCount({ name = "minecraft:cobblestone" }) > 0 do
  36.         for i=1, 16 do
  37.             turtle.select(i);
  38.             turtle.dropDown();
  39.             if getItemCount({name = "minecraft:cobblestone" }) == 0 then
  40.                 break;
  41.             end
  42.         end
  43.     end
  44.  
  45.     turtle.select(1);
  46. end
  47.  
  48. local function main()
  49.     print("Cobbler V2.0");
  50.  
  51.     if #args > 0 and args[1] == "help" then
  52.         help();
  53.         return;
  54.     end
  55.  
  56.     print("Mining cobble...");
  57.  
  58.     while true do
  59.         mineCobble(64);
  60.         depositCobble();
  61.     end
  62. end
  63.  
  64. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement