Advertisement
bobmarley12345

ccPowerMon5

Sep 3rd, 2021 (edited)
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. function string.jsub(str, startIndex, endIndex)
  2.     if (endIndex == nil) then
  3.         endIndex = string.len(str) + 1
  4.     end
  5.    
  6.     return string.sub(str, startIndex, endIndex - 1)
  7. end
  8.  
  9. -- Checks if the given `str` starts with the given `value` (optionally start searching with the given start offset index. 1 by default). `string.startsWith("hello", "he", 1)` == `true`
  10. function string.startsWith(str, value, startIndex)
  11.     if (startIndex == nil) then
  12.         startIndex = 1
  13.     end
  14.    
  15.     return string.jsub(str, startIndex, string.len(value) + startIndex) == value
  16. end
  17.  
  18. -- Checks if the given `str` ends with the given value. string.endsWith("hello", "lo") == true
  19. function string.endsWith(str, value)
  20.     local strLen = string.len(str)
  21.     local valLen = string.len(value)
  22.     return string.sub(str, strLen - valLen + 1, strLen) == value
  23. end
  24.  
  25. function string.contains(str, value, startIndex)
  26.     if (startIndex == nil) then
  27.         startIndex = 1
  28.     end
  29.    
  30.     return
  31. end
  32.  
  33. function string.indexOf(str, value, startIndex)
  34.     if (startIndex == nil) then
  35.         startIndex = 1
  36.     end
  37.  
  38.     local s,e,c = string.find(str, value)
  39.     if (s == nil) then
  40.         return -1
  41.     end
  42.  
  43.     return s
  44. end
  45.  
  46. peripherals = { }
  47.  
  48. Monitor = peripheral.wrap("right")
  49.  
  50. function loadCells()
  51.     for i, name in pairs(peripheral.getNames()) do
  52.         if (string.startsWith(name, "cofh_thermalexpansion_energycell")) then
  53.             local id = tonumber(string.sub(name, 33))
  54.             local handle = peripheral.wrap(name)
  55.             peripherals[id] = {
  56.                 handle = handle,
  57.                 full_name = name,
  58.                 energyMin = 0,
  59.                 energyMax = handle.getMaxEnergyStored("UNKNOWN"),
  60.                 energyNow = handle.getEnergyStored("UNKNOWN"),
  61.                 id = id
  62.             }
  63.         end
  64.     end
  65. end
  66.  
  67. function main()
  68.     loadCells()
  69.     for k,v in pairs(peripherals) do
  70.         print(k .. " - " .. v)
  71.     end
  72. end
  73.  
  74. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement