Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local colors = require("colors")
- local event = require("event")
- local rs = component.redstone -- component.list("redstone")()
- --local os = require("os")
- do_debug = true
- DEBUG = function(msg)
- if do_debug then
- print(msg)
- end
- end
- -- OCEmu has no redstone.
- if rs == nil then
- rs = {}
- rs.getInput = function(s) return 0 end
- rs.setOutput = function(a,b) return 0 end
- end
- local getredanyside = function ()
- for i = 0,6,1
- do
- DEBUG("tested " .. i .. "=" .. rs.getInput(i))
- if rs.getInput(i) > 0 then
- return 15
- end
- end
- return 0
- end
- function file_exists(name)
- local f=io.open(name,"r")
- if f~=nil then io.close(f) return true else return false end
- end
- local open = io.open
- local function read_file(path)
- local file = open(path, "rb") -- r read mode and b binary mode
- if not file then return nil end
- local content = file:read "*a" -- *a or *all reads the whole file
- file:close()
- return content
- end
- local function write_file(path, val)
- local file = io.open(path, "w")
- file:write(val)
- file:close()
- end
- --[[
- "redstone_changed"
- UUID
- side
- previous signal strength
- new signal strength
- ]]--
- local ingredient_input_comparator_signal = sides.south
- local pipe_load_jammer_block = sides.north
- local pipe_unload_jammer_block = sides.up
- local pipe_deliver_materials = sides.east
- local craft_complete_signal = sides.west
- local CRAFTING = false
- local etimer = 0
- function begin_craft_sequence()
- print("\n")
- print("Crafting sequence starting. Loading jammer block.")
- CRAFTING = true
- rs.setOutput(pipe_unload_jammer_block, 0)
- rs.setOutput(pipe_load_jammer_block, 15)
- print("...")
- os.sleep(1)
- print("Enabling material transmission.")
- rs.setOutput(pipe_deliver_materials, 15)
- end
- function end_craft_sequence()
- print("\n")
- print("Crafting sequence ending. Disabling transmission. Removing jammer block.")
- rs.setOutput(pipe_deliver_materials, 0)
- rs.setOutput(pipe_unload_jammer_block, 15)
- rs.setOutput(pipe_load_jammer_block, 0)
- CRAFTING = false
- event.timer(1000, delayed_comparator_recheck, 1)
- end
- function delayed_comparator_recheck()
- if CRAFTING == false and rs.getInput(ingredient_input_comparator_signal) > 0 then
- print("Time delayed check shows inv full: looping craft process.")
- begin_craft_sequence()
- else
- print("Time delayed check shows inv empty: shutting down")
- end
- end
- function redstone_event(eventname, address, side, oldValue, newValue)
- print("redstone_event("..address..", "..side..", "..oldValue..", "..newValue..")")
- if oldValue ~= newValue then
- print("oldValue ~= newValue")
- print("ingredient_input_comparator_signal="..ingredient_input_comparator_signal)
- print("CRAFTING="..CRAFTING)
- if newValue > 0 and side == ingredient_input_comparator_signal == 0 and CRAFTING == false then
- print("bcs")
- begin_craft_sequence()
- elseif newValue > 0 and side == craft_complete_signal and CRAFTING == true then
- print("ecs")
- end_craft_sequence()
- end
- end
- end
- event.listen("redstone_changed", redstone_event)
- print("event handler registered.")
- begin_craft_sequence()
- end_craft_sequence()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement