Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Auto Smeltery for Tinker's Construct
- -- By David Jordan (cube_man)
- ------ INITIALIZATION ------
- -- Variables --
- local side = "back"
- local monitor = peripheral.wrap("top")
- local startTime = 0
- local done = false
- local running = true
- -- Input/Output colors --
- local out_pour = colors.white
- local out_pop_cast = colors.orange
- local out_return_cast = colors.magenta
- local out_return_item = colors.lime
- local in_press_button = colors.lightBlue
- local in_item_in_chest = colors.yellow
- ------ FUNCTIONS ------
- -- Queue a random event to make sure the program is occupied --
- function nullEvent()
- os.queueEvent("randomEvent")
- os.pullEvent()
- end
- -- Print text to the monitor --
- function monitorPrint(str)
- monitor.write(str)
- end
- -- Print a line to the monitor --
- function monitorPrintln(str)
- monitor.write(str)
- local cx, cy = monitor.getCursorPos()
- monitor.setCursorPos(1, cy + 1)
- end
- -- Set the color index of the boundled output to the given value --
- function setOutput(index, value)
- local bundle = redstone.getBundledOutput(side)
- if value then
- redstone.setBundledOutput(side, bit.bor(bundle, index))
- else
- redstone.setBundledOutput(side, bit.band(bundle, bit.bnot(index)))
- end
- end
- -- Get the color index of the bundled output --
- function getOutput(index)
- return bit.band(redstone.getBundledOutput(side), index) == index
- end
- -- Get the color index of the bundled input --
- function getInput(index)
- return bit.band(redstone.getBundledInput(side), index) == index
- end
- ------ MAIN ------
- print("Running Smeltery Program.")
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitorPrintln("Running Smeltery")
- while running do
- setOutput(out_pop_cast, false)
- setOutput(out_return_cast, true)
- setOutput(out_return_item, false)
- setOutput(out_pour, false)
- -- Wait for user to press the button.
- while not getInput(in_press_button) do
- if rs.getInput("left") then
- monitorPrintln("Powering down...")
- os.sleep(1)
- monitor.clear()
- running = false
- break
- end
- nullEvent()
- end
- if not running then
- break
- end
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitorPrintln("Button Pressed!")
- monitorPrint("Pouring")
- -- Keep pouring until the cast is filled.
- local done = false
- local startTime = 0
- while not done do
- monitorPrint(".")
- -- Try to pour for 0.5 seconds --
- setOutput(out_pour, true)
- startTime = os.clock()
- while os.clock() - startTime < 0.5 and not done do
- if getInput(in_item_in_chest) then
- done = true
- end
- nullEvent()
- end
- setOutput(out_pour, false)
- if not done then
- -- Wait for 1.5 seconds --
- startTime = os.clock()
- while os.clock() - startTime < 1.5 and not done do
- if getInput(in_item_in_chest) then
- done = true
- end
- nullEvent()
- end
- end
- end
- monitorPrintln("")
- monitorPrintln("Done!")
- -- Return created item.
- setOutput(out_return_item, true)
- -- Pop cast.
- setOutput(out_pop_cast, true)
- os.sleep(0.4)
- setOutput(out_pop_cast, false)
- -- Return cast.
- --setOutput(out_return_cast, true)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement