[Fix] Prevent FAPIs forced registry path prefix introduced in 0.86 for our Registries (quiqueck/BetterEnd#273)

This commit is contained in:
Frank 2023-07-23 03:51:27 +02:00
parent ad13bcac92
commit a42ed2a414

View file

@ -1,9 +1,12 @@
package org.betterx.bclib.mixin.common; 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.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
import org.betterx.worlds.together.WorldsTogether;
import net.minecraft.resources.RegistryDataLoader; import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Mixin(RegistryDataLoader.class) @Mixin(value = RegistryDataLoader.class, priority = 500)
public class RegistryDataLoaderMixin { public class RegistryDataLoaderMixin {
@Accessor("WORLDGEN_REGISTRIES") @Accessor("WORLDGEN_REGISTRIES")
@Mutable @Mutable
@ -24,14 +28,22 @@ public class RegistryDataLoaderMixin {
} }
@Inject(method = "<clinit>", at = @At("TAIL")) @Inject(method = "<clinit>", 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 //we need this to ensure, that the BCL-Biome Registry is loaded at the correct time
List<RegistryDataLoader.RegistryData<?>> enhanced = new ArrayList(RegistryDataLoader.WORLDGEN_REGISTRIES.size() + 1); List<RegistryDataLoader.RegistryData<?>> enhanced = new ArrayList(RegistryDataLoader.WORLDGEN_REGISTRIES.size() + 1);
enhanced.add(new RegistryDataLoader.RegistryData<>( enhanced.add(new RegistryDataLoader.RegistryData<>(
BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC
)); ));
enhanced.addAll(RegistryDataLoader.WORLDGEN_REGISTRIES); enhanced.addAll(RegistryDataLoader.WORLDGEN_REGISTRIES);
wt_set_WORLDGEN_REGISTRIES(enhanced); 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<String> info) {
if (id.getNamespace().equals(WorldsTogether.MOD_ID) || id.getNamespace().equals(BCLib.MOD_ID)) {
info.setReturnValue(info.getReturnValue());
}
}
} }