Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Get inputs
- local Inputs = { ... }
- --Check # of inputs
- if #Inputs < 2 or #Inputs > 7 then
- print("Usage: branch <solo/side> <branchlength> <branchspacing> <torchspacing> <enderchestslot#> <torchesslot#> <#ofShafts>.")
- return true
- end
- --Check input validity
- if #Inputs == 7 then
- shafts = tonumber(Inputs[7])
- torch = tonumber(Inputs[6])
- chest = tonumber(Inputs[5])
- light = tonumber(Inputs[4])
- spacing = tonumber(Inputs[3])+1
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if shafts < 2 then
- error("Input 7 is the number of shafts. Valid inputs are X > 1.")
- end
- if torch < 1 or torch > 16 then
- error("Input 6 is the slot# of the torches. Valid inputs are 1-16.")
- end
- if chest < 1 or chest > 16 then
- error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
- end
- if chest == torch then
- error("The enderchest and torches cannot be in the same slot#!")
- end
- if light < 0 or light > 14 then
- error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
- end
- if spacing < 2 or spacing > 6 then
- error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
- end
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- elseif #Inputs == 6 then
- shafts = 5
- torch = tonumber(Inputs[6])
- chest = tonumber(Inputs[5])
- light = tonumber(Inputs[4])
- spacing = tonumber(Inputs[3])+1
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if torch < 1 or torch > 16 then
- error("Input 6 is the slot# of the torches. Valid inputs are 1-16.")
- end
- if chest < 1 or chest > 16 then
- error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
- end
- if chest == torch then
- error("The enderchest and torches cannot be in the same slot#!")
- end
- if light < 0 or light > 14 then
- error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
- end
- if spacing < 2 or spacing > 6 then
- error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
- end
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- elseif #Inputs == 5 then
- shafts = 5
- torch = 2
- chest = tonumber(Inputs[5])
- light = tonumber(Inputs[4])
- spacing = tonumber(Inputs[3])+1
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if chest < 1 or chest > 16 then
- error("Input 5 is the slot# of the enderchest. Valid inputs are 1-16")
- end
- if chest == torch then
- error("The enderchest and torches cannot be in the same slot#!")
- end
- if light < 0 or light > 14 then
- error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
- end
- if spacing < 2 or spacing > 6 then
- error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
- end
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- elseif #Inputs == 4 then
- shafts = 5
- torch = 2
- chest = 1
- light = tonumber(Inputs[4])
- spacing = tonumber(Inputs[3])+1
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if light < 0 or light > 14 then
- error("Input 4 is the number of spaces between torches. Valid inputs are 0-14.")
- end
- if spacing < 2 or spacing > 6 then
- error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
- end
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- elseif #Inputs == 3 then
- shafts = 5
- torch = 2
- chest = 1
- light = 12
- spacing = tonumber(Inputs[3])+1
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if spacing < 2 or spacing > 6 then
- error("Input 3 is the number of blocks between shafts. Valid inputs are 2-6.")
- end
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- elseif #Inputs == 2 then
- shafts = 5
- torch = 2
- chest = 1
- light = 12
- spacing = 5
- length = tonumber(Inputs[2])
- side = Inputs[1]
- if length < 5 or length > 75 then
- error("Input 2 is the length of each shaft. Valid inputs are 5-75.")
- end
- if side ~= "solo" and side ~= "left" and side ~= "right" then
- 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.")
- end
- else
- error("Something's gone wrong. Doing Nothing.")
- end
- -- Check for sufficient fuel, sufficient torches, enderchest, and a clear inventory
- local Flvl = turtle.getFuelLevel()
- local TorchNum = turtle.getItemCount(torch)
- if side == "solo" then
- Factor = 2
- else
- Factor = 1
- end
- --Fuel
- if Flvl == 0 then
- print("You need fuel!")
- return
- end
- if Flvl < Factor*(2*(length+spacing+1)+10)*shafts then
- print("Not enough fuel. You need this much more to do that: ")
- print(Factor*(2*(length+spacing+1)+10)*shafts-Flvl)
- return
- end
- --Torches
- if TorchNum == 0 then
- print("You need to put torches in slot # ")
- print(torch)
- return
- end
- if TorchNum < math.ceil(Factor*length/light*shafts) then
- print("Not enough torches. You need this many more to do that: ")
- print(math.ceil(Factor*length/light*shafts)-TorchNum)
- return
- end
- --Enderchest
- if turtle.getItemCount(chest) < 1 then
- print("You need an enderchest in slot# ")
- print(chest)
- return
- end
- --Clear Inventory
- for Slot = 1, 16 do
- if Slot ~= chest and Slot ~= torch and turtle.getItemCount(Slot) ~= 0 then
- error("You need to clear all inventory spaces except for the enderchest and torches.")
- end
- end
- --------------------------
- if side ~= "solo" then
- print("This isn't implemented yet. Use solo mode.")
- return
- end
- if side == "solo" then
- for CurrShaft = 1, shafts do
- -- left shaft
- for CurrDepth = 2, length do
- if not turtle.forward() then
- repeat
- turtle.dig()
- os.sleep(.6)
- until turtle.forward()
- end
- end
- full = 1
- turtle.digDown()
- turtle.turnRight()
- turtle.turnRight()
- for CurrDepth = 1, length do
- turtle.forward()
- turtle.digDown()
- if full == 1 then
- turtle.down()
- if turtle.detectDown() then
- turtle.up()
- turtle.select(chest)
- turtle.placeDown()
- for Slot = 1, 16 do
- if Slot ~= torch then
- turtle.select(Slot)
- turtle.dropDown()
- end
- end
- full = 0
- turtle.select(chest)
- turtle.digDown()
- else
- turtle.up()
- end
- end
- if CurrDepth % light == 0 or CurrDepth == 1 then
- turtle.select(torch)
- turtle.placeDown()
- end
- end
- full = 1
- turtle.down()
- if turtle.detectDown() then
- turtle.up()
- turtle.select(chest)
- turtle.placeDown()
- for Slot = 1, 16 do
- if Slot ~= torch then
- turtle.select(Slot)
- turtle.dropDown()
- end
- end
- turtle.select(chest)
- turtle.digDown()
- full = 0
- else
- turtle.up()
- end
- -- right shaft
- for CurrDepth = 1, length do
- if not turtle.forward() then
- repeat
- turtle.dig()
- os.sleep(.6)
- until turtle.forward()
- end
- end
- full = 1
- turtle.digDown()
- turtle.turnRight()
- turtle.turnRight()
- for CurrDepth = 1, length do
- turtle.forward()
- turtle.digDown()
- if full == 1 then
- turtle.down()
- if turtle.detectDown() then
- turtle.up()
- turtle.select(chest)
- turtle.placeDown()
- for Slot = 1, 16 do
- if Slot ~= torch then
- turtle.select(Slot)
- turtle.dropDown()
- end
- end
- full = 0
- turtle.select(chest)
- turtle.digDown()
- else
- turtle.up()
- end
- end
- if CurrDepth % light == 0 or CurrDepth == 1 then
- turtle.select(torch)
- turtle.placeDown()
- end
- end
- full = 1
- turtle.down()
- if turtle.detectDown() then
- turtle.up()
- turtle.select(chest)
- turtle.placeDown()
- for Slot = 1, 16 do
- if Slot ~= torch then
- turtle.select(Slot)
- turtle.dropDown()
- end
- end
- turtle.select(chest)
- turtle.digDown()
- full = 0
- else
- turtle.up()
- end
- -- Preparing for next shaft
- turtle.select(torch)
- turtle.placeDown()
- turtle.turnRight()
- for CurrSpace = 1, spacing do
- if not turtle.forward() then
- repeat
- turtle.dig()
- os.sleep(.6)
- until turtle.forward()
- end
- turtle.digDown()
- end
- turtle.turnLeft()
- if CurrShaft ~= shafts then
- turtle.dig()
- turtle.forward()
- end
- end
- turtle.turnLeft()
- for Return = 1, shafts*spacing do
- turtle.forward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement