Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This code is developed by me (onix331) and modified by Xenomurks and is availiable under the GNU General Public License (Version 3)
- --See http://opensource.org/licenses/GPL-3.0
- --Have fun
- shaftcount = 0--Used later in the program, usually not necessary do modify it
- space = 15--Defines the space of the turtle
- ver = 1.7--For updates
- chest = 0--If the turtle has stopped at a chest
- stop = 0--If the turtle has stopped at a chest
- direction = r
- function checkl() --To check if length is valid (>0, not a String), also transforms the string into a number
- length = tonumber(length)
- if length==nil then
- print ("Invalid number!")
- length = read()
- checkl()
- elseif length <= 0 then
- print ("Invalid number!")
- length = read()
- checkl()
- end
- end
- function checka()--To check if count is valid (>0, not a String), also transforms the string into a number
- count = tonumber(count)
- if count==nil then
- print ("Invalid number!")
- count = read()
- checka()
- elseif count <= 0 then
- print ("Invalid number!")
- count = read()
- checka()
- end
- end
- function checkr()--To check if direction is valid ((r) or (l))
- if direction=="r" then
- print ("")
- elseif direction=="l" then
- print ("")
- else
- print ("Invalid input!")
- direction = io.read()
- checkr()
- end
- end
- function checkref()--To check if refuel is valid ((r) or (l))
- if refuel=="y" then
- print ("")
- elseif refuel=="n" then
- print ("")
- else
- print ("Invalid number!")
- refuel = io.read()
- checkref()
- end
- end
- function checktor()--To check if torch is valid ((y) or (n))
- if torch=="y" then
- print ("")
- elseif torch=="n" then
- print ("")
- else
- print ("Invalid number!")
- torch = io.read()
- checktor()
- end
- end
- function move()--Basic movement funktion
- local debug = 8--Used to avoid gavel, sand, etc.
- for i = 1, length do
- if turtle.detect() then
- for i = 1, debug do
- turtle.dig()
- end
- turtle.forward()
- else
- turtle.forward()
- end
- if turtle.detectUp() then
- for i = 1, debug do
- turtle.digUp()
- end
- end
- end
- end
- function turnaround()--Turns the turtle at 90 degrees
- turtle.turnRight()
- turtle.turnRight()
- end
- function nextshaft()--Next shaft (right)
- turtle.turnLeft()
- turtle.dig()
- turtle.digUp()
- turtle.forward()
- turtle.dig()
- turtle.digUp()
- turtle.turnRight()
- turtle.select(16)
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.dig()
- turtle.digUp()
- turtle.forward()
- turtle.digUp()
- turtle.turnRight()
- end
- function returnpoint()--Return to initial point
- if direction=="r" then
- turtle.turnRight()
- if shaftcount>=2 then
- turtle.forward()
- end
- turtle.forward()
- for i = 1, shaftcount do
- turtle.forward()
- turtle.forward()
- end
- if stop==1 then
- turtle.forward()
- end
- --turtle.turnLeft()
- for i = 1, space do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- turnaround()
- if chest==1 then
- returnmining()
- end
- end
- function returnmining()--Beta-feature
- stop = 1
- chest = 0
- if direction=="r" then
- turnaround()
- for i = 1, shaftcount do
- turtle.forward()
- turtle.forward()
- turtle.forward()
- end
- turtle.turnRight()
- for i = 1, count do
- move()
- turnaround()
- move()
- move()
- turnaround()
- move()
- nextshaft()
- shaftcount = shaftcount + 1
- count = count - 1
- checkspace()
- end
- end
- end
- function checkspace()--Check for space and if necessary, return to initial point to the chest
- local spaceleft = 0
- for i = 1, space do
- if turtle.getItemSpace(i) > 10 then
- spaceleft = spaceleft + 1
- end
- end
- if spaceleft < 5 then
- chest = 1
- count = count - 1
- returnpoint()
- end
- end
- shell.run ("clear")
- print ("Strip-mining-program by onix331")
- print ("Version ", ver)
- --Start user input
- print ("Length of the single shaft(s):")
- length = read()
- checkl()
- print ("Count of the shafts:")
- count = read()
- checka()
- print ("Want to put some Torches on the Wall?")
- print ("Now? (Yes (y), No (n):")
- torch = read()
- checktor()
- if torch=="y" then
- print ("Please Put some in Slot 16")
- print ("When done, press ENTER")
- local sEvent, param = os.pullEvent("key")
- if sEvent == "key" then
- end
- end
- --Refueling, a little bit complicated
- print ("Dont forget to refuel!")
- print ("Now? (Yes (y), No (n):")
- refuel = read()
- checkref()
- if refuel=="y" then
- print ("Please insert fuel anywhere")
- print ("When done, press ENTER")
- while true do
- local sEvent, param = os.pullEvent("key")
- if sEvent == "key" then
- if param == 28 then
- for i = 1, space do
- for i = 1, 64 do
- shell.run("refuel", rafzahl)
- end
- turtle.select(i)
- end
- turtle.select(1)
- break
- end
- end
- end
- end
- --Print user inputs
- shell.run ("clear")
- print ("Input of Length:")
- print (length)
- print ("Input of count")
- print (count)
- os.sleep(2)
- print ("3")
- os.sleep(1)
- print ("2")
- os.sleep(1)
- print ("1")
- os.sleep(1)
- print("Start!")
- --Main Program
- if direction=="r" then
- --turtle.turnRight()
- for i = 1, count do
- move()
- turnaround()
- move()
- move()
- turnaround()
- move()
- nextshaft()
- shaftcount = shaftcount + 1
- count = count - 1
- checkspace()
- end
- end
- returnpoint()
- print ("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement