diff --git a/patches/minecraft/net/minecraft/world/biome/Biome.java.patch b/patches/minecraft/net/minecraft/world/biome/Biome.java.patch index 8f020a5c7..f907c1696 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 extends net.minecraftforge.registries.ForgeRegistryEntry { ++public final class Biome implements net.minecraftforge.registries.IForgeRegistryEntry { 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_) -> { @@ -14,13 +14,40 @@ }), MobSpawnInfo.field_242552_c.forGetter((p_242442_0_) -> { return p_242442_0_.field_242425_l; - })).apply(p_235064_0_, Biome::new); -+ }), ResourceLocation.field_240908_a_.fieldOf("forge:registry_name").forGetter(Biome::getRegistryName)) ++ }), ResourceLocation.field_240908_a_.optionalFieldOf("forge:registry_name").forGetter(b -> Optional.ofNullable(b.getRegistryName()))) + .apply(p_235064_0_, (climate, category, depth, scale, effects, gen, spawns, name) -> -+ net.minecraftforge.common.ForgeHooks.enhanceBiome(name, climate, category, depth, scale, effects, gen, spawns, p_235064_0_, Biome::new)); ++ net.minecraftforge.common.ForgeHooks.enhanceBiome(name.orElse(null), climate, category, depth, scale, effects, gen, spawns, p_235064_0_, Biome::new)); }); 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_) -> { -@@ -200,7 +202,7 @@ +@@ -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 @@ } 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/patches/minecraft/net/minecraft/world/gen/FlatGenerationSettings.java.patch b/patches/minecraft/net/minecraft/world/gen/FlatGenerationSettings.java.patch new file mode 100644 index 000000000..6f3623891 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/gen/FlatGenerationSettings.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/gen/FlatGenerationSettings.java ++++ b/net/minecraft/world/gen/FlatGenerationSettings.java +@@ -174,7 +174,7 @@ + } + } + +- return (new Biome.Builder()).func_205415_a(biome.func_201851_b()).func_205419_a(biome.func_201856_r()).func_205421_a(biome.func_185355_j()).func_205420_b(biome.func_185360_m()).func_205414_c(biome.func_242445_k()).func_205417_d(biome.func_76727_i()).func_235097_a_(biome.func_235089_q_()).func_242457_a(biomegenerationsettings$builder.func_242508_a()).func_242458_a(biome.func_242433_b()).func_242455_a(); ++ return (new Biome.Builder()).func_205415_a(biome.func_201851_b()).func_205419_a(biome.func_201856_r()).func_205421_a(biome.func_185355_j()).func_205420_b(biome.func_185360_m()).func_205414_c(biome.func_242445_k()).func_205417_d(biome.func_76727_i()).func_235097_a_(biome.func_235089_q_()).func_242457_a(biomegenerationsettings$builder.func_242508_a()).func_242458_a(biome.func_242433_b()).func_242455_a().setRegistryName(biome.getRegistryName()); + } + + public DimensionStructuresSettings func_236943_d_() { diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index e0dab612e..122070372 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -875,13 +875,13 @@ public class ForgeHooks Biome apply(final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns); } - public static Biome enhanceBiome(final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns, final RecordCodecBuilder.Instance codec, final BiomeCallbackFunction callback) + public static Biome enhanceBiome(@Nullable final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns, final RecordCodecBuilder.Instance codec, final BiomeCallbackFunction callback) { BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder(gen); MobSpawnInfoBuilder spawnBuilder = new MobSpawnInfoBuilder(spawns); BiomeLoadingEvent event = new BiomeLoadingEvent(name, climate, category, depth, scale, effects, genBuilder, spawnBuilder); MinecraftForge.EVENT_BUS.post(event); - return callback.apply(event.getClimate(), event.getCategory(), event.getDepth(), event.getScale(), event.getEffects(), event.getGeneration().func_242508_a(), event.getSpawns().func_242577_b()); + return callback.apply(event.getClimate(), event.getCategory(), event.getDepth(), event.getScale(), event.getEffects(), event.getGeneration().func_242508_a(), event.getSpawns().func_242577_b()).setRegistryName(name); } private static class LootTableContext diff --git a/src/main/java/net/minecraftforge/event/world/BiomeLoadingEvent.java b/src/main/java/net/minecraftforge/event/world/BiomeLoadingEvent.java index a467f8960..40e32712f 100644 --- a/src/main/java/net/minecraftforge/event/world/BiomeLoadingEvent.java +++ b/src/main/java/net/minecraftforge/event/world/BiomeLoadingEvent.java @@ -27,6 +27,8 @@ import net.minecraftforge.common.world.MobSpawnInfoBuilder; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.EventPriority; +import javax.annotation.Nullable; + /** * This event fires when a Biome is created from json or when a registered biome is re-created for worldgen. * It allows mods to edit a biome (like add a mob spawn) before it gets used for worldgen. @@ -52,7 +54,7 @@ public class BiomeLoadingEvent extends Event private final BiomeGenerationSettingsBuilder gen; private final MobSpawnInfoBuilder spawns; - public BiomeLoadingEvent(final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final float depth, final float scale, final BiomeAmbience effects, final BiomeGenerationSettingsBuilder gen, final MobSpawnInfoBuilder spawns) + public BiomeLoadingEvent(@Nullable final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final float depth, final float scale, final BiomeAmbience effects, final BiomeGenerationSettingsBuilder gen, final MobSpawnInfoBuilder spawns) { this.name = name; this.climate = climate; @@ -64,6 +66,12 @@ public class BiomeLoadingEvent extends Event this.spawns = spawns; } + /** + * This will get the registry name of the biome. + * It generally SHOULD NOT be null, but due to vanilla's biome handling and codec weirdness, there may be cases where it is. + * Do check for this possibility! + */ + @Nullable public ResourceLocation getName() { return name;