From 5bd9f1bc813992d92478d41e557a4848158a7720 Mon Sep 17 00:00:00 2001 From: apple502j <33279053+apple502j@users.noreply.github.com> Date: Sun, 14 Jul 2024 23:02:21 +0900 Subject: [PATCH] Fix some registry-related bugs (#3932) * Fix tag path for custom registry * Strip knownPackInfo during Biome Modification --- .../modification/BiomeModificationImpl.java | 9 +++++++ .../fabric-biome-api-v1.accesswidener | 3 +++ ...oaderMixin.java => RegistryKeysMixin.java} | 25 +++++++------------ .../fabric-registry-sync-v0.mixins.json | 4 +-- 4 files changed, 23 insertions(+), 18 deletions(-) rename fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/{TagManagerLoaderMixin.java => RegistryKeysMixin.java} (62%) diff --git a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java index 7f5f6c97d..2adaaf425 100644 --- a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java +++ b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java @@ -21,6 +21,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Predicate; @@ -35,6 +36,8 @@ import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.SimpleRegistry; +import net.minecraft.registry.entry.RegistryEntryInfo; import net.minecraft.util.Identifier; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer; @@ -166,6 +169,12 @@ public class BiomeModificationImpl { ); }); } + + if (biomes instanceof SimpleRegistry registry) { + RegistryEntryInfo info = registry.keyToEntryInfo.get(key); + RegistryEntryInfo newInfo = new RegistryEntryInfo(Optional.empty(), info.lifecycle()); + registry.keyToEntryInfo.put(key, newInfo); + } } } diff --git a/fabric-biome-api-v1/src/main/resources/fabric-biome-api-v1.accesswidener b/fabric-biome-api-v1/src/main/resources/fabric-biome-api-v1.accesswidener index 84dfaba87..820a49459 100644 --- a/fabric-biome-api-v1/src/main/resources/fabric-biome-api-v1.accesswidener +++ b/fabric-biome-api-v1/src/main/resources/fabric-biome-api-v1.accesswidener @@ -59,3 +59,6 @@ mutable field net/minecraft/world/biome/GenerationSettings allowedFeatures Ljava # ChunkGenerator accessible field net/minecraft/world/gen/chunk/ChunkGenerator indexedFeaturesListSupplier Ljava/util/function/Supplier; mutable field net/minecraft/world/gen/chunk/ChunkGenerator indexedFeaturesListSupplier Ljava/util/function/Supplier; + +# Registry mutation sync +accessible field net/minecraft/registry/SimpleRegistry keyToEntryInfo Ljava/util/Map; diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/TagManagerLoaderMixin.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java similarity index 62% rename from fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/TagManagerLoaderMixin.java rename to fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java index b68772797..50e5b9f2a 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/TagManagerLoaderMixin.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java @@ -16,28 +16,21 @@ package net.fabricmc.fabric.mixin.registry.sync; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.tag.TagManagerLoader; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; -// Adds namespaces to tag directories for registries added by mods. -@Mixin(TagManagerLoader.class) -abstract class TagManagerLoaderMixin { - @WrapOperation( - method = "buildRequiredGroup", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/registry/RegistryKeys;getTagPath(Lnet/minecraft/registry/RegistryKey;)Ljava/lang/String;" - ) - ) - private String prependDirectoryWithNamespace(RegistryKey> registryKey, Operation original) { - Identifier id = registryKey.getValue(); +@Mixin(RegistryKeys.class) +public class RegistryKeysMixin { + @ModifyReturnValue(method = "getTagPath", at = @At("RETURN")) + private static String prependDirectoryWithNamespace(String original, @Local(argsOnly = true) RegistryKey> registryRef) { + Identifier id = registryRef.getValue(); // Vanilla doesn't mark namespaces in the directories of tags at all, // so we prepend the directories with the namespace if it's a modded registry id. @@ -46,6 +39,6 @@ abstract class TagManagerLoaderMixin { return "tags/" + id.getNamespace() + "/" + id.getPath(); } - return original.call(registryKey); + return original; } } diff --git a/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json b/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json index fb562cdfa..4e7e0480f 100644 --- a/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json +++ b/fabric-registry-sync-v0/src/main/resources/fabric-registry-sync-v0.mixins.json @@ -11,11 +11,11 @@ "MainMixin", "RegistriesAccessor", "RegistriesMixin", + "RegistryKeysMixin", "RegistryLoaderMixin", "SaveLoadingMixin", "SerializableRegistriesMixin", - "SimpleRegistryMixin", - "TagManagerLoaderMixin" + "SimpleRegistryMixin" ], "injectors": { "defaultRequire": 1