diff --git a/patches/minecraft/net/minecraft/world/biome/Biome.java.patch b/patches/minecraft/net/minecraft/world/biome/Biome.java.patch index f907c16963..d4d67c49fc 100644 --- a/patches/minecraft/net/minecraft/world/biome/Biome.java.patch +++ b/patches/minecraft/net/minecraft/world/biome/Biome.java.patch @@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger; -public final class Biome { -+public final class Biome implements net.minecraftforge.registries.IForgeRegistryEntry { ++public final class Biome extends net.minecraftforge.registries.ForgeRegistryEntry.UncheckedRegistryEntry { public static final Logger field_150586_aC = LogManager.getLogger(); public static final Codec field_242418_b = RecordCodecBuilder.create((p_235064_0_) -> { return p_235064_0_.group(Biome.Climate.field_242459_a.forGetter((p_242446_0_) -> { @@ -20,34 +20,7 @@ }); public static final Codec field_242419_c = RecordCodecBuilder.create((p_242432_0_) -> { return p_242432_0_.group(Biome.Climate.field_242459_a.forGetter((p_242441_0_) -> { -@@ -113,6 +115,26 @@ - }); - }); - -+ // FORGE: Since this is special (dynamic registry codec special), we have to re-implement ForgeRegistryEntry here -+ @Nullable -+ private ResourceLocation registryName = null; -+ @Nullable -+ @Override -+ public ResourceLocation getRegistryName() { -+ return registryName; -+ } -+ @Override -+ public Biome setRegistryName(ResourceLocation registryName) { -+ if (getRegistryName() != null) -+ throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + registryName + " Old: " + getRegistryName()); -+ this.registryName = registryName; -+ return this; -+ } -+ @Override -+ public Class getRegistryType() { -+ return Biome.class; -+ } -+ - private Biome(Biome.Climate p_i241927_1_, Biome.Category p_i241927_2_, float p_i241927_3_, float p_i241927_4_, BiomeAmbience p_i241927_5_, BiomeGenerationSettings p_i241927_6_, MobSpawnInfo p_i241927_7_) { - this.field_242423_j = p_i241927_1_; - this.field_242424_k = p_i241927_6_; -@@ -200,7 +222,7 @@ +@@ -200,7 +202,7 @@ } else { if (p_201850_2_.func_177956_o() >= 0 && p_201850_2_.func_177956_o() < 256 && p_201850_1_.func_226658_a_(LightType.BLOCK, p_201850_2_) < 10) { BlockState blockstate = p_201850_1_.func_180495_p(p_201850_2_); diff --git a/src/main/java/net/minecraftforge/registries/ForgeRegistryEntry.java b/src/main/java/net/minecraftforge/registries/ForgeRegistryEntry.java index 45e7562950..54e565bc2b 100644 --- a/src/main/java/net/minecraftforge/registries/ForgeRegistryEntry.java +++ b/src/main/java/net/minecraftforge/registries/ForgeRegistryEntry.java @@ -42,7 +42,7 @@ public abstract class ForgeRegistryEntry> imple if (getRegistryName() != null) throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName()); - this.registryName = GameData.checkPrefix(name, true); + this.registryName = checkRegistryName(name); return (V)this; } @@ -59,4 +59,28 @@ public abstract class ForgeRegistryEntry> imple } public final Class getRegistryType() { return (Class)token.getRawType(); } + + /** + * This will assert that the registry name is valid and warn about potential registry overrides + * It is important as it detects cases where modders unintentionally register objects with the "minecraft" namespace, leading to dangerous errors later. + * @param name The registry name + * @return A verified "correct" registry name + */ + ResourceLocation checkRegistryName(String name) + { + return GameData.checkPrefix(name, true); + } + + /** + * This class exists for registry entries which are dynamic (e.g. loaded via data packs), and also exist in a forge registry prior to that. + * Due to this, the registry name will be set via the codec not during initial registration, and as a result, we want to not warn about possible overrides as the registry name will be set outside of mod context. + */ + public abstract static class UncheckedRegistryEntry> extends ForgeRegistryEntry + { + @Override + ResourceLocation checkRegistryName(String name) + { + return new ResourceLocation(name); + } + } }