Advertisement
cc-editor

Farbproduktion

Jan 1st, 2025 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. settings.load()
  2.  
  3. local me_bridge = peripheral.wrap(settings.get("color.me_bridge"))
  4. local redstone_side = settings.get("color.redstone_side")
  5.  
  6. local max_storage_amount = settings.get("color.max_storage_amount")
  7. local min_storage_amount = settings.get("color.min_storage_amount")
  8.  
  9. local dye_colors = settings.get("color.colors")
  10.  
  11. local function stop_all()
  12.     local redstone_colors = 0
  13.     for i, color in pairs(dye_colors) do
  14.         local color_value = colors.fromBlit(color.value)
  15.         if color.inverted then
  16.             redstone_colors = colors.subtract(redstone_colors, color_value)
  17.         else
  18.             redstone_colors = colors.combine(redstone_colors, color_value)
  19.         end
  20.     end
  21.     redstone.setBundledOutput(redstone_side, redstone_colors)
  22. end
  23.  
  24. local function stop_color(color_blit_value, inverted)
  25.     local output = redstone.getBundledOutput(redstone_side)
  26.     local color_value = colors.fromBlit(color_blit_value)
  27.     if inverted then
  28.         output = colors.subtract(output, color_value)
  29.     else
  30.         output = colors.combine(output, color_value)
  31.     end
  32.     redstone.setBundledOutput(redstone_side, output)
  33. end
  34.  
  35. local function start_color(color_blit_value, inverted)
  36.     local output = redstone.getBundledOutput(redstone_side)
  37.     local color_value = colors.fromBlit(color_blit_value)
  38.     if inverted then
  39.         output = colors.combine(output, color_value)
  40.     else
  41.         output = colors.subtract(output, color_value)
  42.     end
  43.     redstone.setBundledOutput(redstone_side, output)
  44. end
  45.  
  46. local function check_storage()
  47.     for i, color in pairs(dye_colors) do
  48.         print("Checking storage for "..color.name.." ...")
  49.         local item = me_bridge.getItem({name = color.item})
  50.         if item == nil or item.amount == nil then
  51.             print("   NOTHING FOUND - producting")
  52.             start_color(color.value, color.inverted)
  53.         elseif item.amount < max_storage_amount then
  54.             print("   found "..item.amount.." - producting")
  55.             start_color(color.value, color.inverted)
  56.         else
  57.             print("   found "..item.amount.." - OK")
  58.             stop_color(color.value, color.inverted)
  59.         end
  60.         sleep(1)
  61.     end
  62. end
  63.  
  64. print(" -- Farbproduktion -- ")
  65. stop_all()
  66. while true do
  67.     check_storage()
  68.     sleep(30)
  69. end
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement