Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
4cb7e552ea
|
|
@ -47,6 +47,8 @@ public class ModernFixEarlyConfig {
|
||||||
this.addMixinRule("feature.reduce_loading_screen_freezes", false);
|
this.addMixinRule("feature.reduce_loading_screen_freezes", false);
|
||||||
this.addMixinRule("feature.direct_stack_trace", false);
|
this.addMixinRule("feature.direct_stack_trace", false);
|
||||||
this.addMixinRule("perf.fast_registry_validation", true);
|
this.addMixinRule("perf.fast_registry_validation", true);
|
||||||
|
// not stable yet
|
||||||
|
this.addMixinRule("perf.rewrite_registry", false);
|
||||||
this.addMixinRule("perf.jeresources_startup", modPresent("jeresources"));
|
this.addMixinRule("perf.jeresources_startup", modPresent("jeresources"));
|
||||||
this.addMixinRule("perf.remove_biome_temperature_cache", true);
|
this.addMixinRule("perf.remove_biome_temperature_cache", true);
|
||||||
this.addMixinRule("perf.reduce_blockstate_cache_rebuilds", true);
|
this.addMixinRule("perf.reduce_blockstate_cache_rebuilds", true);
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,26 @@ import net.minecraft.client.resources.model.ModelManager;
|
||||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraftforge.client.ItemModelMesherForge;
|
import net.minecraftforge.client.ItemModelMesherForge;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.minecraftforge.registries.IRegistryDelegate;
|
import net.minecraftforge.registries.IRegistryDelegate;
|
||||||
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Overwrite;
|
import org.spongepowered.asm.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.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Mixin(ItemModelMesherForge.class)
|
@Mixin(ItemModelMesherForge.class)
|
||||||
public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||||
@Shadow @Final private Map<IRegistryDelegate<Item>, ModelResourceLocation> locations;
|
@Shadow @Final @Mutable private Map<IRegistryDelegate<Item>, ModelResourceLocation> locations;
|
||||||
|
|
||||||
|
private Map<IRegistryDelegate<Item>, ModelResourceLocation> overrideLocations;
|
||||||
|
|
||||||
public ItemModelShaperMixin(ModelManager arg) {
|
public ItemModelShaperMixin(ModelManager arg) {
|
||||||
super(arg);
|
super(arg);
|
||||||
|
|
@ -25,6 +33,86 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||||
|
|
||||||
private static final ModelResourceLocation SENTINEL = new ModelResourceLocation("modernfix", "sentinel");
|
private static final ModelResourceLocation SENTINEL = new ModelResourceLocation("modernfix", "sentinel");
|
||||||
|
|
||||||
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
|
private void replaceLocationMap(CallbackInfo ci) {
|
||||||
|
overrideLocations = new HashMap<>();
|
||||||
|
// need to replace this map because mods query locations through it
|
||||||
|
locations = new Map<IRegistryDelegate<Item>, ModelResourceLocation>() {
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return ForgeRegistries.ITEMS.getValues().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(Object key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation get(Object key) {
|
||||||
|
return getLocation(((IRegistryDelegate<Item>)key).get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation put(IRegistryDelegate<Item> key, ModelResourceLocation value) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation remove(Object key) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(@NotNull Map<? extends IRegistryDelegate<Item>, ? extends ModelResourceLocation> m) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<IRegistryDelegate<Item>> keySet() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<ModelResourceLocation> values() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<Entry<IRegistryDelegate<Item>, ModelResourceLocation>> entrySet() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModelResourceLocation getLocation(Item item) {
|
||||||
|
ModelResourceLocation map = overrideLocations.getOrDefault(item.delegate, SENTINEL);
|
||||||
|
if(map == SENTINEL) {
|
||||||
|
/* generate the appropriate location from our cache */
|
||||||
|
map = ModelLocationCache.get(item);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @reason Get the stored location for that item and meta, and get the model
|
* @reason Get the stored location for that item and meta, and get the model
|
||||||
* from that location from the model manager.
|
* from that location from the model manager.
|
||||||
|
|
@ -32,11 +120,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||||
@Overwrite
|
@Overwrite
|
||||||
@Override
|
@Override
|
||||||
public BakedModel getItemModel(Item item) {
|
public BakedModel getItemModel(Item item) {
|
||||||
ModelResourceLocation map = locations.getOrDefault(item.delegate, SENTINEL);
|
ModelResourceLocation map = getLocation(item);
|
||||||
if(map == SENTINEL) {
|
|
||||||
/* generate the appropriate location from our cache */
|
|
||||||
map = ModelLocationCache.get(item);
|
|
||||||
}
|
|
||||||
return map == null ? null : getModelManager().getModel(map);
|
return map == null ? null : getModelManager().getModel(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +131,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||||
@Overwrite
|
@Overwrite
|
||||||
@Override
|
@Override
|
||||||
public void register(Item item, ModelResourceLocation location) {
|
public void register(Item item, ModelResourceLocation location) {
|
||||||
locations.put(item.delegate, location);
|
overrideLocations.put(item.delegate, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -513,8 +513,10 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
}
|
}
|
||||||
@Redirect(method = "loadModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/StateDefinition;getPossibleStates()Lcom/google/common/collect/ImmutableList;"))
|
@Redirect(method = "loadModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/StateDefinition;getPossibleStates()Lcom/google/common/collect/ImmutableList;"))
|
||||||
private ImmutableList<BlockState> loadOnlyRelevantBlockState(StateDefinition<Block, BlockState> stateDefinition, ResourceLocation location) {
|
private ImmutableList<BlockState> loadOnlyRelevantBlockState(StateDefinition<Block, BlockState> stateDefinition, ResourceLocation location) {
|
||||||
Set<Property<?>> fixedProperties = new HashSet<>();
|
|
||||||
ModelResourceLocation mrl = (ModelResourceLocation)location;
|
ModelResourceLocation mrl = (ModelResourceLocation)location;
|
||||||
|
if(Objects.equals(mrl.getVariant(), "inventory"))
|
||||||
|
return ImmutableList.of();
|
||||||
|
Set<Property<?>> fixedProperties = new HashSet<>();
|
||||||
BlockState fixedState = stateDefinition.any();
|
BlockState fixedState = stateDefinition.any();
|
||||||
for(String s : COMMA_SPLITTER.split(mrl.getVariant())) {
|
for(String s : COMMA_SPLITTER.split(mrl.getVariant())) {
|
||||||
Iterator<String> iterator = EQUAL_SPLITTER.split(s).iterator();
|
Iterator<String> iterator = EQUAL_SPLITTER.split(s).iterator();
|
||||||
|
|
@ -572,6 +574,8 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
LOGGER.info("Baking {}", arg);
|
LOGGER.info("Baking {}", arg);
|
||||||
UnbakedModel iunbakedmodel = this.getModel(arg);
|
UnbakedModel iunbakedmodel = this.getModel(arg);
|
||||||
iunbakedmodel.getMaterials(this::getModel, new HashSet<>());
|
iunbakedmodel.getMaterials(this::getModel, new HashSet<>());
|
||||||
|
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
|
||||||
|
LOGGER.warn("Model {} not present", arg);
|
||||||
BakedModel ibakedmodel = null;
|
BakedModel ibakedmodel = null;
|
||||||
if (iunbakedmodel instanceof BlockModel) {
|
if (iunbakedmodel instanceof BlockModel) {
|
||||||
BlockModel blockmodel = (BlockModel)iunbakedmodel;
|
BlockModel blockmodel = (BlockModel)iunbakedmodel;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,11 @@
|
||||||
package org.embeddedt.modernfix.mixin.perf.fast_registry_validation;
|
package org.embeddedt.modernfix.mixin.perf.fast_registry_validation;
|
||||||
|
|
||||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistry;
|
import net.minecraftforge.registries.ForgeRegistry;
|
||||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.Marker;
|
import org.apache.logging.log4j.Marker;
|
||||||
import org.embeddedt.modernfix.registry.FastForgeRegistry;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
@ -67,44 +59,4 @@ public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
|
||||||
private void skipTrace(Logger logger, Marker marker, String s, Object o, Object o1, Object o2, Object o3, Object o4) {
|
private void skipTrace(Logger logger, Marker marker, String s, Object o, Object o1, Object o2, Object o3, Object o4) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Shadow @Final @Mutable private BiMap<Integer, V> ids;
|
|
||||||
|
|
||||||
@Shadow @Final @Mutable private BiMap<ResourceKey<V>, V> keys;
|
|
||||||
|
|
||||||
@Shadow @Final private ResourceKey<Registry<V>> key;
|
|
||||||
|
|
||||||
@Shadow @Final @Mutable private BiMap<ResourceLocation, V> names;
|
|
||||||
|
|
||||||
@Shadow @Final @Mutable private BiMap owners;
|
|
||||||
|
|
||||||
private FastForgeRegistry<V> fastRegistry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The following code replaces the Forge HashBiMaps with a more efficient data structure based around
|
|
||||||
* an array list for IDs and one HashMap going from value -> information.
|
|
||||||
*/
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
|
||||||
private void replaceBackingMaps(CallbackInfo ci) {
|
|
||||||
this.fastRegistry = new FastForgeRegistry<>(this.key);
|
|
||||||
this.ids = fastRegistry.getIds();
|
|
||||||
this.keys = fastRegistry.getKeys();
|
|
||||||
this.names = fastRegistry.getNames();
|
|
||||||
this.owners = fastRegistry.getOwners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "freeze", at = @At("RETURN"))
|
|
||||||
private void optimizeRegistry(CallbackInfo ci) {
|
|
||||||
this.fastRegistry.optimize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V"))
|
|
||||||
private void clearBiMap(BiMap map) {
|
|
||||||
if(map == this.owners) {
|
|
||||||
this.fastRegistry.clear();
|
|
||||||
} else if(map == this.keys || map == this.names || map == this.ids) {
|
|
||||||
// do nothing, the registry is faster at clearing everything at once
|
|
||||||
} else
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.embeddedt.modernfix.mixin.perf.rewrite_registry;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistry;
|
||||||
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||||
|
import org.embeddedt.modernfix.registry.FastForgeRegistry;
|
||||||
|
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.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(value = ForgeRegistry.class, remap = false)
|
||||||
|
public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
@Mutable
|
||||||
|
private BiMap<Integer, V> ids;
|
||||||
|
|
||||||
|
@Shadow @Final @Mutable private BiMap<ResourceKey<V>, V> keys;
|
||||||
|
|
||||||
|
@Shadow @Final private ResourceKey<Registry<V>> key;
|
||||||
|
|
||||||
|
@Shadow @Final @Mutable private BiMap<ResourceLocation, V> names;
|
||||||
|
|
||||||
|
@Shadow @Final @Mutable private BiMap owners;
|
||||||
|
|
||||||
|
private FastForgeRegistry<V> fastRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The following code replaces the Forge HashBiMaps with a more efficient data structure based around
|
||||||
|
* an array list for IDs and one HashMap going from value -> information.
|
||||||
|
*/
|
||||||
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
|
private void replaceBackingMaps(CallbackInfo ci) {
|
||||||
|
this.fastRegistry = new FastForgeRegistry<>(this.key);
|
||||||
|
this.ids = fastRegistry.getIds();
|
||||||
|
this.keys = fastRegistry.getKeys();
|
||||||
|
this.names = fastRegistry.getNames();
|
||||||
|
this.owners = fastRegistry.getOwners();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "freeze", at = @At("RETURN"))
|
||||||
|
private void optimizeRegistry(CallbackInfo ci) {
|
||||||
|
this.fastRegistry.optimize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V"))
|
||||||
|
private void clearBiMap(BiMap map) {
|
||||||
|
if(map == this.owners) {
|
||||||
|
this.fastRegistry.clear();
|
||||||
|
} else if(map == this.keys || map == this.names || map == this.ids) {
|
||||||
|
// do nothing, the registry is faster at clearing everything at once
|
||||||
|
} else
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.embeddedt.modernfix.mixin.perf.fast_registry_validation;
|
package org.embeddedt.modernfix.mixin.perf.rewrite_registry;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
|
@ -36,7 +36,8 @@
|
||||||
"perf.nbt_memory_usage.CompoundTagMixin",
|
"perf.nbt_memory_usage.CompoundTagMixin",
|
||||||
"perf.kubejs.RecipeEventJSMixin",
|
"perf.kubejs.RecipeEventJSMixin",
|
||||||
"perf.fast_registry_validation.ForgeRegistryMixin",
|
"perf.fast_registry_validation.ForgeRegistryMixin",
|
||||||
"perf.fast_registry_validation.ForgeRegistrySnapshotMixin",
|
"perf.rewrite_registry.ForgeRegistryMixin",
|
||||||
|
"perf.rewrite_registry.ForgeRegistrySnapshotMixin",
|
||||||
"perf.fast_registry_validation.ResourceKeyMixin",
|
"perf.fast_registry_validation.ResourceKeyMixin",
|
||||||
"perf.cache_strongholds.ChunkGeneratorMixin",
|
"perf.cache_strongholds.ChunkGeneratorMixin",
|
||||||
"perf.cache_upgraded_structures.StructureManagerMixin",
|
"perf.cache_upgraded_structures.StructureManagerMixin",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user