Advertisement
systox

eutester

May 19th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. local aes = 2
  2. local produce = 32768
  3. local modemSide = "front"
  4.  
  5. maxenergy = produce*aes
  6. rednet.open(modemSide)
  7.  
  8. function convertNBT(nbt)
  9.     local conv = {}
  10.     if (nbt == nil) then
  11.         return nil
  12.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  13.         for key, value in pairs(nbt["value"]) do
  14.             conv[key] = convertNBT(value)
  15.         end
  16.     else
  17.         conv = nbt["value"]
  18.     end
  19.     return conv
  20. end
  21.  
  22.  
  23. function getNBT(side)
  24.     local pipe = peripheral.wrap(side)
  25.     pipe.getAvailableItems()
  26.     local event, items = os.pullEvent("available_items_return")
  27.     return convertNBT(pipe.getNBTTagCompound(items[1][1]))
  28. end
  29.  
  30.  
  31. function messure()
  32.     rs.setOutput("bottom",true)
  33.     sleep(.5)
  34.     rs.setOutput("bottom",false)
  35.     sleep(.5)
  36.     return getNBT("right")
  37. end
  38.  
  39. function calculate()
  40.     count = 0
  41.    
  42.     while true do
  43.         if count > 0 then
  44.             local nbt = messure()
  45.             i2 = nbt["lastTotalEnergyEmitted"]
  46.             t2 = nbt["lastMeasureTime"]
  47.             local i = (i2 - i1)
  48.             local t = (t2 - t1)
  49.             print("Energie: "..i/t.."eu/t")
  50.             print("MaxEnergie: "..maxenergy)
  51.             print("å9Cberfluss: "..maxenergy-(i/t))
  52.             pkg = {}
  53.             table.insert(pkg,i/t)
  54.             --table.insert(pkg,maxenergy)
  55.             rednet.broadcast(textutils.serialize(pkg))
  56.             count = 0
  57.         else
  58.             local nbt = messure()
  59.             i1 = nbt["lastTotalEnergyEmitted"]
  60.             t1 = nbt["lastMeasureTime"]
  61.             count = 1
  62.         end
  63.     end
  64. end
  65.  
  66. calculate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement