From 54e9bb633ef2d3b4ffe8cc4ce786dc3aa04eac3b Mon Sep 17 00:00:00 2001 From: TechnologicNick Date: Tue, 19 Nov 2024 00:10:59 +0100 Subject: [PATCH 1/4] Fix `mp_updateOutputData` not updating `active` state if power did not change --- Scripts/libs/other.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 From 2225b2e63bbd00bd96a026c23c0208a44bd050af Mon Sep 17 00:00:00 2001 From: TechnologicNick Date: Tue, 19 Nov 2024 00:11:51 +0100 Subject: [PATCH 2/4] Re-enable Color Block turning on lights on white input --- .../interactable/NumberLogic/ColorBlock.lua | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Scripts/interactable/NumberLogic/ColorBlock.lua b/Scripts/interactable/NumberLogic/ColorBlock.lua index 5012363..e054199 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,6 +37,7 @@ 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. for k, parent in pairs(parents) do if not sm.interactable.isNumberType(parent) and parent:getType() ~= "steering" and @@ -42,6 +47,12 @@ function ColorBlock.server_onFixedUpdate( self, dt ) 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 @@ -52,6 +63,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 +273,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) From 338a4d1112bc1d76fe405d39ff5248f820d3abe7 Mon Sep 17 00:00:00 2001 From: TechnologicNick Date: Tue, 19 Nov 2024 00:18:16 +0100 Subject: [PATCH 3/4] Update Color Block English description to fit, add white to toggle lights Also removed the mentioning of glow, shine and reflection, as these still don't work. --- Gui/Language/English/inventoryDescriptions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From cc5653731f4b497a830f02a0cc29c9c02bd40c72 Mon Sep 17 00:00:00 2001 From: TechnologicNick Date: Tue, 19 Nov 2024 00:55:18 +0100 Subject: [PATCH 4/4] Fix Color Block forcefully recoloring logic inputs when more than one are connected --- Scripts/interactable/NumberLogic/ColorBlock.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Scripts/interactable/NumberLogic/ColorBlock.lua b/Scripts/interactable/NumberLogic/ColorBlock.lua index e054199..0c3a402 100644 --- a/Scripts/interactable/NumberLogic/ColorBlock.lua +++ b/Scripts/interactable/NumberLogic/ColorBlock.lua @@ -10,7 +10,7 @@ print("loading ColorBlock.lua") ---@field power number ---@field color Color ---@field prev number ----@field prevcolor table +---@field prevcolor table ColorBlock = class( nil ) ColorBlock.maxParentCount = 7 ColorBlock.maxChildCount = -1 @@ -38,12 +38,13 @@ function ColorBlock.server_onFixedUpdate( self, dt ) 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 @@ -56,6 +57,9 @@ function ColorBlock.server_onFixedUpdate( self, dt ) 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)