csmit195

OCS RM Furnace Counter

Jun 26th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local targets = {'-4,0,5', '-5,-1,5', '-5,1,5', '-6,-1,5', '-6,1,5', '-7,-1,5', '-7,1,5', '-8,0,5'}
  2.  
  3. os.loadAPI('ocs/apis/sensor')
  4. local prox, monitor = sensor.wrap('right'), peripheral.wrap('bottom')
  5.  
  6. local currentRMFurnaces, trueEmcValue, lastRMFurnaces, currentSecond, maxStacks = 0, 0, 0, 0, 6912*#targets
  7.  
  8. function initiate()
  9.     monitor.setTextScale(1.5)
  10.     while true do
  11.         loop()
  12.         currentSecond = currentSecond + 1
  13.         sleep(1)
  14.     end
  15. end
  16.  
  17. function loop()
  18.     -- Every 2 Seconds to reduce amount of sensor calls and potentially limit lag
  19.     if ( currentSecond % 2 == 0 ) then
  20.         -- Probe Sensors
  21.         currentRMFurnaces = 0
  22.         for index, target in ipairs(targets) do
  23.             local targetDetails = prox.getTargetDetails(target)
  24.             if ( targetDetails and targetDetails.Name == 'Crystal Chest' ) then
  25.                 for slot, item in ipairs(targetDetails.Slots) do
  26.                     if ( item.Name == 'Red Matter Furnace') then
  27.                         currentRMFurnaces = currentRMFurnaces + item.Size
  28.                     end
  29.                 end
  30.             end
  31.         end
  32.        
  33.         -- Calculate EMC Per Second
  34.         local emcPerSecond = math.floor((currentRMFurnaces-lastRMFurnaces) * 10059784)/5
  35.         local rmCountString = 'Furnaces: '..(currentRMFurnaces > 64 and math.floor(currentRMFurnaces / 64)..' stacks & ' or '')..(currentRMFurnaces % 64)..' items'
  36.         local storedEMC = currentRMFurnaces * 10059784
  37.        
  38.         -- Calculate percentage
  39.         local percentageStored = math.ceil((currentRMFurnaces/maxStacks) * 100) .. '%'
  40.        
  41.         -- Store biggest number of EMC incase of Zero Per Second.
  42.         trueEmcValue = (emcPerSecond ~= 0 and emcPerSecond or trueEmcValue)
  43.        
  44.         monitor.clear()
  45.         monitor.setCursorPos(2,3)
  46.         monitor.write('EMC Rate: '..trueEmcValue..' per/s')
  47.         monitor.setCursorPos(2,4)
  48.         monitor.write(rmCountString)
  49.         monitor.setCursorPos(2,5)
  50.         monitor.write('Stored EMC: '..storedEMC)
  51.         monitor.setCursorPos(2,6)
  52.         monitor.write('Percentage: '..percentageStored)
  53.         lastRMFurnaces = currentRMFurnaces
  54.     end
  55. end
  56.  
  57. initiate()
Advertisement
Add Comment
Please, Sign In to add comment