diff --git a/common/build.gradle b/common/build.gradle index e0e3b085..bbf54231 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -23,6 +23,9 @@ dependencies { modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:${rei_version}") { transitive = false } + modCompileOnly("appeng:appliedenergistics2-fabric:${appeng_version}") { + transitive = false + } // compile against the JEI API but do not include it at runtime modCompileOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}") modCompileOnly("mezz.jei:jei-${minecraft_version}-gui:${jei_version}") diff --git a/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java b/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java index 7a020414..9d8e44c5 100644 --- a/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java +++ b/common/src/main/java/org/embeddedt/modernfix/ModernFixClient.java @@ -11,6 +11,8 @@ import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.util.MemoryReserve; import net.minecraft.world.entity.Entity; +import org.embeddedt.modernfix.api.constants.IntegrationConstants; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.embeddedt.modernfix.core.ModernFixMixinPlugin; import org.embeddedt.modernfix.packet.EntityIDSyncPacket; import org.embeddedt.modernfix.platform.ModernFixPlatformHooks; @@ -22,6 +24,7 @@ import org.embeddedt.modernfix.world.IntegratedWatchdog; import java.lang.management.ManagementFactory; import java.lang.reflect.Field; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; public class ModernFixClient { public static long worldLoadStartTime; @@ -33,6 +36,11 @@ public class ModernFixClient { public String brandingString = null; + /** + * The list of loaded client integrations. + */ + public static List CLIENT_INTEGRATIONS = new CopyOnWriteArrayList<>(); + public ModernFixClient() { // clear reserve as it's not needed MemoryReserve.release(); @@ -41,6 +49,13 @@ public class ModernFixClient { } SearchTreeProviderRegistry.register(JEIBackedSearchTree.PROVIDER); SearchTreeProviderRegistry.register(REIBackedSearchTree.PROVIDER); + for(String className : ModernFixPlatformHooks.getCustomModOptions().get(IntegrationConstants.CLIENT_INTEGRATION_CLASS)) { + try { + CLIENT_INTEGRATIONS.add((ModernFixClientIntegration)Class.forName(className).getDeclaredConstructor().newInstance()); + } catch(ReflectiveOperationException | ClassCastException e) { + ModernFix.LOGGER.error("Could not instantiate integration {}", className, e); + } + } } public void resetWorldLoadStateMachine() { diff --git a/common/src/main/java/org/embeddedt/modernfix/api/constants/IntegrationConstants.java b/common/src/main/java/org/embeddedt/modernfix/api/constants/IntegrationConstants.java new file mode 100644 index 00000000..92a9a5e1 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/api/constants/IntegrationConstants.java @@ -0,0 +1,8 @@ +package org.embeddedt.modernfix.api.constants; + +public class IntegrationConstants { + public static final String INTEGRATIONS_KEY = "modernfix:integration"; + + public static final String CLIENT_INTEGRATION_CLASS = "client_entrypoint"; + public static final String INTEGRATION_CLASS = "entrypoint"; +} diff --git a/common/src/main/java/org/embeddedt/modernfix/api/entrypoint/ModernFixClientIntegration.java b/common/src/main/java/org/embeddedt/modernfix/api/entrypoint/ModernFixClientIntegration.java new file mode 100644 index 00000000..f5757766 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/api/entrypoint/ModernFixClientIntegration.java @@ -0,0 +1,49 @@ +package org.embeddedt.modernfix.api.entrypoint; + +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.resources.ResourceLocation; + + +/** + * Implement this interface in a mod class and add it to "modernfix:integration_v1" in your mod metadata file + * to integrate with ModernFix's features. + */ +public interface ModernFixClientIntegration { + /** + * Called when the dynamic resources status has changed during a model reload so mods know whether to run their + * normal codepath or the dynamic version. + * + * @param enabled whether dynamic resources is enabled + */ + default void onDynamicResourcesStatusChange(boolean enabled) { + } + + /** + * Called to allow mods to observe the loading of an unbaked model and either make changes to it or wrap it with their + * own instance. + * @param location the ResourceLocation of the model (this may be a ModelResourceLocation) + * @param originalModel the original model + * @param bakery the model bakery - do not touch internal fields as they probably don't behave the way you expect + * with dynamic resources on + * @return the model which should actually be loaded for this resource location + */ + default UnbakedModel onUnbakedModelLoad(ResourceLocation location, UnbakedModel originalModel, ModelBakery bakery) { + return originalModel; + } + + /** + * Called to allow mods to observe the loading of a baked model and either make changes to it or wrap it with their + * own instance. + * @param location the ResourceLocation of the model (this may be a ModelResourceLocation) + * @param originalModel the original model + * @param bakery the model bakery - do not touch internal fields as they probably don't behave the way you expect + * with dynamic resources on + * @return the model which should actually be loaded for this resource location + */ + default BakedModel onBakedModelLoad(ResourceLocation location, UnbakedModel baseModel, BakedModel originalModel, ModelState state, ModelBakery bakery) { + return originalModel; + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/api/helpers/ModelHelpers.java b/common/src/main/java/org/embeddedt/modernfix/api/helpers/ModelHelpers.java new file mode 100644 index 00000000..33535a14 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/api/helpers/ModelHelpers.java @@ -0,0 +1,55 @@ +package org.embeddedt.modernfix.api.helpers; + +import com.google.common.collect.ImmutableList; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.BlockModelRotation; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import org.embeddedt.modernfix.dynamicresources.ModelBakeryHelpers; +import org.embeddedt.modernfix.util.DynamicMap; + +import java.util.Map; +import java.util.Optional; +import java.util.function.BiFunction; + +@SuppressWarnings("unused") +public final class ModelHelpers { + /** + * Allows converting a ModelResourceLocation back into the corresponding BlockState(s). Try to avoid calling this + * multiple times if possible. + * @param location the location of the model + * @return a list of all blockstates related to the model + */ + public static ImmutableList getBlockStateForLocation(ModelResourceLocation location) { + Optional blockOpt = Registry.BLOCK.getOptional(new ResourceLocation(location.getNamespace(), location.getPath())); + if(blockOpt.isPresent()) + return ModelBakeryHelpers.getBlockStatesForMRL(blockOpt.get().getStateDefinition(), location); + else + return ImmutableList.of(); + } + + /** + * Allows converting a ModelResourceLocation back into the corresponding BlockState(s). Faster version of its + * companion function if and only if you know the corresponding Block already for some reason. + * @param definition the state definition for the Block + * @param location the location of the model + * @return a list of all blockstates related to the model + */ + public static ImmutableList getBlockStateForLocation(StateDefinition definition, ModelResourceLocation location) { + return ModelBakeryHelpers.getBlockStatesForMRL(definition, location); + } + + /** + * Compatibility helper for mods to use to get a map-like view of the model bakery. + * @param modelGetter the model getter function supplied by the integration class + * @return a fake map of the top-level models + */ + public static Map createFakeTopLevelMap(BiFunction modelGetter) { + return new DynamicMap<>(location -> modelGetter.apply(location, BlockModelRotation.X0_Y0)); + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java new file mode 100644 index 00000000..d6bc85b6 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java @@ -0,0 +1,46 @@ +package org.embeddedt.modernfix.common.mixin.perf.dynamic_resources.ae2; + +import appeng.core.AppEng; +import appeng.init.client.InitAutoRotatingModel; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelBakery; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.annotation.RequiresMod; +import org.spongepowered.asm.mixin.Final; +import net.minecraft.client.resources.model.*; +import net.minecraft.resources.ResourceLocation; +import org.embeddedt.modernfix.ModernFixClient; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Map; +import java.util.function.Function; + +@Mixin(InitAutoRotatingModel.class) +@RequiresMod("ae2") +@ClientOnlyMixin +public class RegistrationMixin { + @Shadow @Final private static Map> CUSTOMIZERS; + + @Inject(method = "init", at = @At("TAIL"), remap = false) + private static void doRegisterDynBake(CallbackInfo ci) { + ModernFixClient.CLIENT_INTEGRATIONS.add(new ModernFixClientIntegration() { + @Override + public BakedModel onBakedModelLoad(ResourceLocation location, UnbakedModel baseModel, BakedModel originalModel, ModelState state, ModelBakery bakery) { + if(location.getNamespace().equals(AppEng.MOD_ID)) { + BakedModel m = bakery.bake(ModelBakery.MISSING_MODEL_LOCATION, BlockModelRotation.X0_Y0); + if(originalModel == m) + return originalModel; + Function customizerFn = CUSTOMIZERS.get(location.getPath()); + if(customizerFn != null) + originalModel = customizerFn.apply(originalModel); + } + return originalModel; + } + }); + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java b/common/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java index 49b5c487..850db8f2 100644 --- a/common/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java +++ b/common/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java @@ -20,6 +20,8 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin { public static ModernFixMixinPlugin instance; public ModernFixMixinPlugin() { + /* invoke early to ensure it gets read on one thread */ + ModernFixPlatformHooks.getCustomModOptions(); boolean firstConfig = instance == null; if(firstConfig) { instance = this; diff --git a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 1d072c10..3f0c5a4b 100644 --- a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -183,8 +183,9 @@ public class ModernFixEarlyConfig { disableIfModPresent("mixin.bugfix.paper_chunk_patches", "c2me"); disableIfModPresent("mixin.perf.reuse_datapacks", "tac"); disableIfModPresent("mixin.launch.class_search_cache", "optifine"); + disableIfModPresent("mixin.perf.faster_texture_stitching", "optifine"); disableIfModPresent("mixin.perf.datapack_reload_exceptions", "cyanide"); - disableIfModPresent("mixin.perf.faster_texture_loading", "stitch"); + disableIfModPresent("mixin.perf.faster_texture_loading", "stitch", "optifine"); } private void disableIfModPresent(String configName, String... ids) { diff --git a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java index 8e31ff2c..927a0bb4 100644 --- a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java +++ b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java @@ -14,6 +14,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.level.block.state.BlockState; import org.apache.commons.lang3.tuple.Triple; +import org.embeddedt.modernfix.ModernFix; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -107,7 +108,12 @@ public class DynamicBakedModelProvider implements Map> handler) { throw new AssertionError(); } + + @ExpectPlatform + public static Multimap getCustomModOptions() { + throw new AssertionError(); + } } diff --git a/fabric/build.gradle b/fabric/build.gradle index 0a7f2f6c..3317c721 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -37,6 +37,7 @@ dependencies { modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } modImplementation(fabricApi.module("fabric-data-generation-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } modCompileOnly("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { transitive false } + modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}") { exclude group: 'net.fabricmc', module: 'fabric-loader' } // Remove the next line if you don't want to depend on the API // modApi "me.shedaniel:architectury-fabric:${rootProject.architectury_version}" diff --git a/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java b/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java index 598efce7..66a5d7ac 100644 --- a/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java +++ b/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java @@ -31,7 +31,9 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import org.apache.commons.lang3.tuple.Triple; import org.embeddedt.modernfix.ModernFix; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.embeddedt.modernfix.duck.IExtendedModelBakery; import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider; import org.embeddedt.modernfix.dynamicresources.ModelBakeryHelpers; @@ -46,6 +48,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -247,6 +250,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { "entity/chest", "item", "items", + "part", "pipe", "ropebridge" }; @@ -269,6 +273,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { return materialsSet; } + @Inject(method = "", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=textures")) + private void clearDummyModels(CallbackInfo ci) { + // discard unwrapped models + Predicate> isVanillaModel = entry -> entry.getValue() instanceof BlockModel || entry.getValue() instanceof MultiVariant || entry.getValue() instanceof MultiPart; + this.unbakedCache.entrySet().removeIf(isVanillaModel); + this.topLevelModels.entrySet().removeIf(isVanillaModel); + } + @Inject(method = "uploadTextures", at = @At(value = "FIELD", target = "Lnet/minecraft/client/resources/model/ModelBakery;topLevelModels:Ljava/util/Map;", ordinal = 0), cancellable = true) private void skipBake(TextureManager resourceManager, ProfilerFiller profiler, CallbackInfoReturnable cir) { profiler.pop(); @@ -290,10 +302,6 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { return super.put(key, value); } }; - // discard unwrapped models - Predicate> isVanillaModel = entry -> entry.getValue() instanceof BlockModel || entry.getValue() instanceof MultiVariant || entry.getValue() instanceof MultiPart; - this.unbakedCache.entrySet().removeIf(isVanillaModel); - this.topLevelModels.entrySet().removeIf(isVanillaModel); // bake indigo models Stopwatch watch = Stopwatch.createStarted(); this.topLevelModels.forEach((key, value) -> { @@ -331,6 +339,18 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { return unbakedCache.get(rl); } + @ModifyVariable(method = "cacheAndQueueDependencies", at = @At("HEAD"), argsOnly = true) + private UnbakedModel fireUnbakedEvent(UnbakedModel model, ResourceLocation location) { + for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) { + try { + model = integration.onUnbakedModelLoad(location, model, (ModelBakery)(Object)this); + } catch(RuntimeException e) { + ModernFix.LOGGER.error("Exception firing model load event for {}", location, e); + } + } + return model; + } + /** * @author embeddedt * @reason synchronize @@ -455,7 +475,13 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { ModernFix.LOGGER.error("Model {} returned null baked model", arg); ibakedmodel = bakedMissingModel; } - // TODO event + for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) { + try { + ibakedmodel = integration.onBakedModelLoad(arg, iunbakedmodel, ibakedmodel, arg2, (ModelBakery)(Object)this); + } catch(RuntimeException e) { + ModernFix.LOGGER.error("Exception encountered firing bake event for {}", arg, e); + } + } this.bakedCache.put(triple, ibakedmodel); cir.setReturnValue(ibakedmodel); } diff --git a/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java b/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java index f0aca911..8f786e3f 100644 --- a/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java +++ b/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java @@ -1,11 +1,15 @@ package org.embeddedt.modernfix.platform.fabric; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.metadata.CustomValue; +import net.fabricmc.loader.api.metadata.ModMetadata; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.commands.CommandSourceStack; @@ -14,6 +18,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; import org.embeddedt.modernfix.ModernFixFabric; +import org.embeddedt.modernfix.api.constants.IntegrationConstants; import org.objectweb.asm.tree.*; import java.nio.file.Path; @@ -82,4 +87,26 @@ public class ModernFixPlatformHooksImpl { public static void onServerCommandRegister(Consumer> handler) { CommandRegistrationCallback.EVENT.register((dispatcher, arg, env) -> handler.accept(dispatcher)); } + + private static Multimap modOptions; + public static Multimap getCustomModOptions() { + if(modOptions == null) { + modOptions = ArrayListMultimap.create(); + for (ModContainer container : FabricLoader.getInstance().getAllMods()) { + ModMetadata meta = container.getMetadata(); + if (meta.containsCustomValue(IntegrationConstants.INTEGRATIONS_KEY)) { + CustomValue integrations = meta.getCustomValue(IntegrationConstants.INTEGRATIONS_KEY); + if (integrations.getType() != CustomValue.CvType.OBJECT) { + continue; + } + for (Map.Entry entry : integrations.getAsObject()) { + if(entry.getValue().getType() != CustomValue.CvType.STRING) + continue; + modOptions.put(entry.getKey(), entry.getValue().getAsString()); + } + } + } + } + return modOptions; + } } diff --git a/forge/build.gradle b/forge/build.gradle index c9605c69..7085c5d7 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -45,7 +45,6 @@ dependencies { modCompileOnly("team.chisel.ctm:CTM:${ctm_version}") modCompileOnly("curse.maven:supermartijncore-454372:4455391") - modCompileOnly("appeng:appliedenergistics2-forge:12.9.4") modCompileOnly("vazkii.patchouli:Patchouli:1.19.2-77") common(project(path: ":common", configuration: "namedElements")) { transitive false } diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/dynamicresources/DynamicModelBakeEvent.java b/forge/src/main/java/org/embeddedt/modernfix/forge/dynamicresources/DynamicModelBakeEvent.java deleted file mode 100644 index d8e265c8..00000000 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/dynamicresources/DynamicModelBakeEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.embeddedt.modernfix.forge.dynamicresources; - -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.UnbakedModel; -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.eventbus.api.Event; - -/** - * Fired when a model is baked dynamically. Intended to be used as a replacement for ModelBakeEvent - * if mods want to replace a model. - *

- * Note that this event can fire many times for the same resource location, as models are unloaded - * if unused/under memory pressure. - */ -public class DynamicModelBakeEvent extends Event { - private final ResourceLocation location; - private BakedModel model; - private final UnbakedModel unbakedModel; - private final ModelBakery modelLoader; - public DynamicModelBakeEvent(ResourceLocation location, UnbakedModel unbakedModel, BakedModel model, ModelBakery loader) { - this.location = location; - this.model = model; - this.unbakedModel = unbakedModel; - this.modelLoader = loader; - } - - public ResourceLocation getLocation() { - return this.location; - } - - public BakedModel getModel() { - return this.model; - } - - public UnbakedModel getUnbakedModel() { - return this.unbakedModel; - } - - public ModelBakery getModelLoader() { - return this.modelLoader; - } - - public void setModel(BakedModel model) { - this.model = model; - } -} diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java index 36034991..82497471 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java @@ -27,16 +27,16 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.Property; import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.model.ExtendedBlockModelDeserializer; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.resource.DelegatingPackResources; import net.minecraftforge.resource.PathPackResources; import org.apache.commons.lang3.tuple.Triple; import org.embeddedt.modernfix.ModernFix; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.embeddedt.modernfix.duck.IExtendedModelBakery; import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; import org.embeddedt.modernfix.dynamicresources.ModelBakeryHelpers; import org.objectweb.asm.Opcodes; import org.slf4j.Logger; @@ -46,6 +46,7 @@ import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -92,6 +93,8 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { @Shadow @Nullable public abstract BakedModel bake(ResourceLocation arg, ModelState arg2, Function sprites); @Shadow @Final private static Logger LOGGER; + @Shadow @org.jetbrains.annotations.Nullable public abstract BakedModel bake(ResourceLocation location, ModelState transform); + private Cache, BakedModel> loadedBakedModels; private Cache loadedModels; @@ -221,6 +224,18 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { return unbakedCache.get(rl); } + @ModifyVariable(method = "cacheAndQueueDependencies", at = @At("HEAD"), argsOnly = true) + private UnbakedModel fireUnbakedEvent(UnbakedModel model, ResourceLocation location) { + for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) { + try { + model = integration.onUnbakedModelLoad(location, model, (ModelBakery)(Object)this); + } catch(RuntimeException e) { + ModernFix.LOGGER.error("Exception firing model load event for {}", location, e); + } + } + return model; + } + @Inject(method = "cacheAndQueueDependencies", at = @At("RETURN")) private void addToSmallLoadingCache(ResourceLocation location, UnbakedModel model, CallbackInfo ci) { smallLoadingCache.put(location, model); @@ -333,10 +348,15 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { } else ibakedmodel = iunbakedmodel.bake((ModelBakery) (Object) this, textureGetter, arg2, arg); } - DynamicModelBakeEvent event = new DynamicModelBakeEvent(arg, iunbakedmodel, ibakedmodel, (ModelBakery)(Object)this); - MinecraftForge.EVENT_BUS.post(event); - this.bakedCache.put(triple, event.getModel()); - cir.setReturnValue(event.getModel()); + for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) { + try { + ibakedmodel = integration.onBakedModelLoad(arg, iunbakedmodel, ibakedmodel, arg2, (ModelBakery)(Object)this); + } catch(RuntimeException e) { + ModernFix.LOGGER.error("Exception encountered firing bake event for {}", arg, e); + } + } + this.bakedCache.put(triple, ibakedmodel); + cir.setReturnValue(ibakedmodel); } } } diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java deleted file mode 100644 index a3954573..00000000 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ae2/RegistrationMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources.ae2; - -import appeng.core.AppEng; -import appeng.init.client.InitAutoRotatingModel; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraftforge.common.MinecraftForge; -import org.embeddedt.modernfix.annotation.ClientOnlyMixin; -import org.embeddedt.modernfix.annotation.RequiresMod; -import org.spongepowered.asm.mixin.Final; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Map; -import java.util.function.Function; - -@Mixin(InitAutoRotatingModel.class) -@RequiresMod("appliedenergistics2") -@ClientOnlyMixin -public class RegistrationMixin { - @Shadow @Final private static Map> CUSTOMIZERS; - @Inject(method = "init", at = @At("TAIL"), remap = false) - private static void doRegisterDynBake(CallbackInfo ci) { - MinecraftForge.EVENT_BUS.addListener(RegistrationMixin::onDynamicModelBake); - } - - private static void onDynamicModelBake(DynamicModelBakeEvent event) { - if (!event.getLocation().getNamespace().equals(AppEng.MOD_ID)) { - return; - } - BakedModel missing = event.getModelLoader().getBakedTopLevelModels().get(ModelBakery.MISSING_MODEL_LOCATION); - if(event.getModel() == missing) - return; - Function customizerFn = CUSTOMIZERS.get(event.getLocation().getPath()); - if(customizerFn != null) - event.setModel(customizerFn.apply(event.getModel())); - } -} diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/CTMPackReloadListenerMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/CTMPackReloadListenerMixin.java index 44fa59fc..02928406 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/CTMPackReloadListenerMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/CTMPackReloadListenerMixin.java @@ -3,24 +3,20 @@ package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources.ctm; import com.google.common.collect.ImmutableList; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelResourceLocation; -import net.minecraft.client.resources.model.MultiPartBakedModel; -import net.minecraft.client.resources.model.WeightedBakedModel; +import net.minecraft.client.resources.model.*; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.ChunkRenderTypeSet; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.registries.ForgeRegistries; import org.embeddedt.modernfix.ModernFix; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.annotation.RequiresMod; -import org.embeddedt.modernfix.duck.IExtendedModelBakery; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; +import org.embeddedt.modernfix.api.helpers.ModelHelpers; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -38,7 +34,7 @@ import java.util.function.Predicate; @Mixin(CTMPackReloadListener.class) @RequiresMod("ctm") @ClientOnlyMixin -public abstract class CTMPackReloadListenerMixin { +public abstract class CTMPackReloadListenerMixin implements ModernFixClientIntegration { /* caches the original render checks */ @Shadow @Final private static Map, Predicate> blockRenderChecks; @@ -52,7 +48,7 @@ public abstract class CTMPackReloadListenerMixin { @Inject(method = "", at = @At("RETURN")) private void onInit(CallbackInfo ci) { - MinecraftForge.EVENT_BUS.addListener(EventPriority.LOW, this::onModelBake); + ModernFixClient.CLIENT_INTEGRATIONS.add(this); } @Overwrite(remap = false) @@ -77,28 +73,32 @@ public abstract class CTMPackReloadListenerMixin { return override.test(type); } - private void onModelBake(DynamicModelBakeEvent event) { - if(!(event.getModel() instanceof AbstractCTMBakedModel || event.getModel() instanceof WeightedBakedModel || event.getModel() instanceof MultiPartBakedModel)) - return; + @Override + public BakedModel onBakedModelLoad(ResourceLocation location, UnbakedModel baseModel, BakedModel originalModel, ModelState modelState, ModelBakery bakery) { + if(!(location instanceof ModelResourceLocation)) + return originalModel; + if(!(originalModel instanceof AbstractCTMBakedModel || originalModel instanceof WeightedBakedModel || originalModel instanceof MultiPartBakedModel)) + return originalModel; /* we construct a new ResourceLocation because an MRL is coming in */ - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(event.getLocation().getNamespace(), event.getLocation().getPath())); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(location.getNamespace(), location.getPath())); Holder.Reference delegate = block != null ? ForgeRegistries.BLOCKS.getDelegateOrThrow(block) : null; if(block == null || block == Blocks.AIR || renderCheckOverrides.containsKey(delegate)) - return; + return originalModel; /* find all states that match this MRL */ ImmutableList allStates; try { - allStates = ((IExtendedModelBakery)(Object)event.getModelLoader()).getBlockStatesForMRL(block.getStateDefinition(), (ModelResourceLocation)event.getLocation()); + allStates = ModelHelpers.getBlockStateForLocation(block.getStateDefinition(), (ModelResourceLocation)location); } catch(RuntimeException e) { - ModernFix.LOGGER.error("Couldn't get state for MRL " + event.getLocation(), e); - return; + ModernFix.LOGGER.error("Couldn't get state for MRL " + location, e); + return originalModel; } for(BlockState state : allStates) { - Predicate newPredicate = this.getLayerCheck(state, event.getModel()); + Predicate newPredicate = this.getLayerCheck(state, originalModel); if(newPredicate != null) { renderCheckOverrides.put(delegate, newPredicate); - return; + return originalModel; } } + return originalModel; } } diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/TextureMetadataHandlerMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/TextureMetadataHandlerMixin.java index d932d9c8..7b96051f 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/TextureMetadataHandlerMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/TextureMetadataHandlerMixin.java @@ -1,15 +1,12 @@ package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources.ctm; import com.mojang.datafixers.util.Pair; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.Material; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.*; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.annotation.RequiresMod; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -29,13 +26,13 @@ import java.util.*; @Mixin(TextureMetadataHandler.class) @RequiresMod("ctm") @ClientOnlyMixin -public abstract class TextureMetadataHandlerMixin { +public abstract class TextureMetadataHandlerMixin implements ModernFixClientIntegration { @Shadow @Nonnull protected abstract BakedModel wrap(ResourceLocation loc, UnbakedModel model, BakedModel object, ModelBakery loader) throws IOException; @Inject(method = "", at = @At("RETURN")) private void subscribeDynamic(CallbackInfo ci) { - MinecraftForge.EVENT_BUS.addListener(this::onDynamicModelBake); + ModernFixClient.CLIENT_INTEGRATIONS.add(this); } @Redirect(method = "onModelBake", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/BakedModel;isCustomRenderer()Z")) @@ -43,10 +40,8 @@ public abstract class TextureMetadataHandlerMixin { return model == null || model.isCustomRenderer(); } - public void onDynamicModelBake(DynamicModelBakeEvent event) { - UnbakedModel rootModel = event.getUnbakedModel(); - BakedModel baked = event.getModel(); - ResourceLocation rl = event.getLocation(); + @Override + public BakedModel onBakedModelLoad(ResourceLocation rl, UnbakedModel rootModel, BakedModel baked, ModelState state, ModelBakery bakery) { if (!(baked instanceof AbstractCTMBakedModel) && !baked.isCustomRenderer()) { Deque dependencies = new ArrayDeque<>(); Set seenModels = new HashSet<>(); @@ -59,12 +54,12 @@ public abstract class TextureMetadataHandlerMixin { ResourceLocation dep = dependencies.pop(); UnbakedModel model; try { - model = dep == rl ? rootModel : event.getModelLoader().getModel(dep); + model = dep == rl ? rootModel : bakery.getModel(dep); } catch (Exception e) { continue; } - Collection textures = model.getMaterials(event.getModelLoader()::getModel, errors); + Collection textures = model.getMaterials(bakery::getModel, errors); Collection newDependencies = model.getDependencies(); for (Material tex : textures) { IMetadataSectionCTM meta = null; @@ -86,12 +81,13 @@ public abstract class TextureMetadataHandlerMixin { } if (shouldWrap) { try { - event.setModel(wrap(rl, rootModel, baked, event.getModelLoader())); + baked = wrap(rl, rootModel, baked, bakery); dependencies.clear(); } catch (IOException e) { CTM.logger.error("Could not wrap model " + rl + ". Aborting...", e); } } } + return baked; } } diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/rs/ClientSetupMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/rs/ClientSetupMixin.java index d6704ce2..f7674d06 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/rs/ClientSetupMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/rs/ClientSetupMixin.java @@ -2,12 +2,12 @@ package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources.rs; import com.refinedmods.refinedstorage.render.BakedModelOverrideRegistry; import com.refinedmods.refinedstorage.setup.ClientSetup; -import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.client.resources.model.*; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.annotation.RequiresMod; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,20 +15,24 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + @Mixin(ClientSetup.class) @RequiresMod("refinedstorage") @ClientOnlyMixin public class ClientSetupMixin { @Shadow @Final private static BakedModelOverrideRegistry BAKED_MODEL_OVERRIDE_REGISTRY; - @Inject(method = "onClientSetup", at = @At("RETURN"), remap = false) - private static void addDynamicListener(CallbackInfo ci) { - MinecraftForge.EVENT_BUS.addListener(ClientSetupMixin::onDynamicModelBake); - } - - private static void onDynamicModelBake(DynamicModelBakeEvent event) { - BakedModelOverrideRegistry.BakedModelOverrideFactory factory = BAKED_MODEL_OVERRIDE_REGISTRY.get(event.getLocation() instanceof ModelResourceLocation ? new ResourceLocation(event.getLocation().getNamespace(), event.getLocation().getPath()) : event.getLocation()); - if(factory != null) - event.setModel(factory.create(event.getModel(), event.getModelLoader().getBakedTopLevelModels())); + @Inject(method = "", at = @At("RETURN")) + private void addDynamicListener(CallbackInfo ci) { + ModernFixClient.CLIENT_INTEGRATIONS.add(new ModernFixClientIntegration() { + @Override + public BakedModel onBakedModelLoad(ResourceLocation location, UnbakedModel baseModel, BakedModel originalModel, ModelState state, ModelBakery bakery) { + BakedModelOverrideRegistry.BakedModelOverrideFactory factory = BAKED_MODEL_OVERRIDE_REGISTRY.get(location instanceof ModelResourceLocation ? new ResourceLocation(location.getNamespace(), location.getPath()) : location); + if(factory != null) + return factory.create(originalModel, bakery.getBakedTopLevelModels()); + else + return originalModel; + } + }); } } diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/supermartijncore/ClientRegistrationHandlerMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/supermartijncore/ClientRegistrationHandlerMixin.java index 682484f1..e4cc3781 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/supermartijncore/ClientRegistrationHandlerMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/supermartijncore/ClientRegistrationHandlerMixin.java @@ -4,12 +4,14 @@ import com.supermartijn642.core.registry.ClientRegistrationHandler; import com.supermartijn642.core.util.Pair; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import org.embeddedt.modernfix.ModernFixClient; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.annotation.RequiresMod; -import org.embeddedt.modernfix.forge.dynamicresources.DynamicModelBakeEvent; +import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -48,13 +50,15 @@ public class ClientRegistrationHandlerMixin { @Inject(method = "", at = @At("RETURN")) private void registerDynBake(String modid, CallbackInfo ci) { - MinecraftForge.EVENT_BUS.addListener(this::onDynamicModelBake); - } - - @SubscribeEvent - public void onDynamicModelBake(DynamicModelBakeEvent event) { - Function replacer = modelOverwritesByLocation.get(event.getLocation()); - if(replacer != null) - event.setModel(replacer.apply(event.getModel())); + ModernFixClient.CLIENT_INTEGRATIONS.add(new ModernFixClientIntegration() { + @Override + public BakedModel onBakedModelLoad(ResourceLocation location, UnbakedModel baseModel, BakedModel originalModel, ModelState state, ModelBakery bakery) { + Function replacer = modelOverwritesByLocation.get(location); + if(replacer != null) + return replacer.apply(originalModel); + else + return originalModel; + } + }); } } diff --git a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java index b65a6d74..25174ffb 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java +++ b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java @@ -1,5 +1,7 @@ package org.embeddedt.modernfix.platform.forge; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.brigadier.CommandDispatcher; import net.minecraft.client.renderer.texture.TextureAtlas; @@ -20,7 +22,9 @@ import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.server.ServerLifecycleHooks; +import net.minecraftforge.fml.loading.moddiscovery.ModInfo; import org.embeddedt.modernfix.core.ModernFixMixinPlugin; +import org.embeddedt.modernfix.api.constants.IntegrationConstants; import org.embeddedt.modernfix.forge.classloading.FastAccessTransformerList; import org.embeddedt.modernfix.forge.packet.PacketHandler; import org.embeddedt.modernfix.util.DummyList; @@ -33,6 +37,7 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.nio.file.Path; +import java.util.Map; import java.util.function.Consumer; public class ModernFixPlatformHooksImpl { @@ -145,4 +150,24 @@ public class ModernFixPlatformHooksImpl { handler.accept(event.getDispatcher()); }); } + + private static Multimap modOptions; + public static Multimap getCustomModOptions() { + if(modOptions == null) { + modOptions = ArrayListMultimap.create(); + for (ModInfo meta : LoadingModList.get().getMods()) { + meta.getConfigElement(IntegrationConstants.INTEGRATIONS_KEY).ifPresent(optionsObj -> { + if(optionsObj instanceof Map) { + Map options = (Map)optionsObj; + options.forEach((key, value) -> { + if(key instanceof String && value instanceof String) { + modOptions.put((String)key, (String)value); + } + }); + } + }); + } + } + return modOptions; + } } diff --git a/gradle.properties b/gradle.properties index ef7b1c68..cfb24271 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,3 +17,4 @@ fabric_loader_version=0.14.18 fabric_api_version=0.76.0+1.19.2 modmenu_version=4.1.2 +appeng_version=12.9.3