Advertisement
Virtualham

WIP ComputerCraft Customizeable Turtle BranchMining Program

Jan 5th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.67 KB | None | 0 0
  1. --Get inputs
  2.  
  3. local Inputs = { ... }
  4.  
  5.  
  6. --Check # of inputs
  7.  
  8. if #Inputs < 2 or #Inputs > 7 then
  9.     print("Usage: branch <solo/side> <branchlength> <branchspacing> <torchspacing> <enderchestslot#> <torchesslot#> <#ofShafts>.")
  10.     return true
  11. end
  12.  
  13. --Check input validity
  14.  
  15. if #Inputs == 7 then
  16.     shafts = tonumber(Inputs[7])
  17.     torch = tonumber(Inputs[6])
  18.     chest = tonumber(Inputs[5])
  19.     light = tonumber(Inputs[4])
  20.     spacing = tonumber(Inputs[3])+1
  21.     length = tonumber(Inputs[2])
  22.     side = Inputs[1]
  23.     if shafts < 2 then
  24.         error("Input 7 is the number of shafts. Valid inputs are X > 1.")
  25.     end
  26.     if torch < 1 or torch > 16  then
  27.         error("Input 6 is the slot# of the torches. Valid inputs are 1-16.")
  28.     end
  29.     if chest < 1 or chest > 16 then
  30.         error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
  31.     end
  32.     if chest == torch then
  33.         error("The enderchest and torches cannot be in the same slot#!")
  34.     end
  35.     if light < 0 or light > 14 then
  36.         error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
  37.     end
  38.     if spacing < 2 or spacing > 6 then
  39.         error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
  40.     end
  41.     if length < 5 or length > 75 then
  42.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  43.     end
  44.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  45.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  46.     end
  47.  
  48. elseif #Inputs == 6 then
  49.     shafts = 5
  50.     torch = tonumber(Inputs[6])
  51.     chest = tonumber(Inputs[5])
  52.     light = tonumber(Inputs[4])
  53.     spacing = tonumber(Inputs[3])+1
  54.     length = tonumber(Inputs[2])
  55.     side = Inputs[1]
  56.     if torch < 1 or torch > 16  then
  57.         error("Input 6 is the slot# of the torches. Valid inputs are 1-16.")
  58.     end
  59.     if chest < 1 or chest > 16 then
  60.         error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
  61.     end
  62.     if chest == torch then
  63.         error("The enderchest and torches cannot be in the same slot#!")
  64.     end
  65.     if light < 0 or light > 14 then
  66.         error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
  67.     end
  68.     if spacing < 2 or spacing > 6 then
  69.         error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
  70.     end
  71.     if length < 5 or length > 75 then
  72.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  73.     end
  74.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  75.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  76.     end
  77.  
  78. elseif #Inputs == 5 then
  79.     shafts = 5
  80.     torch = 2
  81.     chest = tonumber(Inputs[5])
  82.     light = tonumber(Inputs[4])
  83.     spacing = tonumber(Inputs[3])+1
  84.     length = tonumber(Inputs[2])
  85.     side = Inputs[1]
  86.     if chest < 1 or chest > 16 then
  87.         error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
  88.     end
  89.     if chest == torch then
  90.         error("The enderchest and torches cannot be in the same slot#!")
  91.     end
  92.     if light < 0 or light > 14 then
  93.         error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
  94.     end
  95.     if spacing < 2 or spacing > 6 then
  96.         error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
  97.     end
  98.     if length < 5 or length > 75 then
  99.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  100.     end
  101.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  102.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  103.     end
  104.        
  105. elseif #Inputs == 4 then
  106.     shafts = 5
  107.     torch = 2
  108.     chest = 1
  109.     light = tonumber(Inputs[4])
  110.     spacing = tonumber(Inputs[3])+1
  111.     length = tonumber(Inputs[2])
  112.     side = Inputs[1]
  113.     if light < 0 or light > 14 then
  114.         error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
  115.     end
  116.     if spacing < 2 or spacing > 6 then
  117.         error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
  118.     end
  119.     if length < 5 or length > 75 then
  120.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  121.     end
  122.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  123.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  124.     end
  125.        
  126. elseif #Inputs == 3 then
  127.     shafts = 5
  128.     torch = 2
  129.     chest = 1
  130.     light = 12
  131.     spacing = tonumber(Inputs[3])+1
  132.     length = tonumber(Inputs[2])
  133.     side = Inputs[1]
  134.     if spacing < 2 or spacing > 6 then
  135.         error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
  136.     end
  137.     if length < 5 or length > 75 then
  138.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  139.     end
  140.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  141.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  142.     end
  143.  
  144. elseif #Inputs == 2 then
  145.     shafts = 5
  146.     torch = 2
  147.     chest = 1
  148.     light = 12
  149.     spacing = 5
  150.     length = tonumber(Inputs[2])
  151.     side = Inputs[1]
  152.     if length < 5 or length > 75 then
  153.         error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
  154.     end
  155.     if side ~= "solo" and side ~= "left" and side ~= "right" then
  156.         error("Input 1 is the shafting style. Valid inputs are 'solo' for one turtle, 'left' if this is the turtle on the left in a pair, or 'right' if this is the turtle on the right in a pair.")
  157.     end
  158.  
  159. else
  160.     error("Something's gone wrong. Doing Nothing.")
  161. end
  162.  
  163. -- Check for sufficient fuel, sufficient torches, enderchest, and a clear inventory
  164.  
  165. local Flvl = turtle.getFuelLevel()
  166. local TorchNum = turtle.getItemCount(torch)
  167. if side == "solo" then
  168.     Factor = 2
  169. else
  170.     Factor = 1
  171. end
  172.  
  173. --Fuel
  174. if Flvl == 0 then
  175.     print("You need fuel!")
  176.     return
  177. end
  178. if Flvl < Factor*(2*(length+spacing+1)+10)*shafts then
  179.     print("Not enough fuel. You need this much more to do that: ")
  180.     print(Factor*(2*(length+spacing+1)+10)*shafts-Flvl)
  181.     return
  182. end
  183.  
  184. --Torches
  185. if TorchNum == 0 then
  186.     print("You need to put torches in slot # ")
  187.     print(torch)
  188.     return
  189. end
  190. if TorchNum < math.ceil(Factor*length/light*shafts) then
  191.     print("Not enough torches. You need this many more to do that: ")
  192.     print(math.ceil(Factor*length/light*shafts)-TorchNum)
  193.     return
  194. end
  195.  
  196. --Enderchest
  197. if turtle.getItemCount(chest) < 1 then
  198.     print("You need an enderchest in slot# ")
  199.     print(chest)
  200.     return
  201. end
  202.  
  203. --Clear Inventory
  204. for Slot = 1, 16 do
  205.     if Slot ~= chest and Slot ~= torch and turtle.getItemCount(Slot) ~= 0 then
  206.         error("You need to clear all inventory spaces except for the enderchest and torches.")
  207.     end
  208. end
  209.  
  210. --------------------------
  211.  
  212. if side ~= "solo" then
  213.     print("This isn't implemented yet. Use solo mode.")
  214.     return
  215. end
  216.  
  217. if side == "solo" then
  218.     for CurrShaft = 1, shafts do
  219.  
  220.         -- left shaft
  221.         for CurrDepth = 2, length do
  222.             if not turtle.forward() then
  223.                 repeat
  224.                     turtle.dig()
  225.                     os.sleep(.6)
  226.                 until turtle.forward()
  227.             end
  228.         end
  229.         full = 1
  230.         turtle.digDown()
  231.         turtle.turnRight()
  232.         turtle.turnRight()
  233.         for CurrDepth = 1, length do
  234.             turtle.forward()
  235.             turtle.digDown()
  236.             if full == 1 then
  237.                 turtle.down()
  238.                 if turtle.detectDown() then
  239.                     turtle.up()
  240.                     turtle.select(chest)
  241.                     turtle.placeDown()
  242.                     for Slot = 1, 16 do
  243.                         if Slot ~= torch then
  244.                             turtle.select(Slot)
  245.                             turtle.dropDown()
  246.                         end
  247.                     end
  248.                     full = 0
  249.                     turtle.select(chest)
  250.                     turtle.digDown()
  251.                 else
  252.                     turtle.up()
  253.                 end    
  254.             end
  255.             if CurrDepth % light == 0 or CurrDepth == 1 then
  256.                 turtle.select(torch)
  257.                 turtle.placeDown()
  258.             end
  259.         end
  260.         full = 1
  261.         turtle.down()
  262.         if turtle.detectDown() then
  263.             turtle.up()
  264.             turtle.select(chest)
  265.             turtle.placeDown()
  266.             for Slot = 1, 16 do
  267.                 if Slot ~= torch then
  268.                     turtle.select(Slot)
  269.                     turtle.dropDown()
  270.                 end
  271.             end
  272.             turtle.select(chest)
  273.             turtle.digDown()
  274.             full = 0
  275.         else
  276.             turtle.up()
  277.         end
  278.  
  279.         -- right shaft
  280.         for CurrDepth = 1, length do
  281.             if not turtle.forward() then
  282.                 repeat
  283.                     turtle.dig()
  284.                     os.sleep(.6)
  285.                 until turtle.forward()
  286.             end
  287.         end
  288.         full = 1
  289.         turtle.digDown()
  290.         turtle.turnRight()
  291.         turtle.turnRight()
  292.         for CurrDepth = 1, length do
  293.             turtle.forward()
  294.             turtle.digDown()
  295.             if full == 1 then
  296.                 turtle.down()
  297.                 if turtle.detectDown() then
  298.                     turtle.up()
  299.                     turtle.select(chest)
  300.                     turtle.placeDown()
  301.                     for Slot = 1, 16 do
  302.                         if Slot ~= torch then
  303.                             turtle.select(Slot)
  304.                             turtle.dropDown()
  305.                         end
  306.                     end
  307.                     full = 0
  308.                     turtle.select(chest)
  309.                     turtle.digDown()
  310.                 else
  311.                     turtle.up()
  312.                 end  
  313.             end
  314.             if CurrDepth % light == 0 or CurrDepth == 1 then
  315.                 turtle.select(torch)
  316.                 turtle.placeDown()
  317.             end
  318.         end
  319.         full = 1
  320.         turtle.down()
  321.         if turtle.detectDown() then
  322.             turtle.up()
  323.             turtle.select(chest)
  324.             turtle.placeDown()
  325.             for Slot = 1, 16 do
  326.                 if Slot ~= torch then
  327.                     turtle.select(Slot)
  328.                     turtle.dropDown()
  329.                 end
  330.             end
  331.             turtle.select(chest)
  332.             turtle.digDown()
  333.             full = 0
  334.         else
  335.             turtle.up()
  336.         end
  337.  
  338.         -- Preparing for next shaft
  339.         turtle.select(torch)
  340.         turtle.placeDown()
  341.  
  342.         turtle.turnRight()
  343.         for CurrSpace = 1, spacing do
  344.             if not turtle.forward() then
  345.                 repeat
  346.                     turtle.dig()
  347.                     os.sleep(.6)
  348.                 until turtle.forward()
  349.             end
  350.             turtle.digDown()
  351.         end
  352.         turtle.turnLeft()
  353.         if CurrShaft ~= shafts then
  354.             turtle.dig()
  355.             turtle.forward()
  356.         end
  357.     end
  358.     turtle.turnLeft()
  359.     for Return = 1, shafts*spacing do
  360.         turtle.forward()
  361.     end
  362. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement