Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local colors = require("colors")
  4. local event = require("event")
  5. local rs = component.redstone -- component.list("redstone")()
  6. --local os = require("os")
  7.  
  8. do_debug = true
  9. DEBUG = function(msg)
  10. if do_debug then
  11. print(msg)
  12. end
  13. end
  14.  
  15. -- OCEmu has no redstone.
  16. if rs == nil then
  17. rs = {}
  18. rs.getInput = function(s) return 0 end
  19. rs.setOutput = function(a,b) return 0 end
  20. end
  21.  
  22. local getredanyside = function ()
  23. for i = 0,6,1
  24. do
  25. DEBUG("tested " .. i .. "=" .. rs.getInput(i))
  26. if rs.getInput(i) > 0 then
  27. return 15
  28. end
  29. end
  30. return 0
  31. end
  32.  
  33. function file_exists(name)
  34. local f=io.open(name,"r")
  35. if f~=nil then io.close(f) return true else return false end
  36. end
  37.  
  38. local open = io.open
  39.  
  40. local function read_file(path)
  41. local file = open(path, "rb") -- r read mode and b binary mode
  42. if not file then return nil end
  43. local content = file:read "*a" -- *a or *all reads the whole file
  44. file:close()
  45. return content
  46. end
  47.  
  48. local function write_file(path, val)
  49. local file = io.open(path, "w")
  50. file:write(val)
  51. file:close()
  52. end
  53.  
  54. --[[
  55. "redstone_changed"
  56. UUID
  57. side
  58. previous signal strength
  59. new signal strength
  60. ]]--
  61.  
  62. local ingredient_input_comparator_signal = sides.south
  63. local pipe_load_jammer_block = sides.north
  64. local pipe_unload_jammer_block = sides.up
  65. local pipe_deliver_materials = sides.east
  66. local craft_complete_signal = sides.west
  67.  
  68. local CRAFTING = false
  69. local etimer = 0
  70.  
  71. function begin_craft_sequence()
  72. print("\n")
  73. print("Crafting sequence starting. Loading jammer block.")
  74. CRAFTING = true
  75. rs.setOutput(pipe_unload_jammer_block, 0)
  76. rs.setOutput(pipe_load_jammer_block, 15)
  77. print("...")
  78. os.sleep(1)
  79. print("Enabling material transmission.")
  80. rs.setOutput(pipe_deliver_materials, 15)
  81. end
  82. function end_craft_sequence()
  83. print("\n")
  84. print("Crafting sequence ending. Disabling transmission. Removing jammer block.")
  85. rs.setOutput(pipe_deliver_materials, 0)
  86. rs.setOutput(pipe_unload_jammer_block, 15)
  87. rs.setOutput(pipe_load_jammer_block, 0)
  88. CRAFTING = false
  89. event.timer(1000, delayed_comparator_recheck, 1)
  90. end
  91.  
  92. function delayed_comparator_recheck()
  93. if CRAFTING == false and rs.getInput(ingredient_input_comparator_signal) > 0 then
  94. print("Time delayed check shows inv full: looping craft process.")
  95. begin_craft_sequence()
  96. else
  97. print("Time delayed check shows inv empty: shutting down")
  98. end
  99. end
  100.  
  101. function redstone_event(eventname, address, side, oldValue, newValue)
  102. print("redstone_event("..address..", "..side..", "..oldValue..", "..newValue..")")
  103. if oldValue ~= newValue then
  104. print("oldValue ~= newValue")
  105. print("ingredient_input_comparator_signal="..ingredient_input_comparator_signal)
  106. print("CRAFTING="..CRAFTING)
  107. if newValue > 0 and side == ingredient_input_comparator_signal == 0 and CRAFTING == false then
  108. print("bcs")
  109. begin_craft_sequence()
  110. elseif newValue > 0 and side == craft_complete_signal and CRAFTING == true then
  111. print("ecs")
  112. end_craft_sequence()
  113. end
  114. end
  115. end
  116.  
  117. event.listen("redstone_changed", redstone_event)
  118. print("event handler registered.")
  119.  
  120. begin_craft_sequence()
  121. end_craft_sequence()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement