Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
e9b52cdd55
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.embeddedt.modernfix.duck;
|
||||||
|
|
||||||
|
public interface ICachedMaterialsModel {
|
||||||
|
public void clearMaterialsCache();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package org.embeddedt.modernfix.mixin.perf.cache_model_materials;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.util.Either;
|
||||||
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
|
import net.minecraft.client.resources.model.Material;
|
||||||
|
import org.embeddedt.modernfix.duck.ICachedMaterialsModel;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
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.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mixin(BlockModel.class)
|
||||||
|
public class BlockModelMixin {
|
||||||
|
@Shadow @Final @Mutable public Map<String, Either<Material, String>> textureMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author embeddedt
|
||||||
|
* @reason detect changes to the texture map, and clear the material cache as needed
|
||||||
|
*/
|
||||||
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
|
private void useTrackingTextureMap(CallbackInfo ci) {
|
||||||
|
Map<String, Either<Material, String>> backingMap = this.textureMap;
|
||||||
|
ICachedMaterialsModel cacheHolder = (ICachedMaterialsModel)this;
|
||||||
|
this.textureMap = new Map<String, Either<Material, String>>() {
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return backingMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return backingMap.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(Object o) {
|
||||||
|
return backingMap.containsKey(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(Object o) {
|
||||||
|
return backingMap.containsValue(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Either<Material, String> get(Object o) {
|
||||||
|
return backingMap.get(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Either<Material, String> put(String s, Either<Material, String> materialStringEither) {
|
||||||
|
Either<Material, String> old = backingMap.put(s, materialStringEither);
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Either<Material, String> remove(Object o) {
|
||||||
|
Either<Material, String> e = backingMap.remove(o);
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(@NotNull Map<? extends String, ? extends Either<Material, String>> map) {
|
||||||
|
backingMap.putAll(map);
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
backingMap.clear();
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<String> keySet() {
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
return backingMap.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<Either<Material, String>> values() {
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
return backingMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<Entry<String, Either<Material, String>>> entrySet() {
|
||||||
|
cacheHolder.clearMaterialsCache();
|
||||||
|
return backingMap.entrySet();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import net.minecraft.client.resources.model.Material;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
|
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import org.embeddedt.modernfix.duck.ICachedMaterialsModel;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
|
@ -18,7 +19,7 @@ import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Mixin(value = {MultiVariant.class, MultiPart.class, BlockModel.class})
|
@Mixin(value = {MultiVariant.class, MultiPart.class, BlockModel.class})
|
||||||
public class VanillaModelMixin {
|
public class VanillaModelMixin implements ICachedMaterialsModel {
|
||||||
private Collection<Material> materialsCache = null;
|
private Collection<Material> materialsCache = null;
|
||||||
|
|
||||||
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
|
||||||
|
|
@ -33,4 +34,9 @@ public class VanillaModelMixin {
|
||||||
if(materialsCache == null)
|
if(materialsCache == null)
|
||||||
materialsCache = Collections.unmodifiableCollection(cir.getReturnValue());
|
materialsCache = Collections.unmodifiableCollection(cir.getReturnValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearMaterialsCache() {
|
||||||
|
materialsCache = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@
|
||||||
"perf.blast_search_trees.MinecraftMixin",
|
"perf.blast_search_trees.MinecraftMixin",
|
||||||
"perf.blast_search_trees.IngredientFilterInvoker",
|
"perf.blast_search_trees.IngredientFilterInvoker",
|
||||||
"perf.cache_model_materials.VanillaModelMixin",
|
"perf.cache_model_materials.VanillaModelMixin",
|
||||||
|
"perf.cache_model_materials.BlockModelMixin",
|
||||||
"perf.cache_model_materials.MultipartMixin",
|
"perf.cache_model_materials.MultipartMixin",
|
||||||
"perf.faster_texture_stitching.StitcherMixin",
|
"perf.faster_texture_stitching.StitcherMixin",
|
||||||
"perf.faster_singleplayer_load.MinecraftServerMixin",
|
"perf.faster_singleplayer_load.MinecraftServerMixin",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user