parent
22f7f4649b
commit
6e0e67b14d
2 changed files with 27 additions and 30 deletions
|
@ -5,7 +5,7 @@
|
|||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
-public final class Biome {
|
||||
+public final class Biome implements net.minecraftforge.registries.IForgeRegistryEntry<Biome> {
|
||||
+public final class Biome extends net.minecraftforge.registries.ForgeRegistryEntry.UncheckedRegistryEntry<Biome> {
|
||||
public static final Logger field_150586_aC = LogManager.getLogger();
|
||||
public static final Codec<Biome> 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<Biome> 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<Biome> 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_);
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class ForgeRegistryEntry<V extends IForgeRegistryEntry<V>> 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<V extends IForgeRegistryEntry<V>> imple
|
|||
}
|
||||
|
||||
public final Class<V> getRegistryType() { return (Class<V>)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<V extends IForgeRegistryEntry<V>> extends ForgeRegistryEntry<V>
|
||||
{
|
||||
@Override
|
||||
ResourceLocation checkRegistryName(String name)
|
||||
{
|
||||
return new ResourceLocation(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue