Advertisement
Sanwi

CC: Big Reactors rod control interface

Feb 10th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. local function getDevices(deviceType) -- Credit: https://github.com/sandalle/minecraft_bigreactor_control, https://github.com/Sanwi
  2. local deviceName = nil
  3. local deviceIndex = 1
  4. local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
  5. local peripheralList = peripheral.getNames() -- Get table of connected peripherals
  6. for peripheralIndex = 1, #peripheralList do -- Log every device found
  7. if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == string.lower(deviceType)) then -- Log devices found which match deviceType and which device index we give them
  8. deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  9. deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  10. deviceIndex = deviceIndex + 1
  11. end
  12. end -- for peripheralIndex = 1, #peripheralList do
  13. return deviceList, deviceNames
  14. end
  15.  
  16. local reactorList, reactorNames = getDevices("bigreactors-reactor")
  17.  
  18.  
  19. -- Get default rod levels
  20. local rodLevels = reactorList[1].getControlRodLevel(1)
  21.  
  22. while true do
  23. term.clear()
  24. term.setCursorPos(1,1)
  25. term.write("Rod insertion level: "..tostring(rodLevels))
  26. term.setCursorPos(1,2)
  27. term.write("Press S to extract by 10%, and W to insert by 10%")
  28. term.setCursorPos(1,3)
  29. term.write("Press E to extract by 1%, and F to insert by 1%")
  30.  
  31. local event, key = os.pullEvent("key")
  32. if key == 17 then -- S
  33. rodLevels = rodLevels + 10
  34. elseif key == 31 then -- W
  35. rodLevels = rodLevels - 10
  36. elseif key == 18 then -- E
  37. rodLevels = rodLevels + 1
  38. elseif key == 33 then -- F
  39. rodLevels = rodLevels - 1
  40. end
  41. if rodLevels < 0 then rodLevels = 0 elseif rodLevels > 100 then rodLevels = 100 end
  42.  
  43. reactorList[1].setAllControlRodLevels(rodLevels)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement