11package moe .caramel .chameleon .util ;
22
3+ import static java .util .Map .entry ;
4+ import static net .minecraft .resources .ResourceLocation .withDefaultNamespace ;
35import com .mojang .blaze3d .platform .NativeImage ;
4- import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
56import it .unimi .dsi .fastutil .objects .ObjectOpenHashSet ;
67import net .minecraft .client .Minecraft ;
78import net .minecraft .core .RegistryAccess ;
@@ -28,23 +29,25 @@ public final class ModConfig extends Settings<ModConfig> {
2829
2930 private static final Path MOD_CONFIG = new File ("./config/caramel.chameleon.properties" ).toPath ();
3031 private static final int CURRENT_CONFIG_VERSION = 1 ;
31- public static final ResourceLocation ORIGINAL_MAC_ICON = ResourceLocation .withDefaultNamespace ("icons/minecraft.icns" );
32- public static final ResourceLocation ORIGINAL_WIN_ICON = ResourceLocation .withDefaultNamespace ("icons/icon_128x128.png" );
33- public static final Map <ResourceLocation , String []> VANILLA_ICON_SET = new Object2ObjectOpenHashMap <>();
34- static {
35- VANILLA_ICON_SET .put (ORIGINAL_MAC_ICON , new String []{ "icons" , "minecraft.icns" });
36- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("icons/icon_16x16.png" ), new String []{ "icons" , "icon_16x16.png" });
37- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("icons/icon_32x32.png" ), new String []{ "icons" , "icon_32x32.png" });
38- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("icons/icon_48x48.png" ), new String []{ "icons" , "icon_48x48.png" });
39- VANILLA_ICON_SET .put (ORIGINAL_WIN_ICON , new String []{ "icons" , "icon_128x128.png" });
40- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("icons/icon_256x256.png" ), new String []{ "icons" , "icon_256x256.png" });
41- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("snapshot/icons/icon_16x16.png" ), new String []{ "icons" , "snapshot" , "icon_16x16.png" });
42- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("snapshot/icons/icon_32x32.png" ), new String []{ "icons" , "snapshot" , "icon_32x32.png" });
43- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("snapshot/icons/icon_48x48.png" ), new String []{ "icons" , "snapshot" , "icon_48x48.png" });
44- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("snapshot/icons/icon_128x128.png" ), new String []{ "icons" , "snapshot" , "icon_128x128.png" });
45- VANILLA_ICON_SET .put (ResourceLocation .withDefaultNamespace ("snapshot/icons/icon_256x256.png" ), new String []{ "icons" , "snapshot" , "icon_256x256.png" });
46- }
47- public static final Function <Minecraft , Set <ResourceLocation >> GET_ICON_SET = client -> {
32+
33+ //<editor-fold desc="Icon registry" defaultstate="collapsed">
34+ public static final ResourceLocation ORIGINAL_MAC_ICON = withDefaultNamespace ("icons/minecraft.icns" );
35+ public static final ResourceLocation ORIGINAL_WIN_ICON = withDefaultNamespace ("icons/icon_128x128.png" );
36+ public static final Map <ResourceLocation , String []> VANILLA_ICON_SET = Map .ofEntries (
37+ entry (ORIGINAL_MAC_ICON , new String []{"icons" , "minecraft.icns" }),
38+ entry (withDefaultNamespace ("icons/icon_16x16.png" ), new String []{ "icons" , "icon_16x16.png" }),
39+ entry (withDefaultNamespace ("icons/icon_32x32.png" ), new String []{ "icons" , "icon_32x32.png" }),
40+ entry (withDefaultNamespace ("icons/icon_48x48.png" ), new String []{ "icons" , "icon_48x48.png" }),
41+ entry (ORIGINAL_WIN_ICON , new String []{ "icons" , "icon_128x128.png" }),
42+ entry (withDefaultNamespace ("icons/icon_256x256.png" ), new String []{ "icons" , "icon_256x256.png" }),
43+ entry (withDefaultNamespace ("snapshot/icons/icon_16x16.png" ), new String []{ "icons" , "snapshot" , "icon_16x16.png" }),
44+ entry (withDefaultNamespace ("snapshot/icons/icon_32x32.png" ), new String []{ "icons" , "snapshot" , "icon_32x32.png" }),
45+ entry (withDefaultNamespace ("snapshot/icons/icon_48x48.png" ), new String []{ "icons" , "snapshot" , "icon_48x48.png" }),
46+ entry (withDefaultNamespace ("snapshot/icons/icon_128x128.png" ), new String []{ "icons" , "snapshot" , "icon_128x128.png" }),
47+ entry (withDefaultNamespace ("snapshot/icons/icon_256x256.png" ), new String []{ "icons" , "snapshot" , "icon_256x256.png" })
48+ );
49+
50+ public static final Function <Minecraft , Set <ResourceLocation >> GET_ICON_SET = (client ) -> {
4851 final Set <ResourceLocation > iconSet = new ObjectOpenHashSet <>();
4952 client .getResourceManager ().listResources ("icons" , resource -> {
5053 if (resource != null ) {
@@ -56,49 +59,33 @@ public final class ModConfig extends Settings<ModConfig> {
5659 iconSet .addAll (VANILLA_ICON_SET .keySet ());
5760 return iconSet ;
5861 };
62+ //</editor-fold>
5963
60- /* ======================================== */
64+ //<editor-fold desc="Instance manager" defaultstate="collapsed">
6165 private static ModConfig instance ;
6266
63- /**
64- * Get Mod config instance.
65- * @return Mod config instance
66- */
6767 public static ModConfig getInstance () {
6868 if (instance == null ) {
6969 instance = new ModConfig ();
7070 }
7171
7272 return instance ;
7373 }
74- /* ======================================== */
75-
74+ //</editor-fold>
7675
77- /* ======================================== */
76+ //<editor-fold desc="Instance" defaultstate="collapsed">
7877 public final Settings <ModConfig >.MutableValue <Integer > configVersion ;
7978 public final Settings <ModConfig >.MutableValue <ResourceLocation > iconLocation ;
8079
81- /**
82- * Mod config constructor
83- */
8480 private ModConfig () {
8581 this (Settings .loadFromFile (MOD_CONFIG ));
8682 }
8783
88- /**
89- * Mod config constructor
90- */
9184 private ModConfig (final Properties properties ) {
9285 super (properties );
9386 this .configVersion = this .getMutable (
9487 "config-version" ,
95- s -> {
96- if (s == null ) {
97- return 0 ;
98- } else {
99- return Integer .parseInt (s );
100- }
101- },
88+ s -> (s == null ) ? 0 : Integer .parseInt (s ),
10289 ModConfig .CURRENT_CONFIG_VERSION
10390 );
10491 this .iconLocation = this .getMutable (
@@ -107,23 +94,16 @@ private ModConfig(final Properties properties) {
10794 (Minecraft .ON_OSX ? ORIGINAL_MAC_ICON : ORIGINAL_WIN_ICON )
10895 );
10996 }
110- /* ======================================== */
11197
11298 @ Override
11399 protected @ NotNull ModConfig reload (final RegistryAccess registryAccess , final Properties properties ) {
114100 instance = new ModConfig (properties );
115101 instance .store (MOD_CONFIG );
116102 return getInstance ();
117103 }
104+ //</editor-fold>
118105
119- /* ======================================== */
120- /**
121- * Apply and save icon setting.
122- *
123- * @param client Minecraft object
124- * @param icon Icon Resource location
125- * @throws IOException InputStream open failed
126- */
106+ //<editor-fold desc="Icon applicator" defaultstate="collapsed">
127107 public static void changeIcon (final Minecraft client , final ResourceLocation icon ) throws IOException {
128108 final String [] vanillaPath = ModConfig .VANILLA_ICON_SET .get (icon );
129109 final IoSupplier <InputStream > iconSupplier ;
@@ -140,13 +120,6 @@ public static void changeIcon(final Minecraft client, final ResourceLocation ico
140120 ModConfig .getInstance ().iconLocation .update (null , icon );
141121 }
142122
143- /**
144- * Change the icon in Windows OS.
145- *
146- * @param client Minecraft object
147- * @param icon Icon Resource location
148- * @throws IOException InputStream open failed
149- */
150123 public static void setWindowsIcon (final Minecraft client , final IoSupplier <InputStream > icon ) throws IOException {
151124 ByteBuffer value = null ;
152125
@@ -157,7 +130,7 @@ public static void setWindowsIcon(final Minecraft client, final IoSupplier<Input
157130 final GLFWImage .Buffer images = GLFWImage .malloc (1 , stack );
158131
159132 value = MemoryUtil .memAlloc (image .getWidth () * image .getHeight () * 4 );
160- value .asIntBuffer ().put (image .getPixelsRGBA ());
133+ value .asIntBuffer ().put (image .getPixelsABGR ());
161134 images .position (0 );
162135 images .width (image .getWidth ());
163136 images .height (image .getHeight ());
@@ -170,5 +143,5 @@ public static void setWindowsIcon(final Minecraft client, final IoSupplier<Input
170143 }
171144 }
172145 }
173- /* ======================================== */
146+ //</editor-fold>
174147}
0 commit comments