From a42ed2a4149bb4510cec83d9a221d017f3f25c8e Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 23 Jul 2023 03:51:27 +0200 Subject: [PATCH] [Fix] Prevent FAPIs forced registry path prefix introduced in 0.86 for our Registries (quiqueck/BetterEnd#273) --- .../mixin/common/RegistryDataLoaderMixin.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/betterx/bclib/mixin/common/RegistryDataLoaderMixin.java b/src/main/java/org/betterx/bclib/mixin/common/RegistryDataLoaderMixin.java index 170eab75..f204936e 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/RegistryDataLoaderMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/RegistryDataLoaderMixin.java @@ -1,9 +1,12 @@ package org.betterx.bclib.mixin.common; +import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData; +import org.betterx.worlds.together.WorldsTogether; import net.minecraft.resources.RegistryDataLoader; +import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -11,11 +14,12 @@ import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.ArrayList; import java.util.List; -@Mixin(RegistryDataLoader.class) +@Mixin(value = RegistryDataLoader.class, priority = 500) public class RegistryDataLoaderMixin { @Accessor("WORLDGEN_REGISTRIES") @Mutable @@ -24,14 +28,22 @@ public class RegistryDataLoaderMixin { } @Inject(method = "", at = @At("TAIL")) - private static void wt_init(CallbackInfo ci) { + private static void bcl_init(CallbackInfo ci) { //we need this to ensure, that the BCL-Biome Registry is loaded at the correct time List> enhanced = new ArrayList(RegistryDataLoader.WORLDGEN_REGISTRIES.size() + 1); enhanced.add(new RegistryDataLoader.RegistryData<>( BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC )); enhanced.addAll(RegistryDataLoader.WORLDGEN_REGISTRIES); - wt_set_WORLDGEN_REGISTRIES(enhanced); } + + // Fabric force changes the directory path for all modded registries to be prefixed with the mod id. + // We do not want this for our BCL-Biome/Surface Rule Registry, so we remove the prefix here. + @Inject(method = "registryDirPath", at = @At("RETURN"), cancellable = true) + private static void prependDirectoryWithNamespace(ResourceLocation id, CallbackInfoReturnable info) { + if (id.getNamespace().equals(WorldsTogether.MOD_ID) || id.getNamespace().equals(BCLib.MOD_ID)) { + info.setReturnValue(info.getReturnValue()); + } + } }