Daniel_Kerman

DKTAPI

Aug 14th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | None | 0 0
  1. -- -- -- -- -- -- -- -- -- --
  2. --   Project:  DKTAPI      --
  3. --  Author: Daniel_Kerman  --
  4. -- Language: Lua / English --
  5. -- -- -- -- -- -- -- -- -- --
  6.  
  7.     -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  8.     --  BASIC DECLARATION AND INITIALIZATION  --
  9.     -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  10.    
  11.     oldturtle = turtle;
  12.    
  13.     counter = {blocksMined=0,counter=0};
  14.    
  15.     -- -- -- -- -- --
  16.     -- OWN TABLES  --
  17.     -- -- -- -- -- --
  18.    
  19.     gravityBlocks =
  20.     {
  21.     sand="minecraft:sand",
  22.     gravel="minecraft:gravel",
  23.     anvil="minecraft:anvil",
  24.     dragon_egg="minecraft:dragon_egg"
  25.     }
  26.    
  27.     -- -- -- -- -- -- -- --
  28.     --  BASIC FUNCTIONS  --
  29.     -- -- -- -- -- -- -- --
  30.    
  31.     function forwardBool()
  32.         local success = oldturtle.forward()
  33.         if success == false then
  34.             return forwardBool()
  35.         end
  36.     end
  37.    
  38.     function backBool()
  39.         local success = oldturtle.back()
  40.         if success == false then
  41.             return backBool()
  42.         end
  43.     end
  44.    
  45.     function upBool()
  46.         local success = oldturtle.up()
  47.         if success == false then
  48.             return upBool()
  49.         end
  50.     end
  51.    
  52.     function downBool()
  53.         local success = oldturtle.down()
  54.         if success == false then
  55.             return downBool()
  56.         end
  57.     end
  58.    
  59.     function gravityBlock()
  60.         local success, data = turtle.inspect()
  61.         if data.name==gravityBlocks.sand or data.name==gravityBlocks.gravel or data.name==gravityBlocks.anvil or data.name==gravityBlocks.dragon_egg then
  62.             return true
  63.         else
  64.             return false
  65.         end
  66.     end
  67.    
  68.     -- -- -- -- -- -- -- -- -- -- --
  69.     -- TURTLE FUNCTION OVERHAUL   --
  70.     -- -- -- -- -- -- -- -- -- -- --
  71.    
  72.     function forward(n)
  73.         local times = n or 1
  74.         for i=0, times do
  75.             forwardBool()
  76.         end
  77.     end
  78.    
  79.     function back(n)
  80.         local times = n or 1
  81.         for i=0, times do
  82.             backBool()
  83.         end
  84.     end
  85.    
  86.     function up(n)
  87.         local times = n or 1
  88.         for i=0, times do
  89.             upBool()
  90.         end
  91.     end
  92.    
  93.     function down(n)
  94.         local times = n or 1
  95.         for i=0, times do
  96.             downBool()
  97.         end
  98.     end
  99.    
  100.     function turn(str,n)
  101.         local direction = str or "right"
  102.         local times = n or 1
  103.         if direction == "left" then
  104.             for i=0, times do
  105.              oldturtle.turnLeft()
  106.             end
  107.         else
  108.             for i=0, times do
  109.              oldturtle.turnRight()
  110.             end
  111.         end
  112.     end
  113.    
  114.     function turnLeft(n)
  115.         local times = n or 1
  116.         for i=0, times do
  117.          oldturtle.turnLeft()
  118.         end
  119.     end
  120.    
  121.     function turnRight(n)
  122.         local times = n or 1
  123.         for i=0, times do
  124.          oldturtle.turnRight()
  125.         end
  126.     end
  127.    
  128.     function setSlot(n)
  129.         local slot = n or 1
  130.         oldturtle.select(slot)
  131.     end
  132.    
  133.     function mainAttack(n)
  134.         local times = n or 1
  135.         for i=0, times do
  136.          oldturtle.attack()
  137.          oldturtle.attackUp()
  138.          oldturtle.attackDown()
  139.         end
  140.     end
  141.    
  142.     function dig(n)
  143.         local times = n or 1
  144.         for i=0,times do
  145.         if gravityBlock()==false then
  146.          oldturtle.dig()
  147.          addBlocksMined()
  148.          forward()
  149.         else
  150.          oldturtle.dig()
  151.          addBlocksMined()
  152.          sleep(0.4)
  153.          forward()
  154.         end
  155.         end
  156.     end
  157.  
  158.     function digDown(n)
  159.         local times = n or 1
  160.         for i=0,times do
  161.          oldturtle.digDown()
  162.          addBlocksMined()
  163.          down()
  164.         end
  165.     end
  166.  
  167.     function digUp(n)
  168.         local times = n or 1
  169.         for i=0,times do
  170.         if gravityBlock==false then
  171.          oldturtle.digUp()
  172.          addBlocksMined()
  173.          up()
  174.         else
  175.          oldturtle.digUp()
  176.          addBlocksMined()
  177.          sleep(1)
  178.          up()
  179.         end
  180.         end
  181.     end
  182.  
  183.     function quarry(n1,n2,n3)
  184.         local quarryWidth = n1 or 1
  185.         local quarryHeight = n2 or 2
  186.         local times = n3 or 1
  187.         for i=0, times do
  188.          dig()
  189.          digDown(quarryHeight-1)
  190.          turn()
  191.          up(quarryHeight)
  192.         for i=0, quarryWidth-1 do
  193.          dig()
  194.          digDown(quarryHeight-1)
  195.          up(quarryHeight-1)
  196.         end
  197.         end
  198.     end
  199.    
  200.     -- -- -- -- -- -- -- --
  201.     -- Setter & Getter   --
  202.     -- -- -- -- -- -- -- --
  203.        
  204.         -- Specific Counter --
  205.        
  206.         function resetCounter(str)
  207.             local str = str or counter
  208.             counter.str = 0
  209.         end
  210.        
  211.         -- BlocksMined --
  212.        
  213.         function resetBlocksMined()
  214.             counter.blocksMined = 0
  215.         end
  216.        
  217.         function setBlocksMined(n)
  218.             local value = n or 0
  219.             counter.blocksMined = value
  220.         end
  221.        
  222.         function getBlocksMined()
  223.             return counter.blocksMined
  224.         end
  225.        
  226.         function addBlocksMined(n) -- Works as subtractBlocksMined with negative Numbers
  227.             local value = n or 1
  228.             counter.blocksMined = counter.blocksMined + value
  229.         end
  230.        
  231.         function subtractBlocksMined(n) -- Works as subtractBlocksMined with negative Numbers
  232.             local value = n or 1
  233.             counter.blocksMined = counter.blocksMined - value
  234.         end
  235.        
  236.         -- ExCounter --
  237.        
  238.         function resetExCounter()
  239.             counter.counter = 0
  240.         end
  241.        
  242.         function setExCounter(n)
  243.             local value = n or 0
  244.             counter.counter = value
  245.         end
  246.        
  247.         function getExCounter()
  248.             return counter.counter
  249.         end
  250.        
  251.         function addExCounter(n)
  252.             local value = n or 1
  253.             counter.counter = counter.counter + value
  254.         end
  255.        
  256.         function subtractExCounter(n)
  257.             local value = n or 1
  258.             counter.counter = counter.counter - value
  259.         end
Advertisement
Add Comment
Please, Sign In to add comment