Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PROGRAM_VERSION = "1.0"
- local completion = require "cc.completion"
- local configured --check to see if the computer has been configured, if not then prompt user, if yes then start working!
- local configurePath = "wisher/_states/botania_uniRail"
- local modes = { "source", "destination" }
- local sides = { "left", "right", "front", "back", "top", "bottom"}
- local mode --either "source" or "destination" from modes{}, source fills carts from farms, destination drains them into facilities
- local inputFace --redstone input
- local outputFace --redstone output
- -- verify whether program has been configured
- if (fs.exists(configurePath)) then
- local handle = fs.open(configurePath, "r")
- local verify = handle.readLine()
- handle.close()
- if (verify == "") then --check to see if file is empty
- configured = false
- else
- configured = true
- end
- else
- configured = false
- end
- -- can reset the config file without manually deleting it
- if #arg > 0 then
- if (string.lower(arg[1]) == "reset") then
- if (fs.exists(configurePath)) then
- fs.delete(configurePath)
- sleep(0.3)
- if (fs.exists(configurePath)) then
- configured = false
- print("config reset!")
- end
- end
- else
- print("to reset config please type \"reset\" after the programname")
- sleep(3)
- os.reboot()
- end
- end
- --run configuration if not configured
- if not configured then
- print("Please select \"source\" or \"destination\"")
- print("source is where you generate the mana")
- print("destination is where it is being delivered")
- print("tab to complete, up/down arrow to show choices, enter to select")
- mode = string.lower(read(nil, nil, function(text) return completion.choice(text, modes, false) end))
- print("Which face is the redstone input, comparator side")
- print("Assume you are looking at the PC screen, front would be facing you, right your right etc.")
- inputFace = string.lower(read(nil, nil, completion.side))
- print("Which face is the output side, powers the rail")
- outputFace = string.lower(read(nil, nil, completion.side))
- print("processing your inputs")
- sleep(3)
- shell.run("clear")
- if (not ((mode == modes[1]) or (mode == modes[2]))) then
- print("incorrectly entered the 'mode', should be 'source' or 'destination'")
- print("restarting in 5 seconds")
- os.reboot()
- end
- local inputVerify = false
- local outputVerify = false
- for i = 1, #sides, 1 do
- if (inputFace == sides[i]) then
- inputVerify = true
- end
- if (outputFace == sides[i]) then
- outputVerify = true
- end
- end
- if (not (inputVerify and outputVerify)) then
- print("incorrectly entered the 'input or ouput', should be left, right, top, bottom, front or back")
- print("restarting in 5 seconds")
- os.reboot()
- end
- print("saving configuration, please wait a few seconds")
- local handle = fs.open(configurePath, "w")
- handle.writeLine(mode)
- handle.writeLine(inputFace)
- handle.writeLine(outputFace)
- handle.close()
- sleep(2)
- if (fs.exists(configurePath)) then
- configured = true
- print("configuration saved!")
- else
- print("something went wrong saving config, restarting")
- sleep(3)
- os.reboot()
- end
- end
- if configured then
- -- import the configuration as variables
- local handle = fs.open(configurePath, "r")
- mode = handle.readLine()
- inputFace = handle.readLine()
- outputFace = handle.readLine()
- handle.close()
- -- source cart
- if (mode == modes[1]) then
- local boot = true
- if ((rs.getAnalogInput(inputFace) == 15) and (boot)) then
- rs.setAnalogOutput(outputFace, 15)
- sleep(0.5)
- rs.setAnalogOutput(outputFace, 0)
- boot = false
- end
- while true do
- print("Waiting to fill cart")
- os.pullEvent("redstone")
- if (rs.getAnalogInput(inputFace) == 15) then
- print("filled cart")
- rs.setAnalogOutput(outputFace, 15)
- sleep(0.5)
- rs.setAnalogOutput(outputFace, 0)
- end
- end
- --destination cart
- else
- rs.setAnalogOutput(outputFace, 15)
- sleep(0.5)
- rs.setAnalogOutput(outputFace, 0)
- while true do
- print("waiting for cart")
- os.pullEvent("redstone")
- local cart = false
- if (rs.getInput(inputFace)) then
- cart = true
- print("emptying cart")
- end
- while cart do
- os.pullEvent("redstone")
- print("depleting cart")
- if (rs.getAnalogInput(inputFace) == 0) then
- rs.setAnalogOutput(outputFace, 15)
- sleep(0.5)
- rs.setAnalogOutput(outputFace, 0)
- cart = false
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment