Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Strip Mining Program--
- -- I didn't write it, just took and upgraded.
- torchDist = 10
- --Start of Torch stuff
- function placeTorch()
- print("Placing torch...")
- if turtle.getItemCount(3) == 1 then
- turtle.select(4) --Considering adding a method of returning home if no torches present in second slot
- turtle.place()
- else
- turtle.select(3)
- turtle.place()
- turtle.select(1)
- end
- torchDist = 1
- end
- function needTorch()
- if torchDist == 10 then
- placeTorch()
- end
- end
- --End of Torch stuff
- function forward()
- while not turtle.forward() do
- turtle.dig()
- sleep(.1)
- end
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(.8)
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(.8)
- end
- end
- function clear()
- shell.run("clear")
- end
- function calculate() --Change this when you start having him loop
- local fuel = turtle.getFuelLevel()
- local chests = turtle.getItemCount(2)
- local torches = turtle.getItemCount(3)+turtle.getItemCount(4)
- local fuelCycles = math.floor(fuel/180)
- local torchCycles = math.floor(torches/4)
- local chestCycles = math.floor(chests*2)
- local cycles = 0
- if fuelCycles<torchCycles then --This big block takes cycles and figures out which between chests, fuel, and torches can perform
- if fuelCycles<chestCycles then --least amount of cycles and sets cycles to that amount. Ensures resources for every cycle.
- cycles = fuelCycles
- else
- cycles = chestCycles
- end
- elseif torchCycles<fuelCycles then
- if torchCycles<chestCycles then
- cycles = torchCycles
- else
- cycles = chestCycles
- end
- elseif fuelCycles<chestCycles then
- if fuelCycles<torchCycles then
- cycles = fuelCycles
- else
- cycles = torchCycles
- end
- elseif chestCycles<fuelCycles then
- if chestCycles< torchCycles then
- cycles = chestCycles
- else
- cycles = torchCycles
- end
- elseif torchCycles<chestCycles then
- if torchCycles< fuelCycles then
- cycles = torchCycles
- else
- cycles = fuelCycles
- end
- elseif chestCycles<torchCycles then
- if chestCycles< fuelCycles then
- cycles = chestCycles
- else
- cycles = fuelCycles
- end
- else
- cycles = fuelCycles
- end
- if fuel <500 or torches<10 then
- print("I need both 500 fuel and at least 10 torches.")
- print("I have "..torches.." torches and "..fuel.." fuel.")
- else
- clear()
- print("-----------------------------------")
- print("Fuel is: "..fuel)
- print(chests.." chests in slot 2")
- print(torches.." torches in slots 3 and 4")
- print("Doing "..cycles.." cycles with these resources.")
- print("-----------------------------------")
- print("Is this acceptable? (y/n)")
- local input = "{"
- while not input == "y" or "n" do
- input = read()
- if input == "y" then
- branchControl(cycles)
- elseif input == "n" then
- print("Shutting down program...")
- sleep(1.5)
- clear()
- break
- else
- print("That is not a valid option! Please type y or n and hit ENTER")
- end
- end
- end
- end
- function chestDrop()
- if turtle.detectDown() then
- local x = 5
- while x<17 do
- turtle.select(x)
- turtle.dropDown()
- x=x+1
- end
- else
- local x=5
- turtle.select(2)
- turtle.placeDown()
- while x<17 do
- turtle.select(x)
- turtle.dropDown()
- x=x+1
- end
- end
- end
- function branchControl(cycles) --Don't indefinitely loop it yet
- while cycles>0 do
- if cycles>0 then
- tunnel(5, false)
- turtle.turnRight()
- forward()
- tunnel(30, true)
- turtle.up()
- forward()
- chestDrop()
- forward()
- turtle.down()
- cycles = cycles -1
- else
- break
- end
- if cycles>0 then
- tunnel(30, true)
- turtle.up()
- forward()
- chestDrop()
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- dig()
- digUp()
- turtle.up()
- dig()
- turtle.turnRight()
- turtle.turnRight()
- dig()
- turtle.down()
- dig()
- turtle.digDown()
- turtle.down()
- if turtle.detectDown() then
- turtle.select(1)
- turtle.placeDown()
- end
- dig()
- turtle.turnLeft()
- turtle.turnLeft()
- dig()
- turtle.turnRight()
- cycles = cycles-1
- else
- break
- end
- end
- end
- function tunnel(distance, isReturn) --Test this before trying to automate it!
- local x =0
- while x<distance do
- forward()
- if not turtle.detectDown() then
- turtle.select(1)
- turtle.placeDown()
- end
- turtle.turnLeft()
- dig()
- needTorch()
- digUp()
- turtle.up()
- dig()
- digUp()
- turtle.up()
- if not turtle.detectUp() then --Sort of helps cover the place? Top and bottom at least get inspection XD
- turtle.select(1)
- turtle.placeUp()
- end
- dig()
- turtle.turnRight()
- turtle.turnRight()
- dig()
- turtle.down()
- dig()
- turtle.down()
- dig()
- turtle.turnLeft()
- x=x+1
- torchDist = torchDist+1
- end
- --And here begins the returning home process
- turtle.turnLeft()
- turtle.turnLeft()
- if isReturn == true then
- local x=0
- while x<distance do
- forward()
- x=x+1
- end
- end
- end
- function init()
- calculate()
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment