From de6fb94562c232f8af7cc2c61ec264ad5e7de547 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 9 May 2023 18:24:51 -0400 Subject: [PATCH] Remove Mixin Config from Client and create seperate ConfigMixin for loading Mixins Earlier --- .../java/noppes/npcs/config/ConfigClient.java | 15 ------ .../java/noppes/npcs/config/ConfigMixin.java | 54 +++++++++++++++++++ .../npcs/mixin/CustomNPCsMixinPlugin.java | 26 ++++++--- 3 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 src/main/java/noppes/npcs/config/ConfigMixin.java diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index 665abb982..675395d12 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -31,12 +31,6 @@ public class ConfigClient public static Property FontSizeProperty; public static int FontSize = 18; - public static Property EntityRendererMixinProperty; - public static boolean EntityRendererMixin = true; - - public static Property AnimationMixinProperty; - public static boolean AnimationMixin = true; - /** * Questing Properties **/ @@ -70,12 +64,6 @@ public class ConfigClient FontSizeProperty = config.get(VISUAL, "Font Size", 18, "Font size for custom fonts (doesn't work with minecrafts font)"); FontSize = FontSizeProperty.getInt(18); - EntityRendererMixinProperty = config.get(VISUAL, "Entity Render Mixin", true, "Enables Overlay Mixins for Conflicts relating to Optifine or other Skin Renderers. If crashes occur, please disable."); - EntityRendererMixin = EntityRendererMixinProperty.getBoolean(true); - - AnimationMixinProperty = config.get(VISUAL, "Animation Mixin", true, "Enables mixins for the ModelRenderer and RenderPlayer classes, allowing for additional animation functionality in the API. If crashes or visual errors occur, please disable."); - AnimationMixin = AnimationMixinProperty.getBoolean(true); - // Questing TrackingInfoAlignmentProperty = config.get(QUESTING, "Tracking Info Alignment", 3, "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3"); TrackingInfoAlignment = TrackingInfoAlignmentProperty.getInt(3); @@ -100,9 +88,6 @@ public class ConfigClient FontSize = LegacyConfig.FontSize; FontSizeProperty.set(FontSize); - EntityRendererMixin = LegacyConfig.EntityRendererMixin; - EntityRendererMixinProperty.set(EntityRendererMixin); - TrackingInfoAlignment = LegacyConfig.TrackingInfoAlignment; TrackingInfoAlignmentProperty.set(TrackingInfoAlignment); diff --git a/src/main/java/noppes/npcs/config/ConfigMixin.java b/src/main/java/noppes/npcs/config/ConfigMixin.java new file mode 100644 index 000000000..08dd65063 --- /dev/null +++ b/src/main/java/noppes/npcs/config/ConfigMixin.java @@ -0,0 +1,54 @@ +package noppes.npcs.config; + +import cpw.mods.fml.common.FMLLog; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; +import org.apache.logging.log4j.Level; + +import java.io.File; + +public class ConfigMixin +{ + public static Configuration config; + + public final static String CLIENT = "CLIENT"; + public final static String GENERAL = "GENERAL"; + + /** + * General Properties + **/ + public static Property EntityRendererMixinProperty; + public static boolean EntityRendererMixin = true; + + public static Property AnimationMixinProperty; + public static boolean AnimationMixin = true; + + public static void init(File configFile) + { + config = new Configuration(configFile); + + try + { + config.load(); + + EntityRendererMixinProperty = config.get(CLIENT, "Entity Render Mixin", true, "Enables Overlay Mixins for Conflicts relating to Optifine or other Skin Renderers. If crashes occur, please disable."); + EntityRendererMixin = EntityRendererMixinProperty.getBoolean(true); + + AnimationMixinProperty = config.get(CLIENT, "Animation Mixin", true, "Enables mixins for the ModelRenderer and RenderPlayer classes, allowing for additional animation functionality in the API. If crashes or visual errors occur, please disable."); + AnimationMixin = AnimationMixinProperty.getBoolean(true); + + } + catch (Exception e) + { + FMLLog.log(Level.ERROR, e, "CNPC+ has had a problem loading its mixin configuration"); + } + finally + { + if (config.hasChanged()) { + config.save(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java b/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java index afd2c963a..b00fd404d 100644 --- a/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java +++ b/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java @@ -1,10 +1,14 @@ package noppes.npcs.mixin; +import cpw.mods.fml.relauncher.FMLLaunchHandler; import noppes.npcs.config.ConfigClient; +import noppes.npcs.config.ConfigMixin; import org.spongepowered.asm.lib.tree.ClassNode; +import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -32,13 +36,23 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin { @Override public List getMixins() { + + // Load Mixin Config + String configPath = "config" + File.separator + "CustomNpcPlus" + File.separator; + ConfigMixin.init(new File(configPath + "mixin.cfg")); + boolean client = FMLLaunchHandler.side().isClient(); + List mixins = new ArrayList<>(); - if (ConfigClient.EntityRendererMixin){ - mixins.add("MixinEntityRenderer"); - } - if (ConfigClient.AnimationMixin) { - mixins.add("MixinModelRenderer"); - mixins.add("MixinRenderPlayer"); + + // Client Only Mixins + if(client){ + if (ConfigMixin.EntityRendererMixin){ + mixins.add("MixinEntityRenderer"); + } + if (ConfigMixin.AnimationMixin) { + mixins.add("MixinModelRenderer"); + mixins.add("MixinRenderPlayer"); + } } return mixins; }