Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local computer = require("computer")
- local sides = require("sides")
- local component = require("component")
- local ic = component.inventory_controller
- --the length of the tunnels
- local distance = 0
- --spacing between the tunnels
- local width = 0
- --from startingpoint to the left or right
- local direction = 0
- --how often is the process repeated
- local multi = 0
- --how often has the process repeated YET
- local multiCounter = 0
- --distance traveled since the last torch
- local torchCounter = 0
- --local xcord = 0
- --local ycord = 0
- --local zcord = 0
- --error check
- local error = 0
- --local minEnergy = 0.25
- local torchDist = 11
- local dropChecker = 1
- --Lets the robot dig up and forward until everything is cleared. Then moves it forward
- function forward(a, b, c)
- local i = 0
- while i < a do
- if robot.detectUp() then
- repeat
- robot.swingUp()
- until not robot.detectUp()
- end
- if robot.detect() then
- repeat
- robot.swing()
- until not robot.detect()
- end
- robot.forward()
- i = i+1
- if b == true then
- if robot.detectDown() == false then
- robot.select(2)
- robot.placeDown()
- end
- end
- if c == true then
- torchCounter = torchCounter+1
- lightCheck()
- end
- end
- end
- --Executes the turn-manouver
- function turn()
- if direction == 0 then
- robot.turnLeft()
- forward(width+1, true, true)
- robot.turnLeft()
- direction = 1
- elseif direction == 1 then
- robot.turnRight()
- forward(width+1, true, true)
- robot.turnRight()
- direction = 0
- end
- end
- --Checks if it is time to place a torch
- function lightCheck()
- if torchCounter >= torchDist then
- placeTorch()
- end
- end
- --Places a torch behind the robot
- function placeTorch()
- if robot.count(1) > 1 then
- local slot1 = ic.getStackInInternalSlot(1)
- if slot1.name == "minecraft:torch" then
- robot.turnAround()
- robot.select(1)
- robot.place(sides.down)
- robot.turnAround()
- torchCounter = 0
- end
- end
- end
- --Checks remaining space in the inventory and starts the unload and restock process if applicable
- function inventoryCheck()
- if robot.count(robot.inventorySize()-2) > 0 then
- returnToChest((multiCounter*(width+1))+(width+1))
- unload()
- restock()
- returnToMine()
- end
- if robot.count(1) < 2 then
- returnToChest((multiCounter*(width+1))+(width+1))
- unload()
- restock()
- returnToMine()
- end
- end
- --Moves the robot back to the starting point
- function returnToChest(length)
- if direction == 0 then
- robot.turnRight()
- elseif direction == 1 then
- robot.turnLeft()
- end
- if robot.detectUp() then
- repeat
- robot.swingUp()
- until not robot.detectUp()
- end
- robot.up()
- local a = 0
- while a < length do
- if robot.detect() then
- repeat
- robot.swing()
- until not robot.detect()
- end
- robot.forward()
- a = a+1
- end
- if robot.detectDown() then
- repeat
- robot.swingDown()
- until not robot.detectDown()
- end
- robot.down()
- if direction == 0 then
- robot.turnRight()
- elseif direction == 1 then
- robot.turnLeft()
- end
- end
- --Drops all Items into to chest. Does NOT drop Slot 1 and leaves 20 Items in Slot 2
- function unload()
- local i = robot.inventorySize()
- while i > 2 do
- robot.select(i)
- if robot.count(i) == 0 then
- else
- robot.drop()
- end
- i = i-1
- end
- robot.select(2)
- robot.drop(44)
- end
- --Refills the first slot with torches from a chest in front of it
- function restock()
- local chestSize, chestSizeAdd = ic.getInventorySize(3)
- local i = 1
- if chestSize == nil then
- else
- while i <= chestSize do
- local info = ic.getStackInSlot(3, i)
- if info == nil then
- else
- if info.name == "minecraft:torch" then
- robot.select(1)
- if robot.space(1)>0 then
- ic.suckFromSlot(3,i,robot.space(1))
- end
- end
- end
- i = i+1
- end
- end
- end
- --Moves the Robot to the last position in the Mine
- function returnToMine()
- if direction == 0 then
- robot.turnRight()
- elseif direction == 1 then
- robot.turnLeft()
- end
- if robot.detectUp() then
- repeat
- robot.swingUp()
- until not robot.detectUp()
- end
- robot.up()
- local a = 0
- while a < ((multiCounter*(width+1))+(width+1)) do
- if robot.detect() then
- repeat
- robot.swing()
- until not robot.detect()
- end
- robot.forward()
- a = a+1
- end
- if robot.detectDown() then
- repeat
- robot.swingDown()
- until not robot.detectDown()
- end
- robot.down()
- if direction == 0 then
- robot.turnRight()
- elseif direction == 1 then
- robot.turnLeft()
- end
- end
- --Basic systemcheck
- function iCheck()
- if robot.count(1) < 1 then
- print("No torches in Slot 1!")
- print("")
- error = 1
- end
- if distance < 1 then
- print("Tunnel lenght is less than 1! Enter a valid distance.")
- print("")
- error = 2
- end
- if width < 1 then
- print("Space between tunnels is less than 1! Enter valid width.")
- print("")
- error = 2
- end
- --if (computer.energy() >= (minEnergy*computer.maxEnergy())) then
- -- print("Energylevel is too low. Please recharge first.")
- -- print("")
- -- error = 3
- --end
- if (direction < 0 or direction > 1) then
- print("A invalid direction was entered.")
- print("")
- error = 2
- end
- os.sleep(3)
- if error == 0 then
- print("Check complete. Starting to mine.")
- print("")
- elseif error == 1 then
- reCheck()
- elseif error == 2 then
- print("Please restart the program.")
- print("")
- computer.shutdown(true)
- elseif error == 3 then
- print("Shutting down.")
- print("")
- computer.shutdown(false)
- end
- end
- --Recheck if only torches are missing
- function reCheck()
- print("Please put some torches in the first inventory-slot.")
- while robot.count(1) == 0 do
- print("Standing by...")
- print("")
- os.sleep(5)
- end
- error = 0
- iCheck()
- end
- --To change basic parameters
- function admin()
- print("minEnergy in %")
- input5 = io.read()
- minEnergy = (tonumber(input5)/100)
- print("torchDist?")
- input6 = io.read()
- torchDist = tonumber(input6)
- print("dropChecker?")
- input7 = io.read()
- dropChecker = tonumber(input7)
- print("End of Admin()")
- print("")
- os.sleep(2)
- end
- --Starts the process
- function start()
- while multiCounter < multi do
- forward(distance, true, true)
- turn()
- if (multiCounter % 2 == 0) then
- --Robot is on the wrong wide of the mine. No good path to the unloading-box
- else
- inventoryCheck()
- end
- multiCounter = multiCounter+1
- end
- if (multi % 2 == 0) then
- returnToChest(((multiCounter-1)*(width+1))+(width+1))
- unload()
- else
- returnToChest(((multiCounter-1)*(width+1))+(width+1))
- robot.turnAround()
- robot.up()
- torchDist = 99999
- forward(distance, false, false)
- robot.down()
- unload()
- end
- print("")
- print("-----------------------")
- print("ALL DONE! SHUTTING DOWN IN 10s")
- print("-----------------------")
- print("")
- os.sleep(10)
- computer.shutdown(false)
- end
- print("Welcome to Voxxels Stripmining program")
- print("-----------------------------------")
- print("How far do you want to go?")
- input1 = io.read()
- distance = tonumber(input1)
- if distance == 1234 then
- admin()
- end
- print("-----------------------------------")
- print("How many blocks between the tunnels?")
- input2 = io.read()
- width = tonumber(input2)
- print("----------------------------------")
- print("Left or Right?")
- print("(0 = Left ; 1 = Right)")
- input3 = io.read()
- direction = tonumber(input3)
- print("----------------------------------")
- print("Ok almost done.")
- print("How often should I repeat that?")
- input4 = io.read()
- multi = tonumber(input4)
- print("")
- print("Well done. Now let me do a quick system check...")
- os.sleep(1)
- print(".")
- os.sleep(1)
- print("..")
- os.sleep(1)
- print("...")
- print("")
- iCheck()
- os.sleep(2)
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement