Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local function find_energy_cube()
  2.   local cube_names = {"Ultimate Energy Cube", "Elite Energy Cube", "Advanced Energy Cube", "Basic Energy Cube"}
  3.   local cube = nil
  4.   for cube_name in cube_names do
  5.     cube = peripheral.find(cube_name)
  6.     if cube != nil then
  7.       break
  8.     end
  9.   end
  10.   return cube
  11. end
  12.  
  13. local cube = find_energy_cube()
  14.  
  15. if cube == nil then
  16.   print("No energy cube found!")
  17.   exit()
  18. end
  19.  
  20. local threshold_percent = 90
  21. local max_energy = cube.getMaxEnergy()
  22. local stored_energy = max_energy
  23. local stored_percent = stored_energy/max_energy
  24.  
  25. local cable_side = "bottom"
  26. local color_separator = colors.red
  27.  
  28. while true do
  29.   -- Update values
  30.   stored_energy = max_energy
  31.   stored_percent = stored_energy/max_energy
  32.  
  33.   -- Change state accordingly
  34.   if stored_percent > threshold_percent then
  35.     redstone.setBundledOutput(cable_side, color_separator)
  36.   else
  37.     redstone.setBundledOutput(cable_side, 0)
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement