Advertisement
psychedelixx

Minecraft Turtle: Spiral miner (Robust)

Jan 4th, 2015
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     --[[
  2.     2015 (c) psychedelixx
  3.     Minecraft Turtle: Spiral miner (Robust)
  4.     2015-01-04
  5.  
  6.     Mines in a spiralform (spin me right round baby) and stays on the level it started.
  7.  
  8.     Robust API:
  9.     http://computercraft.info/wiki/Robust_Turtle_API
  10.  
  11.     Usage:
  12.         - use turtle and type "label set <name>"
  13.           (to give your turtle an unique name so it remembers its programs)
  14.         - type "pastebin get 7Ckr8y7s spiral"
  15.         - type "spiral <limit> [<fillGround 0|1 default 0> <factor default 1.5> <useTesseract 0|1 default 0>]"
  16.     - place chests in slot 16
  17.     ]]
  18. torchesAvailable = false
  19. chestsAvailable = false
  20. torchSlot = 15
  21. factor = 1.5
  22. useTesseract = false
  23.  
  24. function move()
  25.     slot = 1
  26.     while not turtle.detectDown() and fillGround == 1 do
  27.         turtle.select(slot)
  28.         turtle.placeDown()
  29.        
  30.         if slot < 13 then
  31.             slot = slot+1
  32.         else
  33.             print("no items to fill ground")
  34.             fillGround = 0
  35.             break
  36.         end
  37.     end
  38.  
  39.     t.dig()
  40.     t.forward()
  41.     t.digUp()
  42.    
  43.     empty = 0  
  44.     for slot = 1, 13 do
  45.         if turtle.getItemCount(slot) == 0 then
  46.             empty = 1
  47.             break
  48.         end
  49.     end
  50.  
  51.     --[[ if turtle is full, turn around, place chest, move items into it, turn around and continue ]]--
  52.     if empty == 0 then     
  53.         t.turnAround()
  54.  
  55.         if not chestsAvailable then
  56.             print("Please put chests in slot 15 and press enter to continue")
  57.             read()
  58.         end
  59.        
  60.         turtle.select(14)
  61.         turtle.place()
  62.        
  63.         for slot = 1, 13 do
  64.                 turtle.select(slot)
  65.                 turtle.drop()
  66.         end
  67.        
  68.         if useTesseract then
  69.             os.sleep(0.5)
  70.             turtle.select(14)
  71.             turtle.dig()
  72.         end
  73.  
  74.         if turtle.getItemCount(14) > 0 then
  75.                 chestsAvailable = true
  76.         else
  77.                 chestsAvailable = false
  78.         end
  79.        
  80.         t.turnAround()
  81.     end
  82. end
  83.  
  84. local args = { ... }
  85. if #args < 1 then
  86.     print("")
  87.     print("spiral <limit> [<fillGround 0|1 default 0> <factor default 1.5> <useTesseract 0|1 default 0]")
  88.     print("place chests/tesseract in slot 14")
  89.     print("place torches in slots 15 and 16")
  90.  
  91.     error()
  92. end
  93.  
  94. if #args >= 1 then
  95.     limit  = tonumber(args[1])
  96.     fillGround = 0
  97. end
  98. if #args >= 2 then
  99.     fillGround = tonumber(args[2])
  100. end
  101. if #args >= 3 then
  102.     factor= tonumber(args[3])
  103. end
  104. if #args >= 4 then
  105.     if tonumber(args[4]) > 0 then
  106.         useTesseract = true
  107.     else
  108.         useTesseract = false
  109.     end
  110. end
  111.  
  112. if turtle.getFuelLevel() < 0.75*limit*limit + limit then
  113.     print("I need " .. (0.75*limit*limit + limit) - turtle.getFuelLevel() .. " more fuel!")
  114. else
  115.     print("======== 2015 (c) psychedelixx ========")
  116.     print("Let's go!")
  117.     print("Mining a spiral...")
  118.  
  119.     if turtle.getItemCount(15)+turtle.getItemCount(16) > 0 then
  120.         torchesAvailable = true
  121.     else
  122.         print("")
  123.         print("Warning: no torches found in slot 15 and 16. Press enter to continue")
  124.         read()
  125.         torchesAvailable = false
  126.     end
  127.  
  128.     if turtle.getItemCount(14) > 0 then
  129.         chestsAvailable = true
  130.     else
  131.         print("")
  132.         print("Warning: no chests found in slot 14. Press enter to continue")
  133.         read()
  134.         chestsAvailable = false
  135.     end
  136.  
  137.     if turtle.getItemCount(15) > 0 then
  138.         torchesAvailable = true
  139.         torchSlot = 15
  140.     elseif turtle.getItemCount(16) > 0 then
  141.         torchesAvailable = true
  142.         torchSlot = 16
  143.     else    
  144.         torchesAvailable = false
  145.     end
  146.  
  147.     if turtle.getItemCount(14) > 0 then
  148.         chestsAvailable = true
  149.     else
  150.         chestsAvailable = false
  151.     end
  152.    
  153.     x = 0
  154.  
  155.     repeat
  156.         x = x + 1
  157.         y = math.ceil(x*factor)
  158.  
  159.         for i = 1, y do
  160.             move()
  161.             if i%7 == 0 and y-i > 5 and torchesAvailable and turtle.detectDown() then  
  162.                 t.turnAround()
  163.                 turtle.select(torchSlot)
  164.  
  165.                 turtle.place() 
  166.                 t.turnAround()
  167.                
  168.                 if torchSlot == 15 and turtle.getItemCount(torchSlot) == 0 then
  169.                     torchSlot = 16
  170.                 elseif torchSlot == 16 and turtle.getItemCount(torchSlot) == 0 then
  171.                     torchSlot = 15
  172.                 end
  173.  
  174.                 if turtle.getItemCount(15) + turtle.getItemCount(16) > 0 then
  175.                     torchesAvailable = true
  176.                 else
  177.                     torchesAvailable = false
  178.                 end
  179.             end
  180.         end
  181.        
  182.         if torchesAvailable then
  183.             t.dig()
  184.             turtle.select(torchSlot)
  185.             turtle.place()
  186.         end
  187.  
  188.         t.right()
  189.  
  190.         print (y .. " / " .. limit .. "... fuel: " .. turtle.getFuelLevel())
  191.     until y >= limit
  192.     print("Done")
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement