Cache model dependencies and materials

This commit is contained in:
embeddedt 2023-01-29 22:24:12 -05:00
parent 72def15ac6
commit fcc6abe3b7
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
4 changed files with 66 additions and 1 deletions

View File

@ -40,6 +40,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.deduplicate_location", true);
this.addMixinRule("perf.cache_blockstate_cache_arrays", true);
this.addMixinRule("perf.faster_baking", true);
this.addMixinRule("perf.cache_model_materials", true);
/* Keep this off if JEI isn't installed to prevent breaking vanilla gameplay */
this.addMixinRule("perf.blast_search_trees", FMLLoader.getLoadingModList().getModFileById("jei") != null);
this.addMixinRule("safety", true);

View File

@ -0,0 +1,26 @@
package org.embeddedt.modernfix.mixin.perf.cache_model_materials;
import net.minecraft.client.renderer.model.multipart.Multipart;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Collection;
@Mixin(Multipart.class)
public class MultipartMixin {
private Collection<ResourceLocation> dependencyCache = null;
@Inject(method = "getDependencies", at = @At("HEAD"), cancellable = true)
private void useDependencyCache(CallbackInfoReturnable<Collection<ResourceLocation>> cir) {
if(dependencyCache != null)
cir.setReturnValue(dependencyCache);
}
@Inject(method = "getDependencies", at = @At("RETURN"))
private void storeDependencyCache(CallbackInfoReturnable<Collection<ResourceLocation>> cir) {
if(dependencyCache == null)
dependencyCache = cir.getReturnValue();
}
}

View File

@ -0,0 +1,36 @@
package org.embeddedt.modernfix.mixin.perf.cache_model_materials;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.model.BlockModel;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.client.renderer.model.VariantList;
import net.minecraft.client.renderer.model.multipart.Multipart;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
@Mixin(value = {VariantList.class, Multipart.class, BlockModel.class})
public class VanillaModelMixin {
private Collection<RenderMaterial> materialsCache = null;
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
private void useCachedMaterials(Function<ResourceLocation, IUnbakedModel> pModelGetter, Set<Pair<String, String>> pMissingTextureErrors, CallbackInfoReturnable<Collection<RenderMaterial>> cir) {
if(materialsCache != null) {
cir.setReturnValue(materialsCache);
}
}
@Inject(method = "getMaterials", at = @At("RETURN"))
private void storeCachedMaterials(Function<ResourceLocation, IUnbakedModel> pModelGetter, Set<Pair<String, String>> pMissingTextureErrors, CallbackInfoReturnable<Collection<RenderMaterial>> cir) {
if(materialsCache == null)
materialsCache = Collections.unmodifiableCollection(cir.getReturnValue());
}
}

View File

@ -49,7 +49,9 @@
"perf.flatten_model_predicates.PropertyValueConditionMixin",
"perf.blast_search_trees.MinecraftMixin",
"perf.blast_search_trees.IngredientFilterInvoker",
"perf.faster_baking.ModelBakeryMixin"
"perf.faster_baking.ModelBakeryMixin",
"perf.cache_model_materials.VanillaModelMixin",
"perf.cache_model_materials.MultipartMixin"
],
"injectors": {
"defaultRequire": 1