frubi

frubis_stripminer

Jun 21st, 2021 (edited)
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.93 KB | None | 0 0
  1. local parameter = {numOfBranches, lengthOfBranch, skipBranches, numOfFinishedBranches};
  2.  
  3. -- Function declaration
  4. local goBackToEnd;
  5. local skipBranches;
  6. local checkIfInventoryIsFull;
  7. local emptyInventory;
  8. local goBackToStart;
  9. local selectItemInInventory;
  10. local placeItem;
  11. local refuel;
  12. local dig;
  13. local digBranch;
  14. local digBranches;
  15. local setReady;
  16. local main;
  17. local reset;
  18. local pickUpItems;
  19.  
  20. -- Fcuntion implementation
  21. main = function()
  22.    
  23.     if not pcall(function() os.loadAPI("move.lua") end ) then
  24.         print("Move Api could not be loaded!");
  25.         return --Exit programm
  26.     end
  27.     move.init();
  28.    
  29.     if #arg == 1 then
  30.         if arg[1] == -1 then
  31.             --Read file
  32.         end
  33.     end
  34.    
  35.     if #arg == 3 then
  36.        
  37.         lengthOfBranch = arg[1];
  38.         numOfBranches = arg[2];
  39.         skipBranches = arg[3];
  40.        
  41.     else
  42.         print("How long should a branch be? (50)");
  43.         lengthOfBranch = tonumber(io.read()) or 50;
  44.  
  45.         print("How many Branches? (-1 for infinite) (5)");
  46.         numOfBranches = tonumber(io.read()) or 5;
  47.  
  48.         print("Skip Branches? (0)");
  49.         skipBranches = tonumber(io.read()) or 0;  
  50.     end
  51.    
  52.     if move.getY() ~= 0 then
  53.         goBackToStart();
  54.     else  
  55.    
  56.         setReady();
  57.         skipBranches(skipBranches);
  58.         digBranches(lengthOfBranch, numOfBranches);
  59.     end
  60. end
  61.  
  62. goBackToStart = function()
  63.    
  64.     move.turn(2);
  65.     move.forward(math.abs(move.getPosX()));
  66.    
  67.     move.turnToDirection(2);
  68.     move.setPosYOld(move.getPosY());
  69.     move.forward(math.abs(move.getPosY()));
  70.      
  71.     move.down();
  72. end
  73.  
  74. goBackToEnd = function()
  75.  
  76.     move.turnToDirection(0);
  77.        
  78.     if move.getPosZ() == 0 then
  79.         move.Up();
  80.     end
  81.        
  82.     move.forward(move.getPosYOld());
  83.  
  84. end
  85.  
  86. skipBranches = function(amount)
  87.     amount = amount or 0;
  88.     move.forward(amount*3)
  89. end
  90.    
  91. checkIfInventoryIsFull = function()
  92.     for i=1,16 do
  93.         if turtle.getItemCount(i) == 0 then
  94.             return false;
  95.         end
  96.     end
  97.     return true
  98. end
  99.  
  100. emptyInventory = function()
  101.     for i=1, 16 do
  102.         local data = turtle.getItemDetail(i);
  103.         if data and data.name ~= "minecraft:torch" and data.name ~="minecraft:coal" then
  104.             turtle.select(i);
  105.             turtle.drop();
  106.         end
  107.     end
  108.     if checkIfInventoryIsFull() then
  109.         os.reboot();
  110.     end
  111. end
  112.  
  113. selectItemInInventory = function(itemName)
  114.     for i=1,16 do
  115.         local data = turtle.getItemDetail(i);
  116.         if data ~= nil then
  117.             if data.name == itemName then
  118.                 turtle.select(i);
  119.                 return;
  120.             end
  121.         end
  122.     end
  123.     return -1;
  124. end
  125.  
  126. placeItem = function(itemName)
  127.     if selectItemInInventory(itemName) ~= -1 then
  128.         turtle.placeUp();
  129.     end
  130. end
  131.  
  132. refuel = function(amount)
  133.     for i=1, 16 do
  134.         if turtle.getFuelLevel() > amount then
  135.             break;
  136.         else
  137.             if selectItemInInventory("minecraft:coal") == -1 then
  138.                reset();
  139.             end
  140.             turtle.refuel();
  141.         end
  142.     end
  143.     if turtle.getFuelLevel() < amount then
  144.         reset();
  145.     end
  146. end
  147.  
  148. dig = function(length)
  149.     for i=1, length do
  150.         turtle.dig();
  151.         move.forward(1);
  152.        
  153.         turtle.digDown();
  154.        
  155.         local success, data = turtle.inspectUp()
  156.         if success and data.name ~= "minecraft:wall_torch" then
  157.             turtle.digUp();
  158.         end
  159.      end
  160. end  
  161.  
  162. digBranch = function(length)
  163.     dig(length);
  164.     placeItem("minecraft:torch");
  165.     move.turn(2)
  166.    
  167.     local steps_10 = math.floor(length/10); -- Zehner Schritte
  168.     local steps = math.fmod(length, 10); -- Einer Schritte
  169.    
  170.     for i=1, steps_10 do
  171.         move.forward(10);
  172.         placeItem("minecraft:torch");
  173.     end
  174.    
  175.     move.forward(steps);
  176.  
  177.     refuel(length*2);
  178. end
  179.  
  180. digBranches = function(length, amount)
  181.     if amount == -1 then
  182.         amount = 1e309;
  183.     end
  184.        
  185.     for i=1, amount do
  186.        
  187.         move.turnToDirection(0);
  188.         dig(3);
  189.        
  190.         move.turnToDirection(1);
  191.         digBranch(length);
  192.         if checkIfInventoryIsFull() then
  193.             goBackToStart();
  194.             emptyInventory();
  195.             goBackToEnd();
  196.             move.turnToDirection(1);
  197.             pickUpItems(length);
  198.         end
  199.        
  200.         move.turnToDirection(3);
  201.         digBranch(length);
  202.         if checkIfInventoryIsFull() then
  203.             goBackToStart();
  204.             emptyInventory();
  205.             goBackToEnd();
  206.             move.turnToDirection(3)
  207.             pickUpItems(length);
  208.         end
  209.     end
  210.        
  211.     reset();
  212. end
  213.  
  214. pickUpItems = function(length)
  215.     for i=1, length do
  216.         turtle.suckDown();
  217.         move.forward(1);
  218.     end
  219.     move.turn(2);
  220.     move.forward(length);
  221. end
  222.  
  223. setReady = function()
  224.     if move.getPosYOld() ~= 0 then
  225.       goBackToEnd();
  226.     elseif turtle.detectDown() then
  227.         move.up();
  228.     end
  229. end
  230.    
  231. reset = function()
  232.     goBackToStart();
  233.     emptyInventory();
  234.     turnToDirection(0);
  235.     os.reboot();
  236. end
  237.  
  238. main();
Add Comment
Please, Sign In to add comment