KapitanWalnut

Recharger v0.2

Mar 14th, 2014
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. --Recharger by KapitanWalnut
  2. --3/14/2014  v0.2
  3. --When incorporated with the proper devices, this program will attempt to recharge a flux device at set intervals.
  4. --do not have any adjacent redstone signals other then intended... machine looks for redstone signals
  5. --Intended to be used with continuous harvesting machines such as mob grinders or crop harvesters.
  6. --NOT intended to be used as remote recharge station. I have a different program for that ;)
  7.  
  8. --CONFIG
  9. waitTime = 60 --seconds to wait before attempting another recharge
  10. invSide = "left" --side that receives redstone indication signal about state of managed inventory (inv)
  11. suckSide = "bottom" --side to output redstone signal in order to suck contents from managed inv
  12.  
  13. --whether or not device is in charging mode
  14. charging = false
  15.  
  16. --INITIALIZE
  17. --note: upon initialization, program will assume any items in adjacent inventory need to be recharged.
  18. function initialize()
  19.     term.clear()
  20.     term.setCursorPos(1,1)
  21.     print("Initializing...")
  22.     sleep(5)
  23.     charging = rs.getInput(invSide) --if nothing in inv, assume it is recharging
  24.     if not charging then --if something in inv, send it to recharge
  25.         suckOn()
  26.         charging = true
  27.     end
  28. end
  29.  
  30. --turn sucker on
  31. function suckOn()
  32.     rs.setOutput(suckSide, true)
  33. end
  34.  
  35. --turn sucker off
  36. function suckOff()
  37.     rs.setOutput(suckSide, false)
  38. end
  39.  
  40. --main logic function: handles the mechanics of recharging and waiting to charge
  41. function mainLogic()
  42.     --wait for redstone signal to change
  43.     os.pullEvent("redstone")
  44.     --get state of input
  45.     tempState = rs.getInput(invSide)
  46.     if tempState then --if true, means inventory is empty, so turn sucker off
  47.         suckOff()
  48.         term.clear()
  49.         term.setCursorPos(1,1)
  50.         print("Device sent to charger...")
  51.     else --if false, means inventory has item in it
  52.         term.clear()
  53.         term.setCursorPos(1,1)
  54.         print("Device received from charger.")
  55.         print("Harvesting for ",waitTime," seconds...")
  56.         sleep(waitTime) --wait specified time
  57.         suckOn() --turn on sucker to charge again
  58.     end
  59. end
  60.  
  61. --main function
  62. function main()
  63.     initialize()
  64.     while true do --infinite loop
  65.         mainLogic()
  66.     end
  67. end
  68.  
  69. --run main function
  70. main()
Advertisement
Add Comment
Please, Sign In to add comment