Port changes to 1.21.5 (Still need to rewrite all Ingredient Mixins)

This commit is contained in:
DerCommander323 2025-06-26 22:16:58 +02:00
parent 0564c3d75b
commit a7e32ad943
13 changed files with 67 additions and 68 deletions

View File

@ -3,58 +3,16 @@ package org.embeddedt.modernfix.command;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import org.embeddedt.modernfix.ModernFix;
import org.embeddedt.modernfix.duck.IProfilingServerFunctionManager;
import org.embeddedt.modernfix.structure.CachingStructureManager;
import java.io.InputStream;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.minecraft.commands.Commands.literal;
public class ModernFixCommands {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("modernfix")
.then(literal("upgradeStructures")
.requires(source -> source.hasPermission(3))
.executes(context -> {
ServerLevel level = context.getSource().getLevel();
if(level == null) {
context.getSource().sendFailure(Component.literal("Couldn't find server level"));
return 0;
}
ResourceManager manager = level.getServer().resources.resourceManager();
Map<ResourceLocation, Resource> structures = manager.listResources("structures", p -> p.getPath().endsWith(".nbt"));
int upgradedNum = 0;
Pattern pathPattern = Pattern.compile("^structures/(.*)\\.nbt$");
for(Map.Entry<ResourceLocation, Resource> entry : structures.entrySet()) {
upgradedNum++;
ResourceLocation found = entry.getKey();
Matcher matcher = pathPattern.matcher(found.getPath());
if(!matcher.matches())
continue;
ResourceLocation structureLocation = new ResourceLocation(found.getNamespace(), matcher.group(1));
try(InputStream resource = entry.getValue().open()) {
CachingStructureManager.readStructureTag(structureLocation, level.getServer().getFixerUpper(), resource);
Component msg = Component.literal("checked " + structureLocation + " (" + upgradedNum + "/" + structures.size() + ")");
context.getSource().sendSuccess(() -> msg, false);
} catch(Throwable e) {
ModernFix.LOGGER.error("Couldn't upgrade structure " + found, e);
context.getSource().sendFailure(Component.literal("error reading " + structureLocation + " (" + upgradedNum + "/" + structures.size() + ")"));
}
}
context.getSource().sendSuccess(() -> Component.literal("All structures upgraded"), false);
return 1;
}))
.then(literal("mcfunctions").requires(source -> source.hasPermission(3))
.executes(context -> {
ServerLevel level = context.getSource().getLevel();

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.common.mixin.feature.mcfunction_profiling;
/* TODO: Remove or reimplement
import com.google.common.base.Stopwatch;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
@ -70,3 +71,4 @@ public class ServerFunctionManagerMixin implements IProfilingServerFunctionManag
return sb.toString();
}
}
*/

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.common.mixin.perf.lazy_search_tree_registry;
/* TODO: Remove or reimplement
import net.minecraft.client.searchtree.SearchRegistry;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.searchtree.LazySearchTree;
@ -15,3 +16,4 @@ public class SearchRegistryMixin {
return LazySearchTree.decorate(supplier);
}
}
*/

View File

@ -81,7 +81,7 @@ public class DynamicModelProvider {
this.makeLoadingCache(this::loadClientItemProperties);
private final LoadingCache<ResourceLocation, Optional<ItemModel>> loadedItemModels =
this.makeLoadingCache(this::loadItemModel);
this.makeLoadingCache(this::loadItemModel);
/*
private final LoadingCache<ResourceLocation, Optional<BakedModel>> loadedStandaloneModels =
@ -605,4 +605,4 @@ public class DynamicModelProvider {
BlockStateModel.UnbakedRoot modifyBlockModelBeforeBake(BlockStateModel.UnbakedRoot model, BlockState state, ModelBaker baker);
BlockStateModel modifyBlockModelAfterBake(BlockStateModel bakedModel, BlockStateModel.UnbakedRoot unbaked, BlockState state, ModelBaker baker);
}
}
}

View File

@ -75,7 +75,7 @@ public class PackResourcesCacheEngine {
void outputResources(String namespace, Path baseNioPath, String path, PackResources.ResourceOutput output) {
if (children.isEmpty()) {
// This is a terminal node.
ResourceLocation location = new ResourceLocation(namespace, path);
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(namespace, path);
output.accept(location, () -> Files.newInputStream(baseNioPath.resolve(path)));
} else {
for (var entry : children.entrySet()) {

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.searchtree;
/* TODO: Remove or reimplement
import com.google.common.base.Stopwatch;
import net.minecraft.client.searchtree.RefreshableSearchTree;
import net.minecraft.client.searchtree.SearchRegistry;
@ -58,3 +59,4 @@ public class LazySearchTree<T> implements RefreshableSearchTree<T> {
return list -> new LazySearchTree<>(list, originalSupplier);
}
}
*/

View File

@ -32,32 +32,57 @@ accessible field net/minecraft/client/renderer/texture/Stitcher$Holder width I
accessible field net/minecraft/client/renderer/texture/Stitcher$Holder height I
accessible field net/minecraft/network/syncher/EntityDataAccessor id I
mutable field net/minecraft/network/syncher/EntityDataAccessor id I
accessible method net/minecraft/Util makeExecutor (Ljava/lang/String;)Ljava/util/concurrent/ExecutorService;
accessible field net/minecraft/server/level/ChunkMap updatingChunkMap Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;
accessible field net/minecraft/server/level/ChunkMap visibleChunkMap Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;
accessible field net/minecraft/server/level/ChunkMap pendingUnloads Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;
accessible method net/minecraft/resources/ResourceKey <init> (Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/resources/ResourceLocation;)V
accessible field net/minecraft/client/renderer/block/model/BlockModel GSON Lcom/google/gson/Gson;
accessible class net/minecraft/server/level/ChunkMap$DistanceManager
accessible class net/minecraft/client/resources/model/ModelBakery$BakedCacheKey
accessible method net/minecraft/client/resources/model/ModelBakery$BakedCacheKey <init> (Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/math/Transformation;Z)V
accessible class net/minecraft/client/resources/model/ModelBakery$ModelBakerImpl
accessible method net/minecraft/client/resources/model/ModelBakery$ModelBakerImpl <init> (Lnet/minecraft/client/resources/model/ModelBakery;Lnet/minecraft/client/resources/model/ModelBakery$TextureGetter;Lnet/minecraft/client/resources/model/ModelResourceLocation;)V
accessible method net/minecraft/client/resources/model/ModelBakery getModel (Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/resources/model/UnbakedModel;
accessible class net/minecraft/client/resources/model/ModelManager$ReloadState
accessible method net/minecraft/client/resources/model/BlockStateModelLoader loadBlockStateDefinitionStack (Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/level/block/state/StateDefinition;Ljava/util/List;)Lnet/minecraft/client/resources/model/BlockStateModelLoader$LoadedModels;
accessible class net/minecraft/client/resources/model/BlockStateModelLoader$LoadedBlockModelDefinition
accessible method net/minecraft/client/resources/model/BlockStateModelLoader$LoadedBlockModelDefinition <init> (Ljava/lang/String;Lnet/minecraft/client/renderer/block/model/BlockModelDefinition;)V
accessible class net/minecraft/world/level/chunk/PalettedContainer$Data
accessible field net/minecraft/server/MinecraftServer resources Lnet/minecraft/server/MinecraftServer$ReloadableResources;
accessible class net/minecraft/server/MinecraftServer$ReloadableResources
accessible method net/minecraft/client/gui/screens/Screen addRenderableWidget (Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;
accessible field net/minecraft/client/KeyMapping ALL Ljava/util/Map;
accessible field net/minecraft/client/renderer/block/model/multipart/MultiPart definition Lnet/minecraft/world/level/block/state/StateDefinition;
accessible field net/minecraft/client/renderer/block/model/ItemOverrides$BakedOverride model Lnet/minecraft/client/resources/model/BakedModel;
mutable field net/minecraft/client/renderer/block/model/ItemOverrides$BakedOverride model Lnet/minecraft/client/resources/model/BakedModel;
accessible field net/minecraft/client/renderer/entity/EnderDragonRenderer$DragonModel entity Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;
accessible method net/minecraft/world/level/block/state/StateDefinition appendPropertyCodec (Lcom/mojang/serialization/MapCodec;Ljava/util/function/Supplier;Ljava/lang/String;Lnet/minecraft/world/level/block/state/properties/Property;)Lcom/mojang/serialization/MapCodec;
accessible class net/minecraft/client/multiplayer/SessionSearchTrees$Key
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State preparationNanos Ljava/util/concurrent/atomic/AtomicLong;
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State reloadNanos Ljava/util/concurrent/atomic/AtomicLong;
accessible class net/minecraft/client/resources/model/ModelDiscovery$ModelWrapper
accessible method net/minecraft/client/resources/model/ModelDiscovery$ModelWrapper <init> (Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/resources/model/UnbakedModel;Z)V
accessible field net/minecraft/client/resources/model/ModelDiscovery$ModelWrapper parent Lnet/minecraft/client/resources/model/ModelDiscovery$ModelWrapper;
accessible method net/minecraft/client/resources/model/BlockStateDefinitions definitionLocationToBlockStateMapper ()Ljava/util/function/Function;
accessible class net/minecraft/world/item/crafting/Ingredient$Value
accessible class net/minecraft/world/item/crafting/Ingredient$ItemValue
accessible class net/minecraft/client/multiplayer/ClientChunkCache$Storage
accessible class net/minecraft/client/renderer/RenderType$CompositeRenderType
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRule
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SurfaceRule
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker$Type
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Mapped
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Mapped$Type
accessible class net/minecraft/world/level/levelgen/DensityFunctions$MulOrAdd
accessible class net/minecraft/world/level/levelgen/DensityFunctions$MulOrAdd$Type
accessible class net/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase$Cache
accessible class net/minecraft/server/level/ServerChunkCache$MainThreadExecutor
accessible class net/minecraft/client/renderer/block/model/BlockElementFace$Deserializer
accessible class net/minecraft/client/renderer/texture/Stitcher$Holder
accessible class net/minecraft/server/level/ChunkMap$DistanceManager
accessible class net/minecraft/client/resources/model/ModelBakery$ModelBakerImpl
accessible class net/minecraft/client/resources/model/ModelManager$ReloadState
accessible class net/minecraft/client/resources/model/BlockStateModelLoader$LoadedBlockModelDefinition
accessible class net/minecraft/world/level/chunk/PalettedContainer$Data
accessible class net/minecraft/server/MinecraftServer$ReloadableResources
accessible class net/minecraft/client/multiplayer/SessionSearchTrees$Key
accessible class net/minecraft/client/resources/model/ModelDiscovery$ModelWrapper
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State preparationNanos Ljava/util/concurrent/atomic/AtomicLong;
accessible field net/minecraft/server/packs/resources/ProfiledReloadInstance$State reloadNanos Ljava/util/concurrent/atomic/AtomicLong;

View File

@ -1,11 +1,11 @@
package org.embeddedt.modernfix.forge.mixin.feature.measure_time;
package org.embeddedt.modernfix.neoforge.mixin.feature.measure_time;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraftforge/event/AddReloadListenerEvent$WrappedStateAwareListener")
@Mixin(targets = "net/neoforged/bus/AddReloadListenerEvent$WrappedStateAwareListener")
public abstract class AddReloadListenerEventWrapperMixin implements PreparableReloadListener {
@Shadow @Final private PreparableReloadListener wrapped;

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.neoforge.mixin.perf.faster_ingredients;
/* FIXME: Ingredient rework
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntComparators;
import it.unimi.dsi.fastutil.ints.IntList;
@ -58,7 +59,7 @@ public abstract class IngredientMixin implements ExtendedIngredient {
* registry would normally contain, rather than a modified version.
* <p>
* Note: this is a separate problem from the issue where clients may receive recipes before tags in 1.21.
*/
*
private boolean mfix$areTagsAvailable() {
return !MinecraftServerReloadTracker.isReloadActive();
}
@ -66,7 +67,7 @@ public abstract class IngredientMixin implements ExtendedIngredient {
/**
* @author embeddedt
* @reason tag ingredients can be tested without iterating over all items
*/
*
@Inject(method = "test(Lnet/minecraft/world/item/ItemStack;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/crafting/Ingredient;getItems()[Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
private void modernfix$fasterTagIngredientTest(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
if (this.isVanilla() && this.values.length == 1 && this.values[0] instanceof Ingredient.TagValue tagValue && mfix$areTagsAvailable()) {
@ -77,7 +78,7 @@ public abstract class IngredientMixin implements ExtendedIngredient {
/**
* @author embeddedt
* @reason exploding the stack list is unnecessary
*/
*
@Inject(method = "hasNoItems", at = @At("HEAD"), cancellable = true, remap = false)
public void hasNoItems(CallbackInfoReturnable<Boolean> cir) {
if (this.isVanilla()) {
@ -116,7 +117,7 @@ public abstract class IngredientMixin implements ExtendedIngredient {
* @author embeddedt
* @reason tag ingredients can be converted to stacking IDs without expanding into stacks, since stacking only
* goes by item ID
*/
*
@Inject(method = "getStackingIds", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/crafting/Ingredient;getItems()[Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
private void modernfix$fasterTagIngredientStacking(CallbackInfoReturnable<IntList> cir) {
if (this.isVanilla() && this.values.length == 1 && this.values[0] instanceof Ingredient.TagValue tagValue && mfix$areTagsAvailable()) {
@ -135,7 +136,7 @@ public abstract class IngredientMixin implements ExtendedIngredient {
* @author embeddedt
* @reason Change caching of item stacks to use a soft reference, which allows the GC to evict the array under
* memory pressure/when it hasn't been used.
*/
*
@Overwrite
public ItemStack[] getItems() {
// For compatibility if mods explicitly force a set of item stacks to be used
@ -192,3 +193,4 @@ public abstract class IngredientMixin implements ExtendedIngredient {
this.mfix$cachedItemStacks = null;
}
}
*/

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.neoforge.mixin.perf.ingredient_item_deduplication;
/* FIXME: Ingredient rework
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
@ -12,9 +13,10 @@ public class IngredientItemValueMixin {
* @author embeddedt
* @reason Defensively copy the item so that the deduplication is not visible to most mods (unless they introspect
* the item held within this object directly). This is necessary since some mods edit the returned stack.
*/
/
@ModifyExpressionValue(method = "getItems", at = @At(value = "FIELD", target = "Lnet/minecraft/world/item/crafting/Ingredient$ItemValue;item:Lnet/minecraft/world/item/ItemStack;"))
private ItemStack mfix$defensiveCopy(ItemStack original) {
return original.copy();
}
}
*/

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.neoforge.mixin.perf.ingredient_item_deduplication;
/* FIXME: Ingredient rework
import net.minecraft.world.item.crafting.Ingredient;
import org.embeddedt.modernfix.neoforge.recipe.IngredientValueDeduplicator;
import org.spongepowered.asm.mixin.Mixin;
@ -15,3 +16,4 @@ public class IngredientMixin {
return stream.map(IngredientValueDeduplicator::deduplicate);
}
}
*/

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.neoforge.mixin.perf.smart_ingredient_sync;
/* FIXME: Ingredient rework
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.RegistryFriendlyByteBuf;
@ -52,3 +53,4 @@ public abstract class IngredientMixin {
}
}
}
*/

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.neoforge.recipe;
/* FIXME: Ingredient rework
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import net.minecraft.world.item.ItemStackLinkedSet;
@ -7,7 +8,7 @@ import net.minecraft.world.item.crafting.Ingredient;
/**
* @author embeddedt (original inspiration from Uncandango's AllTheLeaks mod)
*/
*
public class IngredientValueDeduplicator {
private static final ObjectOpenCustomHashSet<Ingredient.ItemValue> VALUES = new ObjectOpenCustomHashSet<>(new Hash.Strategy<>() {
@Override
@ -31,3 +32,4 @@ public class IngredientValueDeduplicator {
}
}
}
*/