Daniel_Kerman

DRTurtleAPI

Aug 20th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.59 KB | None | 0 0
  1. -- API
  2.  
  3. looseBlocks = {"minecraft:gravel","minecraft:sand"};
  4. distance = 0;
  5. blocksMined = 0;
  6.  
  7. function clc(x,y,bc,tc)
  8.     x = x or 1;
  9.     y = y or 1;
  10.     bc = bc or colors.black;
  11.     tc = tc or colors.white;
  12.     term.setCursorPos(x,y);
  13.     term.setBackgroundColor(bc);
  14.     term.setTextColor(tc);
  15.     term.clear();
  16. end
  17.  
  18. function attack()
  19.     local success = true;
  20.     while (success) do
  21.         success = turtle.attack();
  22.     end
  23. end
  24.  
  25. function attackUp()
  26.     local success = true;
  27.     while (success) do
  28.         success = turtle.attackUp();
  29.     end
  30. end
  31.  
  32. function attackDown()
  33.     local success = true;
  34.     while (success) do
  35.         success = turtle.attackDown();
  36.     end
  37. end
  38.  
  39. function dig()
  40.     if turtle.dig() then
  41.         blocksMined = blocksMined + 1;
  42.         return blocksMined;
  43.     end
  44. end
  45.  
  46. function digUp()
  47.     if turtle.digUp() then
  48.         blocksMined = blocksMined + 1;
  49.         return blocksMined;
  50.     end
  51. end
  52.  
  53. function digDown()
  54.     if turtle.digDown() then
  55.         blocksMined = blocksMined + 1;
  56.         return blocksMined;
  57.     end
  58. end
  59.  
  60. function fw()
  61.     local success = false;
  62.     while (success == false) do
  63.         success = turtle.forward();
  64.     end
  65. end
  66.  
  67. function b()
  68.     local success = false;
  69.     while (success == false) do
  70.         success = turtle.back();
  71.     end
  72. end
  73.  
  74. function u()
  75.     local success = false;
  76.     while (success == false) do
  77.         success = turtle.up();
  78.     end
  79. end
  80.  
  81. function d()
  82.     local success = false;
  83.     while (success == false) do
  84.         success = turtle.down();
  85.     end
  86. end
  87.  
  88. function isLoose()
  89.     local found = false;
  90.     for i=1, #looseBlocks do
  91.         local scs, block = turtle.inspect();
  92.         if (block.name == looseBlocks[i]) then
  93.             found = true;
  94.         end
  95.     end
  96.     return found;
  97. end
  98.  
  99. function isLooseUp()
  100.     local found = false;
  101.     for i=1, #looseBlocks do
  102.         local scs, block = turtle.inspectUp();
  103.         if (block.name == looseBlocks[i]) then
  104.             found = true;
  105.         end
  106.     end
  107.     return found;
  108. end
  109.  
  110. function isLooseDown()
  111.     local found = false;
  112.     for i=1, #looseBlocks do
  113.         local scs, block = turtle.inspectDown();
  114.         if (block.name == looseBlocks[i]) then
  115.             found = true;
  116.         end
  117.     end
  118.     return found;
  119. end
  120.  
  121. function fwd(length)
  122.     for i=1, length do
  123.         dig();
  124.         turtle.attack();
  125.         fw(); distance = distance + 1;
  126.     end
  127. end
  128.  
  129. function inventoryFull()
  130.     if (0 < turtle.getItemCount(16)) then
  131.         return true;
  132.     else
  133.         return false;
  134.     end
  135. end
  136.  
  137. function place(lastSlot)
  138.     lastSlot = lastSlot or 16;
  139.     for i=1,lastSlot do
  140.         local count = turtle.getItemCount(i);
  141.         if (0 < count) then turtle.place(); break; end
  142.     end
  143. end
  144.  
  145. function placeUp(lastSlot)
  146.     lastSlot = lastSlot or 16;
  147.     for i=1,lastSlot do
  148.         local count = turtle.getItemCount(i);
  149.         if (0 < count) then turtle.placeUp(); break; end
  150.     end
  151. end
  152.  
  153. function placeDown(lastSlot)
  154.     lastSlot = lastSlot or 16;
  155.     for i=1,lastSlot do
  156.         local count = turtle.getItemCount(i);
  157.         if (0 < count) then turtle.placeDown(); break; end
  158.     end
  159. end
  160.  
  161. function turn(invert)
  162.     invert = invert or false;
  163.     if invert then turtle.turnRight(); turtle.turnRight();
  164.     else turtle.turnLeft(); turtle.turnLeft(); end
  165. end
  166.  
  167. function digA(ignoreUp, ignoreDown)
  168.     ignoreUp = ignoreUp or false;
  169.     ignoreDown = ignoreDown or false;
  170.     dig(); sleep(sleepTime);
  171.     attack();
  172.     while ( isLoose() ) do
  173.         dig();
  174.         sleep(sleepTime);
  175.     end
  176.     fw(); distance = distance + 1;
  177.     if (ignoreUp==false) then
  178.         digUp(); sleep(sleepTime);
  179.         attackUp();
  180.         while ( isLooseUp() ) do
  181.             digUp();
  182.             sleep(sleepTime);
  183.         end
  184.     end
  185.     if (ignoreDown==false) then
  186.         digDown(); sleep(sleepTime);
  187.         attackDown();
  188.         if ( isLooseDown() ) then
  189.             for n=1, 4 do
  190.                 while ( isLoose() ) do
  191.                     dig();
  192.                     sleep(sleepTime);
  193.                 end
  194.                 turtle.turnLeft();
  195.             end
  196.         end
  197.     end
  198.     return inventoryFull();
  199. end
Advertisement
Add Comment
Please, Sign In to add comment