Changes for Biomes from Fabric API

This commit is contained in:
Frank 2022-05-27 12:08:19 +02:00
parent 6c10735874
commit b8b12623bf
7 changed files with 202 additions and 171 deletions

View file

@ -69,34 +69,34 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class BiomeAPI { public class BiomeAPI {
public static class Dimension { public static class BiomeType {
public static final Dimension NONE = new Dimension("NONE"); public static final BiomeType NONE = new BiomeType("NONE");
public static final Dimension OVERWORLD = new Dimension("OVERWORLD"); public static final BiomeType OVERWORLD = new BiomeType("OVERWORLD");
public static final Dimension NETHER = new Dimension("NETHER"); public static final BiomeType NETHER = new BiomeType("NETHER");
public static final Dimension BCL_NETHER = new Dimension("BCL_NETHER", NETHER); public static final BiomeType BCL_NETHER = new BiomeType("BCL_NETHER", NETHER);
public static final Dimension OTHER_NETHER = new Dimension("OTHER_NETHER", NETHER); public static final BiomeType OTHER_NETHER = new BiomeType("OTHER_NETHER", NETHER);
public static final Dimension END = new Dimension("END"); public static final BiomeType END = new BiomeType("END");
public static final Dimension END_LAND = new Dimension("END_LAND", END); public static final BiomeType END_LAND = new BiomeType("END_LAND", END);
public static final Dimension END_VOID = new Dimension("END_VOID", END); public static final BiomeType END_VOID = new BiomeType("END_VOID", END);
public static final Dimension BCL_END_LAND = new Dimension("BCL_END_LAND", END_LAND); public static final BiomeType BCL_END_LAND = new BiomeType("BCL_END_LAND", END_LAND);
public static final Dimension BCL_END_VOID = new Dimension("BCL_END_VOID", END_VOID); public static final BiomeType BCL_END_VOID = new BiomeType("BCL_END_VOID", END_VOID);
public static final Dimension OTHER_END_LAND = new Dimension("OTHER_END_LAND", END_LAND); public static final BiomeType OTHER_END_LAND = new BiomeType("OTHER_END_LAND", END_LAND);
public static final Dimension OTHER_END_VOID = new Dimension("OTHER_END_VOID", END_VOID); public static final BiomeType OTHER_END_VOID = new BiomeType("OTHER_END_VOID", END_VOID);
private static final Map<ResourceLocation, Dimension> DIMENSION_MAP = Maps.newHashMap(); private static final Map<ResourceLocation, BiomeType> BIOME_TYPE_MAP = Maps.newHashMap();
public final Dimension parentOrNull; public final BiomeType parentOrNull;
private final String debugName; private final String debugName;
public Dimension(String debugName) { public BiomeType(String debugName) {
this(debugName, null); this(debugName, null);
} }
public Dimension(String debugName, Dimension parentOrNull) { public BiomeType(String debugName, BiomeType parentOrNull) {
this.parentOrNull = parentOrNull; this.parentOrNull = parentOrNull;
this.debugName = debugName; this.debugName = debugName;
} }
public boolean is(Dimension d) { public boolean is(BiomeType d) {
if (d == this) return true; if (d == this) return true;
if (parentOrNull != null) return parentOrNull.is(d); if (parentOrNull != null) return parentOrNull.is(d);
return false; return false;
@ -134,11 +134,11 @@ public class BiomeAPI {
public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END)); public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END));
public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END,
getFromRegistry(Biomes.END_MIDLANDS).value(), getFromRegistry(Biomes.END_MIDLANDS).value(),
0.5F); 0.5F);
public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END,
getFromRegistry(Biomes.END_HIGHLANDS).value(), getFromRegistry(Biomes.END_HIGHLANDS).value(),
0.5F); 0.5F);
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens"))); public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation( public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation(
@ -193,19 +193,19 @@ public class BiomeAPI {
* @param dim The Dimension fo rthis Biome * @param dim The Dimension fo rthis Biome
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerBiome(BCLBiome bclbiome, Dimension dim) { public static BCLBiome registerBiome(BCLBiome bclbiome, BiomeType dim) {
if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) { if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) {
final Biome biome = bclbiome.getBiome(); final Biome biome = bclbiome.getBiome();
ResourceLocation loc = bclbiome.getID(); ResourceLocation loc = bclbiome.getID();
Registry.register(BuiltinRegistries.BIOME, loc, biome); Registry.register(BuiltinRegistries.BIOME, loc, biome);
} }
ID_MAP.put(bclbiome.getID(), bclbiome); ID_MAP.put(bclbiome.getID(), bclbiome);
Dimension.DIMENSION_MAP.put(bclbiome.getID(), dim); BiomeType.BIOME_TYPE_MAP.put(bclbiome.getID(), dim);
if (dim != null && dim.is(Dimension.NETHER)) { if (dim != null && dim.is(BiomeType.NETHER)) {
TagAPI.addBiomeTag(BiomeTags.IS_NETHER, bclbiome.getBiome()); TagAPI.addBiomeTag(BiomeTags.IS_NETHER, bclbiome.getBiome());
TagAPI.addBiomeTag(CommonBiomeTags.IN_NETHER, bclbiome.getBiome()); TagAPI.addBiomeTag(CommonBiomeTags.IN_NETHER, bclbiome.getBiome());
} else if (dim != null && dim.is(Dimension.END)) { } else if (dim != null && dim.is(BiomeType.END)) {
TagAPI.addBiomeTag(BiomeTags.IS_END, bclbiome.getBiome()); TagAPI.addBiomeTag(BiomeTags.IS_END, bclbiome.getBiome());
} }
@ -215,24 +215,26 @@ public class BiomeAPI {
} }
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
return registerSubBiome(parent, subBiome, Dimension.DIMENSION_MAP.getOrDefault(parent.getID(), Dimension.NONE)); return registerSubBiome(parent,
subBiome,
BiomeType.BIOME_TYPE_MAP.getOrDefault(parent.getID(), BiomeType.NONE));
} }
public static BCLBiome registerSubBiome(BCLBiome parent, Biome subBiome, float genChance) { public static BCLBiome registerSubBiome(BCLBiome parent, Biome subBiome, float genChance) {
return registerSubBiome(parent, return registerSubBiome(parent,
subBiome, subBiome,
genChance, genChance,
Dimension.DIMENSION_MAP.getOrDefault(parent.getID(), Dimension.NONE)); BiomeType.BIOME_TYPE_MAP.getOrDefault(parent.getID(), BiomeType.NONE));
} }
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome, Dimension dim) { public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome, BiomeType dim) {
registerBiome(subBiome, dim); registerBiome(subBiome, dim);
parent.addSubBiome(subBiome); parent.addSubBiome(subBiome);
return subBiome; return subBiome;
} }
public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance, Dimension dim) { public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance, BiomeType dim) {
BCLBiome subBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); BCLBiome subBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
return registerSubBiome(parent, subBiome, dim); return registerSubBiome(parent, subBiome, dim);
} }
@ -245,7 +247,7 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerNetherBiome(BCLBiome bclBiome) { public static BCLBiome registerNetherBiome(BCLBiome bclBiome) {
registerBiome(bclBiome, Dimension.BCL_NETHER); registerBiome(bclBiome, BiomeType.BCL_NETHER);
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(bclBiome.getBiomeHolder()); ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(bclBiome.getBiomeHolder());
if (bclBiome.allowFabricRegistration()) { if (bclBiome.allowFabricRegistration()) {
@ -263,7 +265,7 @@ public class BiomeAPI {
*/ */
public static BCLBiome registerNetherBiome(Biome biome) { public static BCLBiome registerNetherBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome, null); BCLBiome bclBiome = new BCLBiome(biome, null);
registerBiome(bclBiome, Dimension.OTHER_NETHER); registerBiome(bclBiome, BiomeType.OTHER_NETHER);
return bclBiome; return bclBiome;
} }
@ -275,7 +277,7 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(BCLBiome biome) { public static BCLBiome registerEndLandBiome(BCLBiome biome) {
registerBiome(biome, Dimension.BCL_END_LAND); registerBiome(biome, BiomeType.BCL_END_LAND);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BiomeAPI.getBiomeKey(biome.getBiome()); ResourceKey<Biome> key = BiomeAPI.getBiomeKey(biome.getBiome());
@ -296,7 +298,7 @@ public class BiomeAPI {
public static BCLBiome registerEndLandBiome(Holder<Biome> biome) { public static BCLBiome registerEndLandBiome(Holder<Biome> biome) {
BCLBiome bclBiome = new BCLBiome(biome.value(), null); BCLBiome bclBiome = new BCLBiome(biome.value(), null);
registerBiome(bclBiome, Dimension.OTHER_END_LAND); registerBiome(bclBiome, BiomeType.OTHER_END_LAND);
return bclBiome; return bclBiome;
} }
@ -310,9 +312,9 @@ public class BiomeAPI {
*/ */
public static BCLBiome registerEndLandBiome(Holder<Biome> biome, float genChance) { public static BCLBiome registerEndLandBiome(Holder<Biome> biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome.value(), BCLBiome bclBiome = new BCLBiome(biome.value(),
VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
registerBiome(bclBiome, Dimension.OTHER_END_LAND); registerBiome(bclBiome, BiomeType.OTHER_END_LAND);
return bclBiome; return bclBiome;
} }
@ -324,7 +326,7 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(BCLBiome biome) { public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
registerBiome(biome, Dimension.END_VOID); registerBiome(biome, BiomeType.END_VOID);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder()); ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder());
@ -344,7 +346,7 @@ public class BiomeAPI {
public static BCLBiome registerEndVoidBiome(Holder<Biome> biome) { public static BCLBiome registerEndVoidBiome(Holder<Biome> biome) {
BCLBiome bclBiome = new BCLBiome(biome.value(), null); BCLBiome bclBiome = new BCLBiome(biome.value(), null);
registerBiome(bclBiome, Dimension.END_VOID); registerBiome(bclBiome, BiomeType.END_VOID);
return bclBiome; return bclBiome;
} }
@ -358,9 +360,9 @@ public class BiomeAPI {
*/ */
public static BCLBiome registerEndVoidBiome(Holder<Biome> biome, float genChance) { public static BCLBiome registerEndVoidBiome(Holder<Biome> biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome.value(), BCLBiome bclBiome = new BCLBiome(biome.value(),
VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
registerBiome(bclBiome, Dimension.END_VOID); registerBiome(bclBiome, BiomeType.END_VOID);
return bclBiome; return bclBiome;
} }
@ -523,8 +525,8 @@ public class BiomeAPI {
return getFromRegistry(biomeID) == null; return getFromRegistry(biomeID) == null;
} }
public static boolean wasRegisteredAs(ResourceLocation biomeID, Dimension dim) { public static boolean wasRegisteredAs(ResourceLocation biomeID, BiomeType dim) {
if (Dimension.DIMENSION_MAP.containsKey(biomeID) && Dimension.DIMENSION_MAP.get(biomeID).is(dim)) return true; if (BiomeType.BIOME_TYPE_MAP.containsKey(biomeID) && BiomeType.BIOME_TYPE_MAP.get(biomeID).is(dim)) return true;
BCLBiome biome = getBiome(biomeID); BCLBiome biome = getBiome(biomeID);
if (biome != null && biome != BiomeAPI.EMPTY_BIOME && biome.getParentBiome() != null) { if (biome != null && biome != BiomeAPI.EMPTY_BIOME && biome.getParentBiome() != null) {
return wasRegisteredAs(biome.getParentBiome().getID(), dim); return wasRegisteredAs(biome.getParentBiome().getID(), dim);
@ -533,19 +535,19 @@ public class BiomeAPI {
} }
public static boolean wasRegisteredAsNetherBiome(ResourceLocation biomeID) { public static boolean wasRegisteredAsNetherBiome(ResourceLocation biomeID) {
return wasRegisteredAs(biomeID, Dimension.NETHER); return wasRegisteredAs(biomeID, BiomeType.NETHER);
} }
public static boolean wasRegisteredAsEndBiome(ResourceLocation biomeID) { public static boolean wasRegisteredAsEndBiome(ResourceLocation biomeID) {
return wasRegisteredAs(biomeID, Dimension.END); return wasRegisteredAs(biomeID, BiomeType.END);
} }
public static boolean wasRegisteredAsEndLandBiome(ResourceLocation biomeID) { public static boolean wasRegisteredAsEndLandBiome(ResourceLocation biomeID) {
return wasRegisteredAs(biomeID, Dimension.END_LAND); return wasRegisteredAs(biomeID, BiomeType.END_LAND);
} }
public static boolean wasRegisteredAsEndVoidBiome(ResourceLocation biomeID) { public static boolean wasRegisteredAsEndVoidBiome(ResourceLocation biomeID) {
return wasRegisteredAs(biomeID, Dimension.END_VOID); return wasRegisteredAs(biomeID, BiomeType.END_VOID);
} }
/** /**
@ -557,7 +559,7 @@ public class BiomeAPI {
public static void registerBiomeModification(ResourceKey<LevelStem> dimensionID, public static void registerBiomeModification(ResourceKey<LevelStem> dimensionID,
BiConsumer<ResourceLocation, Holder<Biome>> modification) { BiConsumer<ResourceLocation, Holder<Biome>> modification) {
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID,
k -> Lists.newArrayList()); k -> Lists.newArrayList());
modifications.add(modification); modifications.add(modification);
} }
@ -594,14 +596,15 @@ public class BiomeAPI {
public static void _runTagAdders() { public static void _runTagAdders() {
for (var mod : TAG_ADDERS.entrySet()) { for (var mod : TAG_ADDERS.entrySet()) {
Stream<ResourceLocation> s = null; Stream<ResourceLocation> s = null;
if (mod.getKey() == Level.NETHER) s = Dimension.DIMENSION_MAP.entrySet() if (mod.getKey() == Level.NETHER) s = BiomeType.BIOME_TYPE_MAP.entrySet()
.stream() .stream()
.filter(e -> e.getValue().is(Dimension.NETHER)) .filter(e -> e.getValue()
.map(e -> e.getKey()); .is(BiomeType.NETHER))
else if (mod.getKey() == Level.END) s = Dimension.DIMENSION_MAP.entrySet() .map(e -> e.getKey());
.stream() else if (mod.getKey() == Level.END) s = BiomeType.BIOME_TYPE_MAP.entrySet()
.filter(e -> e.getValue().is(Dimension.END)) .stream()
.map(e -> e.getKey()); .filter(e -> e.getValue().is(BiomeType.END))
.map(e -> e.getKey());
if (s != null) { if (s != null) {
s.forEach(id -> { s.forEach(id -> {
BCLBiome b = BiomeAPI.getBiome(id); BCLBiome b = BiomeAPI.getBiome(id);
@ -623,7 +626,7 @@ public class BiomeAPI {
public static void onFinishingBiomeTags(ResourceKey dimensionID, public static void onFinishingBiomeTags(ResourceKey dimensionID,
BiConsumer<ResourceLocation, Holder<Biome>> modification) { BiConsumer<ResourceLocation, Holder<Biome>> modification) {
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = TAG_ADDERS.computeIfAbsent(dimensionID, List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = TAG_ADDERS.computeIfAbsent(dimensionID,
k -> Lists.newArrayList()); k -> Lists.newArrayList());
modifications.add(modification); modifications.add(modification);
} }
@ -674,9 +677,9 @@ public class BiomeAPI {
} }
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.get(level List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.get(level
.dimensionTypeRegistration() .dimensionTypeRegistration()
.unwrapKey() .unwrapKey()
.orElseThrow()); .orElseThrow());
for (Holder<Biome> biomeHolder : biomes) { for (Holder<Biome> biomeHolder : biomes) {
if (biomeHolder.isBound()) { if (biomeHolder.isBound()) {
applyModificationsAndUpdateFeatures(modifications, biomeHolder); applyModificationsAndUpdateFeatures(modifications, biomeHolder);

View file

@ -0,0 +1,23 @@
package org.betterx.bclib.interfaces;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
public interface TheEndBiomeDataAccessor {
boolean bcl_canGenerateAsEndBiome(ResourceKey<Biome> key);
boolean bcl_canGenerateAsEndMidlandBiome(ResourceKey<Biome> key);
boolean bcl_canGenerateAsEndBarrensBiome(ResourceKey<Biome> key);
default boolean bcl_isNonVanillaAndCanGenerateInEnd(ResourceKey<Biome> key) {
return !"minecraft".equals(key.location().getNamespace()) &&
bcl_canGenerateInEnd(key);
}
default boolean bcl_canGenerateInEnd(ResourceKey<Biome> key) {
return bcl_canGenerateAsEndBarrensBiome(key) ||
bcl_canGenerateAsEndMidlandBiome(key) ||
bcl_canGenerateAsEndBiome(key)
;
}
}

View file

@ -1,23 +0,0 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Climate;
import net.fabricmc.fabric.impl.biome.NetherBiomeData;
import org.betterx.bclib.world.biomes.FabricBiomesData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = NetherBiomeData.class, remap = false)
public class NetherBiomeDataMixin {
@Inject(method = "addNetherBiome", at = @At(value = "HEAD"))
private static void bclib_addNetherBiome(ResourceKey<Biome> biome,
Climate.ParameterPoint spawnNoisePoint,
CallbackInfo info) {
FabricBiomesData.NETHER_BIOMES.add(biome);
}
}

View file

@ -1,45 +1,44 @@
package org.betterx.bclib.mixin.common; package org.betterx.bclib.mixin.common;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
import net.fabricmc.fabric.impl.biome.WeightedPicker;
import org.betterx.bclib.world.biomes.FabricBiomesData; import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = TheEndBiomeData.class, remap = false) import javax.annotation.Nullable;
public class TheEndBiomeDataMixin { import java.util.Map;
@Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD"))
private static void bclib_addEndBiomeReplacement(ResourceKey<Biome> replaced, @Mixin(value = TheEndBiomeData.Overrides.class, remap = false)
ResourceKey<Biome> variant, public class TheEndBiomeDataMixin implements TheEndBiomeDataAccessor {
double weight, @Shadow
CallbackInfo info) { @Final
if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { @Nullable
FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endBiomesMap;
} else { @Shadow
FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); @Final
} @Nullable
private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endMidlandsMap;
@Shadow
@Final
@Nullable
private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endBarrensMap;
public boolean bcl_canGenerateAsEndBiome(ResourceKey<Biome> key) {
return endBiomesMap.containsKey(key);
} }
@Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) public boolean bcl_canGenerateAsEndMidlandBiome(ResourceKey<Biome> key) {
private static void bclib_addEndMidlandsReplacement(ResourceKey<Biome> highlands, return endMidlandsMap.containsKey(key);
ResourceKey<Biome> midlands,
double weight,
CallbackInfo info) {
FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight);
} }
@Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) public boolean bcl_canGenerateAsEndBarrensBiome(ResourceKey<Biome> key) {
private static void bclib_addEndBarrensReplacement(ResourceKey<Biome> highlands, return endBarrensMap.containsKey(key);
ResourceKey<Biome> barrens,
double weight,
CallbackInfo info) {
FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight);
FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight);
} }
} }

View file

@ -14,6 +14,8 @@ import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.synth.SimplexNoise; import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.betterx.bclib.BCLib; import org.betterx.bclib.BCLib;
@ -21,6 +23,7 @@ import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry; import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
import org.betterx.bclib.config.Configs; import org.betterx.bclib.config.Configs;
import org.betterx.bclib.interfaces.BiomeMap; import org.betterx.bclib.interfaces.BiomeMap;
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
import org.betterx.bclib.noise.OpenSimplexNoise; import org.betterx.bclib.noise.OpenSimplexNoise;
import org.betterx.bclib.world.biomes.BCLBiome; import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap; import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
@ -51,9 +54,9 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
.stable() .stable()
.forGetter(source -> Optional.of(source.biomeSourceVersion))) .forGetter(source -> Optional.of(source.biomeSourceVersion)))
.apply(instance, .apply(instance,
instance.stable(BCLibEndBiomeSource::new) instance.stable(BCLibEndBiomeSource::new)
) )
); );
private final Holder<Biome> centerBiome; private final Holder<Biome> centerBiome;
private final Holder<Biome> barrens; private final Holder<Biome> barrens;
private final Point pos; private final Point pos;
@ -88,8 +91,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
endVoidBiomePicker = new BiomePicker(biomeRegistry); endVoidBiomePicker = new BiomePicker(biomeRegistry);
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include",
"end_void_biomes", "end_void_biomes",
StringArrayEntry.class).getValue(); StringArrayEntry.class).getValue();
this.possibleBiomes().forEach(biome -> { this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biome.unwrapKey().orElseThrow().location(); ResourceLocation key = biome.unwrapKey().orElseThrow().location();
String group = key.getNamespace() + "." + key.getPath(); String group = key.getNamespace() + "." + key.getPath();
@ -135,32 +138,56 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) { protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) {
datapackBiomes.addAll(getBclBiomes(this.biomeRegistry)); datapackBiomes.addAll(getBclBiomes(this.biomeRegistry));
return new BCLibEndBiomeSource(this.biomeRegistry, return new BCLibEndBiomeSource(this.biomeRegistry,
datapackBiomes.stream().toList(), datapackBiomes.stream().toList(),
this.currentSeed, this.currentSeed,
Optional.of(biomeSourceVersion), Optional.of(biomeSourceVersion),
true); true);
} }
private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) { private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include",
"end_land_biomes", "end_land_biomes",
StringArrayEntry.class).getValue(); StringArrayEntry.class).getValue();
include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include", include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include",
"end_void_biomes", "end_void_biomes",
StringArrayEntry.class).getValue()); StringArrayEntry.class).getValue());
if (TheEndBiomeData.createOverrides(biomeRegistry) instanceof TheEndBiomeDataAccessor acc) {
return getBiomes(biomeRegistry,
new ArrayList<>(0),
include,
(biome, location) ->
BCLibEndBiomeSource.isValidNonVanillaEndBiome(biome, location) ||
acc.bcl_isNonVanillaAndCanGenerateInEnd(biome.unwrapKey().orElseThrow())
return getBiomes(biomeRegistry, new ArrayList<>(0), include, BCLibEndBiomeSource::isValidBCLEndBiome); );
} else {
return getBiomes(biomeRegistry,
new ArrayList<>(0),
include,
BCLibEndBiomeSource::isValidNonVanillaEndBiome);
}
} }
private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) { private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include",
"end_land_biomes", "end_land_biomes",
StringArrayEntry.class).getValue(); StringArrayEntry.class).getValue();
include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include", include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include",
"end_void_biomes", "end_void_biomes",
StringArrayEntry.class).getValue()); StringArrayEntry.class).getValue());
return getBiomes(biomeRegistry, new ArrayList<>(0), include, BCLibEndBiomeSource::isValidEndBiome); if (TheEndBiomeData.createOverrides(biomeRegistry) instanceof TheEndBiomeDataAccessor acc) {
return getBiomes(biomeRegistry,
new ArrayList<>(0),
include,
(biome, location) ->
BCLibEndBiomeSource.isValidEndBiome(biome, location) || acc.bcl_canGenerateInEnd(
biome.unwrapKey().orElseThrow())
);
} else {
return getBiomes(biomeRegistry, new ArrayList<>(0), include, BCLibEndBiomeSource::isValidEndBiome);
}
} }
@ -169,10 +196,10 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
BiomeAPI.wasRegisteredAsEndBiome(location); BiomeAPI.wasRegisteredAsEndBiome(location);
} }
private static boolean isValidBCLEndBiome(Holder<Biome> biome, ResourceLocation location) { private static boolean isValidNonVanillaEndBiome(Holder<Biome> biome, ResourceLocation location) {
return biome.is(BiomeTags.IS_END) || return biome.is(BiomeTags.IS_END) ||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_END_LAND) || BiomeAPI.wasRegisteredAs(location, BiomeAPI.BiomeType.BCL_END_LAND) ||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_END_VOID); BiomeAPI.wasRegisteredAs(location, BiomeAPI.BiomeType.BCL_END_VOID);
} }
public static float getLegacyHeightValue(SimplexNoise simplexNoise, int i, int j) { public static float getLegacyHeightValue(SimplexNoise simplexNoise, int i, int j) {
@ -206,18 +233,18 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
protected void onInitMap(long seed) { protected void onInitMap(long seed) {
if ((biomeSourceVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)) { if ((biomeSourceVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)) {
this.mapLand = new SquareBiomeMap(seed, this.mapLand = new SquareBiomeMap(seed,
GeneratorOptions.getBiomeSizeEndLand(), GeneratorOptions.getBiomeSizeEndLand(),
endLandBiomePicker); endLandBiomePicker);
this.mapVoid = new SquareBiomeMap(seed, this.mapVoid = new SquareBiomeMap(seed,
GeneratorOptions.getBiomeSizeEndVoid(), GeneratorOptions.getBiomeSizeEndVoid(),
endVoidBiomePicker); endVoidBiomePicker);
} else { } else {
this.mapLand = new HexBiomeMap(seed, this.mapLand = new HexBiomeMap(seed,
GeneratorOptions.getBiomeSizeEndLand(), GeneratorOptions.getBiomeSizeEndLand(),
endLandBiomePicker); endLandBiomePicker);
this.mapVoid = new HexBiomeMap(seed, this.mapVoid = new HexBiomeMap(seed,
GeneratorOptions.getBiomeSizeEndVoid(), GeneratorOptions.getBiomeSizeEndVoid(),
endVoidBiomePicker); endVoidBiomePicker);
} }
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed));
@ -246,7 +273,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
noise, noise,
(biomeX >> 1) + 1, (biomeX >> 1) + 1,
(biomeZ >> 1) + 1 (biomeZ >> 1) + 1
) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5; ) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5;
if (height > -20F && height < -5F) { if (height > -20F && height < -5F) {
return barrens; return barrens;

View file

@ -34,23 +34,23 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
public static final Codec<BCLibNetherBiomeSource> CODEC = RecordCodecBuilder public static final Codec<BCLibNetherBiomeSource> CODEC = RecordCodecBuilder
.create(instance -> instance .create(instance -> instance
.group(RegistryOps .group(RegistryOps
.retrieveRegistry(Registry.BIOME_REGISTRY) .retrieveRegistry(Registry.BIOME_REGISTRY)
.forGetter(source -> source.biomeRegistry), .forGetter(source -> source.biomeRegistry),
Codec Codec
.LONG .LONG
.fieldOf("seed") .fieldOf("seed")
.stable() .stable()
.forGetter(source -> { .forGetter(source -> {
return source.currentSeed; return source.currentSeed;
}), }),
Codec Codec
.INT .INT
.optionalFieldOf("version") .optionalFieldOf("version")
.stable() .stable()
.forGetter(source -> Optional.of(source.biomeSourceVersion)) .forGetter(source -> Optional.of(source.biomeSourceVersion))
) )
.apply(instance, instance.stable(BCLibNetherBiomeSource::new)) .apply(instance, instance.stable(BCLibNetherBiomeSource::new))
); );
private BiomeMap biomeMap; private BiomeMap biomeMap;
private final BiomePicker biomePicker; private final BiomePicker biomePicker;
@ -104,10 +104,10 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) { protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) {
datapackBiomes.addAll(getBclBiomes(this.biomeRegistry)); datapackBiomes.addAll(getBclBiomes(this.biomeRegistry));
return new BCLibNetherBiomeSource(this.biomeRegistry, return new BCLibNetherBiomeSource(this.biomeRegistry,
datapackBiomes.stream().toList(), datapackBiomes.stream().toList(),
this.currentSeed, this.currentSeed,
Optional.of(biomeSourceVersion), Optional.of(biomeSourceVersion),
true); true);
} }
/** /**
@ -125,7 +125,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
List<String> exclude = Configs.BIOMES_CONFIG.getEntry("force_exclude", "nether_biomes", StringArrayEntry.class) List<String> exclude = Configs.BIOMES_CONFIG.getEntry("force_exclude", "nether_biomes", StringArrayEntry.class)
.getValue(); .getValue();
return getBiomes(biomeRegistry, exclude, include, BCLibNetherBiomeSource::isValidBCLNetherBiome); return getBiomes(biomeRegistry, exclude, include, BCLibNetherBiomeSource::isValidNonVanillaNetherBiome);
} }
@ -145,8 +145,11 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
BiomeAPI.wasRegisteredAsNetherBiome(location); BiomeAPI.wasRegisteredAsNetherBiome(location);
} }
private static boolean isValidBCLNetherBiome(Holder<Biome> biome, ResourceLocation location) { private static boolean isValidNonVanillaNetherBiome(Holder<Biome> biome, ResourceLocation location) {
return BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_NETHER); return (
!"minecraft".equals(location.getNamespace()) &&
NetherBiomeData.canGenerateInNether(biome.unwrapKey().get())) ||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.BiomeType.BCL_NETHER);
} }
public static <T> void debug(Object el, Registry<T> reg) { public static <T> void debug(Object el, Registry<T> reg) {
@ -195,8 +198,8 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
); );
} else { } else {
this.biomeMap = mapConstructor.apply(seed, this.biomeMap = mapConstructor.apply(seed,
GeneratorOptions.getBiomeSizeNether(), GeneratorOptions.getBiomeSizeNether(),
biomePicker); biomePicker);
} }
} }

View file

@ -23,7 +23,6 @@
"MainMixin", "MainMixin",
"MinecraftServerMixin", "MinecraftServerMixin",
"MobSpawnSettingsAccessor", "MobSpawnSettingsAccessor",
"NetherBiomeDataMixin",
"NoiseBasedChunkGeneratorMixin", "NoiseBasedChunkGeneratorMixin",
"NoiseGeneratorSettingsMixin", "NoiseGeneratorSettingsMixin",
"PistonBaseBlockMixin", "PistonBaseBlockMixin",