diff --git a/build.gradle b/build.gradle index 5034aa48..3ca6a2ab 100644 --- a/build.gradle +++ b/build.gradle @@ -148,6 +148,8 @@ dependencies { runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}")// core runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")// Mekanism: Generators runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:tools")// Mekanism: Tools + + runtimeOnly fg.deobf("curse.maven:betterfoliage-470013:3396105") } compileOnly fg.deobf("curse.maven:refinedstorage-243076:3807951") diff --git a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixConfig.java b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixConfig.java index 58a36f5b..98e720e7 100644 --- a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixConfig.java +++ b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixConfig.java @@ -27,6 +27,8 @@ public class ModernFixConfig { public static ForgeConfigSpec.BooleanValue REBUILD_BLOCKSTATES_ASYNC; + public static ForgeConfigSpec.ConfigValue> MODELS_TO_BAKE; + public static Set jeiPluginBlacklist; static { @@ -41,6 +43,9 @@ public class ModernFixConfig { REBUILD_BLOCKSTATES_ASYNC = COMMON_BUILDER .comment("Rebuild blockstate cache asynchronously. Should work with most mods, but can be disabled.") .define("rebuild_blockstate_cache_async", true); + MODELS_TO_BAKE = COMMON_BUILDER + .comment("List of additional mod IDs for which models should be baked at resource reload time") + .defineList("models_to_bake_early", Collections.emptyList(), o -> o instanceof String); } static { diff --git a/src/main/java/org/embeddedt/modernfix/mixin/perf/faster_baking/ModelBakeryMixin.java b/src/main/java/org/embeddedt/modernfix/mixin/perf/faster_baking/ModelBakeryMixin.java index 075d6e86..b004ccb2 100644 --- a/src/main/java/org/embeddedt/modernfix/mixin/perf/faster_baking/ModelBakeryMixin.java +++ b/src/main/java/org/embeddedt/modernfix/mixin/perf/faster_baking/ModelBakeryMixin.java @@ -1,5 +1,6 @@ package org.embeddedt.modernfix.mixin.perf.faster_baking; +import com.google.common.collect.ImmutableSet; import com.mojang.datafixers.util.Pair; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.*; @@ -18,6 +19,7 @@ import org.apache.commons.lang3.tuple.Triple; import org.apache.logging.log4j.Logger; import org.embeddedt.modernfix.ModernFix; import org.embeddedt.modernfix.ModernFixClient; +import org.embeddedt.modernfix.core.config.ModernFixConfig; import org.embeddedt.modernfix.duck.IExtendedModelBakery; import org.embeddedt.modernfix.models.LazyBakedModel; import org.spongepowered.asm.mixin.*; @@ -52,6 +54,21 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { @Shadow @Final private Map, IBakedModel> bakedCache; + @Shadow @Final private Map unbakedCache; + + private IBakedModel bakeIfPossible(ResourceLocation p_229350_1_) { + IBakedModel ibakedmodel = null; + + try { + ibakedmodel = this.bake(p_229350_1_, ModelRotation.X0_Y0); + } catch (Exception exception) { + exception.printStackTrace(); + LOGGER.warn("Unable to bake model: '{}': {}", p_229350_1_, exception); + } + + return ibakedmodel; + } + @Inject(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;pop()V")) private void bakeModels(IProfiler pProfiler, int p_i226056_4_, CallbackInfo ci) { pProfiler.popPush("atlas"); @@ -67,21 +84,32 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery { this.atlasSet = new SpriteMap(this.atlasPreparations.values().stream().map(Pair::getFirst).collect(Collectors.toList())); IBakedModel missingModel = this.bake(MISSING_MODEL_LOCATION, ModelRotation.X0_Y0); this.bakedTopLevelModels.put(MISSING_MODEL_LOCATION, missingModel); + Set incompatibleLazyBakedModels = ImmutableSet.builder() + .addAll(ModernFixConfig.MODELS_TO_BAKE.get()) + .add("betterfoliage") + .build(); + /* First, bake any incompatible models ahead of time (for mods that have custom models) */ + this.unbakedCache.keySet().forEach(location -> { + if(incompatibleLazyBakedModels.contains(location.getNamespace())) { + this.bakeIfPossible(location); + } + }); + /* Then store them as top-level models if needed, and set up the lazy models */ this.topLevelModels.keySet().forEach((p_229350_1_) -> { - this.bakedTopLevelModels.put(p_229350_1_, new LazyBakedModel(() -> { - synchronized (this.bakedCache) { - IBakedModel ibakedmodel = null; + if(incompatibleLazyBakedModels.contains(p_229350_1_.getNamespace())) { + IBakedModel model = this.bakeIfPossible(p_229350_1_); + if(model != null) + this.bakedTopLevelModels.put(p_229350_1_, model); + } else { + this.bakedTopLevelModels.put(p_229350_1_, new LazyBakedModel(() -> { + synchronized (this.bakedCache) { + IBakedModel ibakedmodel = this.bakeIfPossible(p_229350_1_); - try { - ibakedmodel = this.bake(p_229350_1_, ModelRotation.X0_Y0); - } catch (Exception exception) { - exception.printStackTrace(); - LOGGER.warn("Unable to bake model: '{}': {}", p_229350_1_, exception); + return ibakedmodel != null ? ibakedmodel : missingModel; } + })); + } - return ibakedmodel != null ? ibakedmodel : missingModel; - } - })); }); }