diff --git a/Gui/Language/English/inventoryDescriptions.json b/Gui/Language/English/inventoryDescriptions.json index 015786f..82dfe93 100644 --- a/Gui/Language/English/inventoryDescriptions.json +++ b/Gui/Language/English/inventoryDescriptions.json @@ -460,7 +460,7 @@ }, "921a2ace-b543-4ca3-8a9b-6f3dd3132fa9": { "title": "Color Block", - "description": "A block that can change colors.\n\nUse 1 number input to display a color from black to white (-1 is a quick way to get to white).\nUse 3 number inputs (painted red, green, blue) to use this block in RGB mode. Set each color component from 0 to 255\n\nPainting the block also works.\nCan connect color blocks together as well.\nWhite, grey, and black for glow, shine, and reflection. Colored logic input to change from RGB to HSV mode.", + "description": "A block that can change colors. Use 1 number input to display a color from black to white (-1 is a quick way to get to white). Use 3 number inputs (painted red, green, blue) to use this block in RGB mode. Set each color component from 0 to 255\n\nPainting the block also works. Can connect color blocks together as well. White for turning connected lights on/off. Colored logic input to change from RGB to HSV mode.", "keywords": [ "modpack", "smart", "logic", "number", "rgb", "colour", "screen", "display", "pixel", "dot", "glow", "shine", "reflect", "red", "green", "blue", "glow", "custom", "paint" ] }, "9c47ec58-bdfc-43a4-b066-852156ad812a": { diff --git a/Scripts/interactable/NumberLogic/ColorBlock.lua b/Scripts/interactable/NumberLogic/ColorBlock.lua index 5012363..0c3a402 100644 --- a/Scripts/interactable/NumberLogic/ColorBlock.lua +++ b/Scripts/interactable/NumberLogic/ColorBlock.lua @@ -6,7 +6,11 @@ dofile "../../libs/load_libs.lua" print("loading ColorBlock.lua") - +---@class ColorBlock : ShapeClass +---@field power number +---@field color Color +---@field prev number +---@field prevcolor table ColorBlock = class( nil ) ColorBlock.maxParentCount = 7 ColorBlock.maxChildCount = -1 @@ -18,7 +22,7 @@ ColorBlock.poseWeightCount = 1 function ColorBlock.server_onCreate( self ) self.power = 0 - self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this. + -- self.glowinput = 0 -- glow of this block end function ColorBlock.server_onProjectile(self, X, hits, four) local red = math.random(0,255) @@ -33,18 +37,29 @@ function ColorBlock.server_onFixedUpdate( self, dt ) local green = 0 local blue = 0 local HSVmode = false + local active = nil -- turn connected lamps on/off based on this. + local parentIndicesToRemove = {} for k, parent in pairs(parents) do if not sm.interactable.isNumberType(parent) and parent:getType() ~= "steering" and tostring(parent:getShape():getShapeUuid()) ~= "ccaa33b6-e5bb-4edc-9329-b40f6efe2c9e" --[[orienter]] then -- logic: switch, logic gate, ... - table.remove(parents, k) + table.insert(parentIndicesToRemove, k) -- We cannot directly remove the parent from the table, as it would mess up the iteration local parentcolor = parent:getShape().color if not (parentcolor.r == parentcolor.g) or not (parentcolor.r == parentcolor.b) then HSVmode = parent.active + elseif tostring(parentcolor) == "eeeeeeff" then + if active == nil then + active = parent.active + else + active = active or parent.active + end end end end + for i = #parentIndicesToRemove, 1, -1 do + table.remove(parents, parentIndicesToRemove[i]) + end if #parents == 1 then self.power = math.round(sm.interactable.getPower(parents[1]))%(256^3) @@ -52,6 +67,11 @@ function ColorBlock.server_onFixedUpdate( self, dt ) local green = (self.power % (256^2)/256)%256 local blue = self.power % 256 self.shape.color = sm.color.new(red/255, green/255, blue/255, 1) + if active == nil then + active = parents[1].active + else + -- White logic overrides the active state, so do not change it + end elseif #parents >= 3 then if self.prev and self.prev < 3 then -- 2 -> 3 parents event trigger , colors parents rgb @@ -257,13 +277,13 @@ function ColorBlock.server_onFixedUpdate( self, dt ) self.color = color - mp_updateOutputData(self, self.power, self.glowinput > 0) + mp_updateOutputData(self, self.power, active) end -function ColorBlock.client_onCreate(self) - --self.interactable:setGlowMultiplier(0) - self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this. -end +-- function ColorBlock.client_onCreate(self) +-- --self.interactable:setGlowMultiplier(0) +-- self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this. +-- end function ColorBlock.client_giveError(self, error) diff --git a/Scripts/libs/other.lua b/Scripts/libs/other.lua index d65f8a2..b54f9e2 100644 --- a/Scripts/libs/other.lua +++ b/Scripts/libs/other.lua @@ -38,11 +38,11 @@ function mp_updateOutputData(self, power, active) self.sv_saved_power = power sInteractable:setPower(power) - if (active ~= self.sv_saved_active) or should_reset then - self.sv_saved_active = active - sInteractable:setActive(active) - end - sm.interactable.setValue(sInteractable, power) end + + if (active ~= self.sv_saved_active) or should_reset then + self.sv_saved_active = active + sInteractable:setActive(active) + end end \ No newline at end of file