Advertisement
MatthewJ217

Faster Excavate (v1)

Nov 5th, 2023
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. -- fast_excavate v1
  2.  
  3. if not turtle then
  4.     print("This program requires a turtle")
  5.     exit()
  6. end
  7.  
  8. local tArgs = { ... }
  9. local expect = require "cc.expect"
  10. print(tArgs[1]);
  11. expect(1, tonumber(tArgs[1]), "number");
  12. expect(2, tonumber(tArgs[2]), "number", "nil");
  13. expect(3, tonumber(tArgs[3]), "number", "nil");
  14. local self = require "self"
  15.  
  16. local depth = 0;
  17. local x = tonumber(tArgs[1])
  18. local y = tonumber(tArgs[2]) or tonumber(tArgs[1])
  19. local maxDepth = tonumber(tArgs[3]) or 1000000
  20. local facing = false;
  21.  
  22. local function unload()
  23.     local bookmark = self.getPosition();
  24.     self.goToPosition(0, 0, 0, 2);
  25.     for i=1,16 do
  26.         self.select(i);
  27.         self.drop(64);
  28.     end
  29.     self.select(1);
  30.     self.goToPosition(bookmark);
  31. end
  32.  
  33. local function endProgram()
  34.     self.goToPosition(0, 0, 0, 0);
  35.     print("Finished!");
  36. end
  37.  
  38. local function refuel()
  39.     self.refuel()
  40. end
  41.  
  42. local function miningCycle()
  43.         if not self.forward() then endProgram() end
  44.         if self.getItemCount(15) > 0 then self.back() unload() self.forward() end
  45.         self.digUp();
  46.         if self.getItemCount(15) > 0 then unload() end
  47.         self.digDown();
  48.         if self.getItemCount(15) > 0 then unload() end
  49. end
  50.  
  51. local function main()
  52.     self.forced = true;
  53.     local cont = false;
  54.    
  55.     local p = self.getPosition();
  56.     p.y = p.y-1; -- Start only one tile below the chest
  57.     -- Repeat while it can move down
  58.     while self.goToPosition(p) do
  59.         -- Make sure to grab the block dircetly under it when it moves down
  60.         self.digDown()
  61.         if self.getItemCount(15) > 0 then unload() end
  62.         for width=1,x do
  63.             if cont then
  64.                 if facing then
  65.                     self.turnLeft()
  66.                     miningCycle()
  67.                     self.turnLeft()
  68.                 else
  69.                     self.turnRight()
  70.                         miningCycle()
  71.                     self.turnRight()
  72.                 end
  73.                 facing = not facing
  74.             end
  75.             cont = true;
  76.             for depth=2,y do
  77.                 miningCycle()
  78.             end
  79.         end
  80. --      self.turnLeft()
  81. --      self.turnLeft()
  82.         p = self.getPosition();
  83.         p.y = p.y-3;
  84.         p.h = (p.h+2)%4;
  85. --      if x%2 == 1 then facing = not facing end
  86. --      facing = not facing
  87.         cont = false;
  88.     end
  89.     endProgram()
  90. end
  91.  
  92. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement