Advertisement
cragrim

_OpenPeripheralModDepletedFuelRodReplacer

Jun 29th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. --#########
  2. --IC2 Reactor depleted fuel rod replacer
  3. --Requires the OpenPeripherals mod! //Cragrim
  4. --#########
  5.  
  6. --  EDIT THE FOLLOWING
  7.  
  8. --Direction of the MEInterface from reactor
  9. --Use up, down, north, west, east, south
  10. storeDir = "down"
  11.  
  12. --Redstone input that starts the replacement
  13. redstoneSide = "top"
  14.  
  15. --MEInterface depleted uranium inv slot
  16. meSlotOld = 2
  17. --MEInterface fuel rod inv slot
  18. meSlotNew = 1
  19.  
  20. --Direction of the reactor from the computer
  21. using = peripheral.wrap("right")
  22.  
  23. --  DONT EDIT THE FOLLOWING
  24.  
  25. newItem = "ic2.reactorUraniumSimple"
  26. oldItem = "ic2.reactorUraniumSimpledepleted"
  27.  
  28. function errType(number)
  29.   number = tonumber(number)
  30.   if type(number) ~= "number" then
  31.     return false
  32.   else
  33.     return true
  34.   end
  35. end
  36.  
  37. function getName(peripheral,slot)
  38.   --check for integer
  39.   if errType(slot) == false then
  40.     return ""
  41.   else
  42.     if peripheral ~= nil then
  43.       item = peripheral.getStackInSlot(slot)
  44.       if item ~= nil then
  45.         return item["name"]
  46.       else
  47.         return ""
  48.       end
  49.     end
  50.   end
  51. end
  52.  
  53. while true do
  54.   print("Waiting for redstone signal from "..redstoneSide..".")
  55.   os.pullEvent("redstone")
  56.   if rs.getInput(redstoneSide) or rs.getBundledInput(redstoneSide, colors.white) then
  57.     print("Searching for ".. oldItem.." to replace with "..newItem..".")
  58.     count = 0
  59.     for i=1,54 do
  60.       if getName(using,i) == oldItem then
  61.         count = count + 1
  62.         using.pushItem(storeDir,i,1,meSlotOld)
  63.         using.pullItem(storeDir,meSlotNew,1,i)
  64.       end            
  65.     end
  66.     print("Replaced "..count.." items.")
  67.     os.sleep(10)
  68.   end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement