Fix some registry-related bugs (#3932)

* Fix tag path for custom registry

* Strip knownPackInfo during Biome Modification
This commit is contained in:
apple502j 2024-07-14 23:02:21 +09:00 committed by GitHub
parent c111832abb
commit 5bd9f1bc81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 18 deletions

View file

@ -21,6 +21,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -35,6 +36,8 @@ import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.registry.entry.RegistryEntryInfo;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer; import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer;
@ -166,6 +169,12 @@ public class BiomeModificationImpl {
); );
}); });
} }
if (biomes instanceof SimpleRegistry<Biome> registry) {
RegistryEntryInfo info = registry.keyToEntryInfo.get(key);
RegistryEntryInfo newInfo = new RegistryEntryInfo(Optional.empty(), info.lifecycle());
registry.keyToEntryInfo.put(key, newInfo);
}
} }
} }

View file

@ -59,3 +59,6 @@ mutable field net/minecraft/world/biome/GenerationSettings allowedFeatures Ljava
# ChunkGenerator # ChunkGenerator
accessible field net/minecraft/world/gen/chunk/ChunkGenerator indexedFeaturesListSupplier Ljava/util/function/Supplier; 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; 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;

View file

@ -16,28 +16,21 @@
package net.fabricmc.fabric.mixin.registry.sync; package net.fabricmc.fabric.mixin.registry.sync;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local;
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 net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.tag.TagManagerLoader; import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
// Adds namespaces to tag directories for registries added by mods. @Mixin(RegistryKeys.class)
@Mixin(TagManagerLoader.class) public class RegistryKeysMixin {
abstract class TagManagerLoaderMixin { @ModifyReturnValue(method = "getTagPath", at = @At("RETURN"))
@WrapOperation( private static String prependDirectoryWithNamespace(String original, @Local(argsOnly = true) RegistryKey<? extends Registry<?>> registryRef) {
method = "buildRequiredGroup", Identifier id = registryRef.getValue();
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/registry/RegistryKeys;getTagPath(Lnet/minecraft/registry/RegistryKey;)Ljava/lang/String;"
)
)
private String prependDirectoryWithNamespace(RegistryKey<? extends Registry<?>> registryKey, Operation<String> original) {
Identifier id = registryKey.getValue();
// Vanilla doesn't mark namespaces in the directories of tags at all, // 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. // 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 "tags/" + id.getNamespace() + "/" + id.getPath();
} }
return original.call(registryKey); return original;
} }
} }

View file

@ -11,11 +11,11 @@
"MainMixin", "MainMixin",
"RegistriesAccessor", "RegistriesAccessor",
"RegistriesMixin", "RegistriesMixin",
"RegistryKeysMixin",
"RegistryLoaderMixin", "RegistryLoaderMixin",
"SaveLoadingMixin", "SaveLoadingMixin",
"SerializableRegistriesMixin", "SerializableRegistriesMixin",
"SimpleRegistryMixin", "SimpleRegistryMixin"
"TagManagerLoaderMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1