WineCraftHD

SkyTurtle - Chest Test

Dec 16th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.01 KB | None | 0 0
  1. -- Chests in slot 1, fuel in slot 2
  2. local IgnoreSlots = 2
  3. local fuelIndex = 2
  4.  
  5.  
  6. local DepthIntoGrid = 0
  7. local DepthTarget = 120
  8.  
  9. local mov = {}
  10. local rot = {}
  11. local dig = {}
  12.  
  13. local function Refuel()
  14.         currentFuelRequired = (10 + (DepthTarget-DepthIntoGrid)*2)/20
  15.         if turtle.getFuelLevel() < currentFuelRequired then
  16.                 turtle.select(fuelIndex)
  17.                 return turtle.refuel(currentFuelRequired)
  18.         else
  19.                 return true
  20.         end
  21. end
  22.  
  23. mov.forward = function(times)
  24.         local boolean v = false
  25.         for i=1,times do
  26.                 if turtle.detect() == false then
  27.                         while not turtle.forward() do
  28.                                 Refuel()
  29.                                 sleep(1)
  30.                         end
  31.                         v = true
  32.                 else
  33.                         v = false
  34.                         return v
  35.                 end
  36.         end
  37.         return v
  38. end
  39.  
  40. mov.back = function(times)
  41.         local boolean v = false
  42.         for i=1,times do
  43.                 while not turtle.back() do
  44.                         Refuel()
  45.                         sleep(1)
  46.                 end
  47.                 v = true
  48.         end
  49.         return v
  50. end
  51.  
  52. mov.up = function(times)
  53.     print("In mov.up")
  54.     local boolean v = false
  55.     for i=1,times do
  56.         if turtle.detectUp() == false then
  57.             while turtle.up() == false do
  58.                 Refuel()
  59.                 sleep(1)
  60.             end
  61.             v = true
  62.         else
  63.             v = false
  64.             print("Out mov.up")
  65.             return v
  66.         end
  67.     end
  68.     print("Out mov.up")
  69.     return v
  70. end
  71.  
  72. mov.down = function(times)
  73.     print("In mov.down")
  74.     local boolean v = false
  75.     for i=1,times do
  76.         if turtle.detectDown() == false then
  77.             while turtle.down() == false do
  78.                     Refuel()
  79.                     sleep(1)
  80.             end
  81.             v = true
  82.         else
  83.             print("Out mov.down")
  84.             v = false
  85.             return v
  86.         end
  87.     end
  88.     print("Out mov.down")
  89.     return v
  90. end
  91.  
  92. mov.place = function()
  93.     while not turtle.place() do
  94.           sleep(1)
  95.     end
  96.     return true
  97. end
  98.  
  99. rot.right = function()
  100.     while not turtle.turnRight() do
  101.             sleep(1)
  102.     end
  103.     return true
  104. end
  105.  
  106. rot.left = function()
  107.     while not turtle.turnLeft() do
  108.             sleep(1)
  109.     end
  110.     return true
  111. end
  112.  
  113. dig.forward = function()
  114.     print("In dig.forward")
  115.         if turtle.detect() then
  116.                 while not turtle.dig() do
  117.                                 sleep(1)
  118.                 end
  119.     print("Out dig.forward")
  120.                 return true
  121.         else
  122.                 print("No Block to mine forward")
  123.     print("Out dig.forward")
  124.                 return false
  125.         end
  126. end
  127.  
  128. dig.up = function()
  129.     print("In dig.up")
  130.         if turtle.detectUp() then
  131.                 while not turtle.digUp() do
  132.                                 sleep(1)
  133.                 end
  134.     print("Out dig.up")
  135.                 return true
  136.         else
  137.                 print("No Block to mine up")
  138.     print("Out dig.up")
  139.                 return false
  140.         end
  141. end
  142.  
  143. dig.down = function()
  144.     print("In dig.down")
  145.         if turtle.detectDown() then
  146.                 while not turtle.digDown() do
  147.                                 sleep(1)
  148.                 end
  149.     print("Out dig.down")
  150.                 return true
  151.         else
  152.                 print("No Block to mine down")
  153.     print("Out dig.down")
  154.                 return false
  155.         end
  156. end
  157.  
  158. local function DigMoveForward()
  159.     print("In DigMoveForward")
  160.         if mov.forward(1) == false then
  161.                 dig.forward()
  162.                 sleep(0.5)
  163.                 DigMoveForward()
  164.         end
  165.     print("Out DigMoveForward")
  166. end
  167.  
  168. local function DigMoveUp()
  169.     print("In DigMoveUp")
  170.         while mov.up(1) == false do
  171.                 dig.up()
  172.                 sleep(0.5)
  173.         end
  174.     print("Out DigMoveUp")
  175. end
  176.  
  177. local function DigMoveDown()
  178.     print("In DigMoveDown")
  179.         while mov.down(1) == false do
  180.                 dig.down()
  181.                 sleep(0.5)
  182.         end
  183.     print("Out DigMoveDown")
  184. end
  185.  
  186. local function ReturnBack()
  187.     print("In ReturnBack")
  188.     turtle.select(1)
  189.     while not turtle.compareUp() do
  190.         DigMoveUp()
  191.     end
  192.     print("Out ReturnBack")
  193. end
  194.  
  195. local function CheckRefuel()
  196.     if Refuel() == false then
  197.         print("***Out of fuel***")
  198.         ReturnBack()
  199.         while Refuel() do
  200.                            
  201.         end
  202.         for i=1,DepthIntoGrid do
  203.             DigMoveDown()
  204.         end
  205.     end
  206. end
  207.  
  208. local function DepositChest()
  209.     print("In DepositChest")
  210.     turtle.select(1)
  211.     if not turtle.compareUp() then
  212.         print("ERROR: Should be below chest.")
  213.     print("Out DepositChest")
  214.         return
  215.     end
  216.        
  217.     print("Depositing the Load...")
  218.     for i = IgnoreSlots + 1,16 do
  219.             turtle.select(i)
  220.             turtle.dropUp()
  221.     end
  222.     print("Out DepositChest")
  223. end
  224.  
  225. local function InventoryFull()
  226.     print("In InventoryFull")
  227.     SlotsFull = 0
  228.     for i=1,16 do
  229.             if turtle.getItemCount(i) > 0 then
  230.                     SlotsFull = SlotsFull + 1
  231.             end
  232.     end
  233.    
  234.     if SlotsFull == 16 then
  235.     print("Out InventoryFull")
  236.             return true;
  237.     else
  238.     print("Out InventoryFull")
  239.             return false;
  240.     end
  241. end
  242.  
  243. local function CheckInventory()
  244.     if InventoryFull() then
  245.         print("***Inventory Full***")
  246.         ReturnBack()
  247.         DepositChest()
  248.         for i=1,DepthIntoGrid do
  249.             DigMoveDown()
  250.         end
  251.     end
  252. end
  253.  
  254. local function Harvest()
  255.     while turtle.suck() == true do
  256.         CheckInventory()
  257.     end
  258.    
  259.     dig.forward()
  260. end
  261.  
  262. local function Advance()
  263.     DigMoveDown()
  264.     DepthIntoGrid = DepthIntoGrid + 1
  265.     BlocksTillEnd = DepthTarget - DepthIntoGrid    
  266. end
  267.  
  268. local function Finish()
  269.     print("In Finish")
  270.     ReturnBack()
  271.     DepositChest()
  272.     DigMoveForward()
  273.     DigMoveForward()
  274.     DigMoveForward()
  275.     DigMoveForward()    
  276.     print("Out Finish")
  277. end
  278.  
  279. function StartMining()
  280.     print("In StartMining")
  281.    
  282.     BlocksTillEnd = DepthTarget - DepthIntoGrid
  283.      
  284.     while BlocksTillEnd > 0 do
  285.        
  286.         CheckRefuel()
  287.         CheckInventory()
  288.         Harvest()
  289.        
  290.         for i=1,4 do
  291.             Advance()
  292.         end            
  293.      
  294.         print("Depth: ")
  295.         print(DepthIntoGrid)
  296.     end
  297.    
  298.     Harvest()
  299.     Finish()
  300.    
  301.     print("Out StartMining")
  302. end
  303.  
  304.  
  305. -- MAIN PROGRAM
  306. local FuelCount = turtle.getItemCount(fuelIndex)
  307.  
  308. if FuelCount == 0 then
  309.     print("please put fuel in the last slot of the Turtle.")
  310.     return
  311. else
  312.     if FuelCount < 10 then
  313.         print("Please put at least 10 of the fuel you are using in the Turtle.")
  314.         return
  315.     end
  316. end
  317.  
  318. Refuel()
  319. turtle.select(1)
  320. turtle.placeUp()
  321. StartMining()
Advertisement
Add Comment
Please, Sign In to add comment