22
33import java .util .function .Consumer ;
44import mekanism .api .gear .IModule ;
5+ import mekanism .api .gear .IModuleContainer ;
6+ import mekanism .api .gear .IModuleHelper ;
57import mekanism .api .gear .config .ModuleColorConfig ;
68import mekanism .client .gui .GuiModuleTweaker ;
79import mekanism .client .gui .GuiUtils ;
1113import mekanism .common .MekanismLang ;
1214import mekanism .common .content .gear .shared .ModuleColorModulationUnit ;
1315import mekanism .common .lib .Color ;
16+ import mekanism .common .registries .MekanismModules ;
1417import mekanism .common .util .text .TextUtils ;
18+ import net .minecraft .client .Minecraft ;
1519import net .minecraft .client .gui .GuiGraphics ;
1620import net .minecraft .network .chat .Component ;
1721import net .minecraft .world .entity .EquipmentSlot ;
@@ -76,21 +80,26 @@ protected void click(double mouseX, double mouseY) {
7680 Runnable previewReset = null ;
7781 IModule <?> currentModule = parent .getCurrentModule ();
7882 if (armorPreview != null && data .name ().equals (ModuleColorModulationUnit .COLOR ) && currentModule != null ) {
79- ItemStack stack = parent .getContainerStack ();
83+ ItemStack stack = parent .getContainerStack (). copy () ;
8084 if (stack .getItem () instanceof ArmorItem armorItem ) {
8185 //Ensure the preview has been initialized
8286 armorPreview .get ();
8387 EquipmentSlot slot = armorItem .getEquipmentSlot ();
8488 //Replace the current preview with our copy
8589 armorPreview .updatePreview (slot , stack );
86- updatePreviewColor = c -> setData (c .argb ());
90+ updatePreviewColor = c -> {
91+ IModuleContainer moduleContainer = IModuleHelper .INSTANCE .getModuleContainer (stack );
92+ if (moduleContainer != null ) {//Note: Should always be present
93+ //Note: We can use the source data to ensure we have the correct config option, as with does not mutate it
94+ moduleContainer .replaceModuleConfig (Minecraft .getInstance ().level .registryAccess (), stack , MekanismModules .COLOR_MODULATION_UNIT ,
95+ data .with (c .argb ()));
96+ }
97+ };
8798 previewReset = () -> armorPreview .resetToDefault (slot );
8899 }
89100 }
90- GuiColorWindow window = new GuiColorWindow (parent .gui (), parent .getGuiWidth () / 2 - 160 / 2 , parent .getGuiHeight () / 2 - 120 / 2 , supportsAlpha ,
91- color -> setData (color .argb ()), armorPreview , updatePreviewColor , previewReset );
92- window .setColor (getColor ());
93- parent .gui ().addWindow (window );
101+ parent .gui ().addWindow (new GuiColorWindow (parent .gui (), parent .getGuiWidth () / 2 - 160 / 2 , parent .getGuiHeight () / 2 - 120 / 2 , supportsAlpha ,
102+ getColor (), color -> setData (color .argb ()), armorPreview , updatePreviewColor , previewReset ));
94103 }
95104 }
96105}
0 commit comments