Advertisement
Guest User

test

a guest
Jan 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1. local comp = require("component")
  2. local s = require("sides")
  3.  
  4. local t = comp.transposer
  5. local gpu = comp.gpu
  6. local rs = comp.redstone
  7. local mfsu = comp.ic2_te_mfsu
  8.  
  9. gpu.setResolution(80,40)
  10. local sWidth, sHeight = gpu.getResolution()
  11.  
  12. local interfaceSide = s.top
  13. local inputSlot = 1
  14. local outputSlot = 2
  15.  
  16. local fuelDamage = 10000
  17.  
  18. local numOfReactors = 4
  19. local reactors = {[1]={["side"]=s.west, ["slot"]=14, ["fuel"]=0},
  20.                   [2]={["side"]=s.west, ["slot"]=17, ["fuel"]=0},
  21.                   [3]={["side"]=s.east, ["slot"]=14, ["fuel"]=0},
  22.                   [4]={["side"]=s.east, ["slot"]=17, ["fuel"]=0}}
  23.  
  24. local storageEnergy = 0
  25. local storageDelta = 0
  26. local storageCapacity = 0
  27.  
  28. function CheckReactor(side, slot)
  29.  stack = t.getStackInSlot(side, slot)
  30.  if(stack ~= nil) then
  31.   if(stack.name == "ic2:nuclear") then
  32.    --t.transferItem(s.bottom, s.top, slot, 1)
  33.    return 0
  34.   else
  35.    if(stack.customDamage == nil) then
  36.     return fuelDamage
  37.    end
  38.    return fuelDamage - stack.customDamage  
  39.   end
  40.  end
  41.  return 0
  42. end
  43.  
  44. function RefuelReactor(side, slot)
  45.  --Transfer Out
  46.  t.transferItem(side, interfaceSide, 1, slot)
  47.  
  48.  --Transfer In
  49.  t.transferItem(interfaceSide, side, 1, inputSlot, slot)
  50. end
  51.  
  52. function GetStorage()
  53.  if(storageCapacity == 0) then storageCapacity = mfsu.getCapacity() end
  54.  lastEnergy = storageEnergy
  55.  storageEnergy = mfsu.getEnergy()
  56.  storageDelta = storageEnergy - lastEnergy
  57. end
  58.  
  59. function DisplayClear()
  60.  gpu.setBackground(0x000000, false)
  61.  gpu.fill(1,1, sWidth, sHeight, " ")
  62. end
  63.  
  64. function DisplayBar(y, height, value, text, fgColor1, fgColor2, bgColor1, bgColor2, bgColor3)
  65.  xText = math.floor(((sWidth-2) - #text)/2)+2
  66.  
  67.  xFill = math.floor((sWidth-2)*value + 0.5)+2
  68.  yText = y + math.floor(height/2)
  69.  gpu.setForeground(fgColor1, false)
  70.  for y=y,y+height-1 do
  71.   if(y == yText) then
  72.    for x=2,xText-1 do
  73.     bgColor = bgColor1
  74.     if(x<xFill) then
  75.      if(x%2==1) then bgColor = bgColor2 end
  76.     else
  77.      bgColor = bgColor3
  78.     end
  79.     gpu.setBackground(bgColor, false)
  80.  
  81.     gpu.set(x,y, " ")
  82.    end
  83.    x = xText  
  84.    for c in text:gmatch(".") do
  85.  
  86.     bgColor = bgColor1
  87.     if(x<xFill) then
  88.      if(x%2==1) then bgColor = bgColor2 end
  89.     else
  90.      bgColor = bgColor3
  91.      gpu.setForeground(fgColor2, false)
  92.     end
  93.     gpu.setBackground(bgColor, false)
  94.  
  95.     gpu.set(x,y, c)
  96.     x = x + 1
  97.    end
  98.  
  99.    for x=xText+#text,sWidth-1 do
  100.     bgColor = bgColor1
  101.     if(x<xFill) then
  102.      if(x%2==1) then bgColor = bgColor2 end
  103.     else
  104.      bgColor = bgColor3
  105.     end
  106.     gpu.setBackground(bgColor, false)
  107.  
  108.     gpu.set(x,y, " ")
  109.    end
  110.   else
  111.    for x=2,sWidth-1 do
  112.     bgColor = bgColor1
  113.     if(x < xFill) then
  114.      if(x%2==1) then bgColor = bgColor2 end
  115.     else
  116.      bgColor = bgColor3
  117.     end
  118.     gpu.setBackground(bgColor, false)
  119.     gpu.set(x,y, " ")
  120.    end
  121.   end
  122.  end
  123. end
  124.  
  125. function DisplayUpdate()
  126.  --DisplayClear()
  127.  
  128.  storageText = (math.floor(storageEnergy).. " / " .. math.floor(storageCapacity))
  129.  DisplayBar(2,19, storageEnergy/storageCapacity, storageText, 0x222222, 0xAAAAAA, 0x00B6FF, 0x66B6FF, 0x111111)
  130.  
  131.  
  132. end
  133.  
  134. DisplayClear()
  135.  
  136. while true do
  137.  
  138.  rFuelStrings = "Reactors: "
  139.  -- Update Reactors
  140.  for r=1,numOfReactors do
  141.   rSide = reactors[r]["side"]
  142.   rSlot = reactors[r]["slot"]
  143.  
  144.   rFuel = CheckReactor(rSide, rSlot)
  145.  
  146.   if(rFuel == 0) then
  147.    RefuelReactor(rSide, rSlot)
  148.   end
  149.  
  150.   rFuel = CheckReactor(rSide, rSlot)
  151.   --rFuelStrings = rFuelStrings .. "[" .. r .. "]: " .. math.floor(rFuel/fuelDamage * 100) .. ", "
  152.   reactors[r]["fuel"] = rFuel
  153.  end
  154.  --print(rFuelStrings)
  155.  
  156.  --Update Storage
  157.  GetStorage()
  158.  --print("Storage: " .. math.floor(storageEnergy/storageCapacity * 100))
  159.  
  160.  if(storageEnergy/storageCapacity < 0.75) then
  161.   rs.setOutput(s.east, 1)
  162.   rs.setOutput(s.west, 1)
  163.  elseif(storageEnergy/storageCapacity > 0.99) then
  164.   rs.setOutput(s.east, 0)
  165.   rs.setOutput(s.west, 0)
  166.  end
  167.  
  168.  DisplayUpdate()
  169.  os.sleep(1)
  170. -- break
  171. end
  172. --print(CheckReactor(s.top, 1))
  173. --RefuelReactor(s.top, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement