[Fix] Adding world specific data to global registry
This commit is contained in:
parent
69cd398af4
commit
eda6ea6d67
7 changed files with 71 additions and 20 deletions
|
@ -5,6 +5,7 @@ import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||||
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.BiomeAPI;
|
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||||
|
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||||
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.worlds.together.biomesource.BiomeSourceWithConfig;
|
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
|
||||||
|
@ -138,7 +139,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
|
||||||
final BCLBiome bclBiome;
|
final BCLBiome bclBiome;
|
||||||
if (!BiomeAPI.hasBiome(biomeID)) {
|
if (!BiomeAPI.hasBiome(biomeID)) {
|
||||||
bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.END_LAND);
|
bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.END_LAND);
|
||||||
BiomeAPI.registerBiome(bclBiome);
|
InternalBiomeAPI.registerBCLBiomeData(bclBiome);
|
||||||
} else {
|
} else {
|
||||||
bclBiome = BiomeAPI.getBiome(biomeID);
|
bclBiome = BiomeAPI.getBiome(biomeID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.betterx.bclib.api.v2.generator.map.MapStack;
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||||
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.BiomeAPI;
|
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||||
|
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||||
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.worlds.together.biomesource.BiomeSourceWithConfig;
|
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
|
||||||
|
@ -97,7 +98,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
|
||||||
}
|
}
|
||||||
if (!BiomeAPI.hasBiome(biomeID)) {
|
if (!BiomeAPI.hasBiome(biomeID)) {
|
||||||
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.NETHER);
|
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.NETHER);
|
||||||
BiomeAPI.registerBiome(bclBiome);
|
InternalBiomeAPI.registerBCLBiomeData(bclBiome);
|
||||||
biomePicker.addBiome(bclBiome);
|
biomePicker.addBiome(bclBiome);
|
||||||
} else {
|
} else {
|
||||||
BCLBiome bclBiome = BiomeAPI.getBiome(biomeID);
|
BCLBiome bclBiome = BiomeAPI.getBiome(biomeID);
|
||||||
|
|
|
@ -27,6 +27,18 @@ import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores additional Data for a {@link Biome}. Instances of {@link BCLBiome} are linked to
|
||||||
|
* Biomes using a {@link ResourceKey<Biome>}. The data is registerd and Stored in
|
||||||
|
* {@link BCLBiomeRegistry#BCL_BIOMES_REGISTRY} registries, allowing them to be overriden by Datapacks.
|
||||||
|
* <p>
|
||||||
|
* As such, if you extend BCLBiome with custom types, especially if those new type have a custom state,
|
||||||
|
* you need to provide a Codec for your class using
|
||||||
|
* {@link BCLBiomeRegistry#registerBiomeCodec(ResourceLocation, KeyDispatchDataCodec)}.
|
||||||
|
* <p>
|
||||||
|
* You may use {@link BCLBiome#codecWithSettings(RecordCodecBuilder.Instance)} to create a Codec that includes
|
||||||
|
* all default settings for {@link BCLBiome} as well as additional Data for your specific subclass.
|
||||||
|
*/
|
||||||
public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
||||||
public static final Codec<BCLBiome> CODEC = RecordCodecBuilder.create(instance -> codecWithSettings(instance).apply(
|
public static final Codec<BCLBiome> CODEC = RecordCodecBuilder.create(instance -> codecWithSettings(instance).apply(
|
||||||
instance,
|
instance,
|
||||||
|
|
|
@ -42,16 +42,43 @@ public class BCLBiomeRegistry {
|
||||||
**/
|
**/
|
||||||
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location());
|
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location());
|
||||||
|
|
||||||
public static Codec<? extends BCLBiome> registerBiomeCodec(
|
/**
|
||||||
|
* Register a codec for a custom subclass of {@link BCLBiome}. Each subclass needs to provide
|
||||||
|
* a codec, otherwise the instance will get rebuild as a regular BCLib biome loosing the Type
|
||||||
|
* of the class as well as all member values
|
||||||
|
*
|
||||||
|
* @param location A {@link ResourceLocation} identifying this class
|
||||||
|
* @param codec The matching Codec
|
||||||
|
* @return The codec that will get used
|
||||||
|
*/
|
||||||
|
public static <E extends BCLBiome> Codec<E> registerBiomeCodec(
|
||||||
ResourceLocation location,
|
ResourceLocation location,
|
||||||
KeyDispatchDataCodec<? extends BCLBiome> codec
|
KeyDispatchDataCodec<E> codec
|
||||||
) {
|
) {
|
||||||
Registry.register(BIOME_CODECS, location, codec.codec());
|
Registry.register(BIOME_CODECS, location, codec.codec());
|
||||||
return codec.codec();
|
return codec.codec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public static ResourceKey<BCLBiome> register(BCLBiome biome) {
|
public static ResourceKey<BCLBiome> register(BCLBiome biome) {
|
||||||
Registry.register(BUILTIN_BCL_BIOMES, biome.getBCLBiomeKey(), biome);
|
return register(null, biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register new Biome Data
|
||||||
|
*
|
||||||
|
* @param access The {@link RegistryAccess} to use. If null, we will use the
|
||||||
|
* built inregistry ({@link BCLBiomeRegistry#BUILTIN_BCL_BIOMES})
|
||||||
|
* @param biome The Biome Data to register
|
||||||
|
* @return The resource-key for the registry
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static ResourceKey<BCLBiome> register(RegistryAccess access, BCLBiome biome) {
|
||||||
|
Registry.register(
|
||||||
|
access == null ? BUILTIN_BCL_BIOMES : access.registryOrThrow(BCL_BIOMES_REGISTRY),
|
||||||
|
biome.getBCLBiomeKey(),
|
||||||
|
biome
|
||||||
|
);
|
||||||
return biome.getBCLBiomeKey();
|
return biome.getBCLBiomeKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,14 +270,9 @@ public class BiomeAPI {
|
||||||
InternalBiomeAPI.OTHER_END_VOID
|
InternalBiomeAPI.OTHER_END_VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
@Deprecated(forRemoval = true)
|
||||||
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
|
|
||||||
*
|
|
||||||
* @param bclbiome {@link BCLBiome}
|
|
||||||
* @return {@link BCLBiome}
|
|
||||||
*/
|
|
||||||
public static BCLBiome registerBiome(BCLBiome bclbiome) {
|
public static BCLBiome registerBiome(BCLBiome bclbiome) {
|
||||||
return registerBiome(bclbiome, BuiltinRegistries.BIOME);
|
return InternalBiomeAPI.registerBuiltinBiome(bclbiome);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,7 +313,7 @@ public class BiomeAPI {
|
||||||
&& registryOrNull.get(bclbiome.getID()) == null) {
|
&& registryOrNull.get(bclbiome.getID()) == null) {
|
||||||
Registry.register(registryOrNull, bclbiome.getBiomeKey(), bclbiome.biomeToRegister);
|
Registry.register(registryOrNull, bclbiome.getBiomeKey(), bclbiome.biomeToRegister);
|
||||||
|
|
||||||
BCLBiomeRegistry.register(bclbiome);
|
BCLBiomeRegistry.register(null, bclbiome);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dim != null && dim.is(BiomeType.NETHER)) {
|
if (dim != null && dim.is(BiomeType.NETHER)) {
|
||||||
|
@ -792,8 +787,9 @@ public class BiomeAPI {
|
||||||
*
|
*
|
||||||
* @param biome The {@link Biome} to sort the features for
|
* @param biome The {@link Biome} to sort the features for
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public static void sortBiomeFeatures(Holder<Biome> biome) {
|
public static void sortBiomeFeatures(Holder<Biome> biome) {
|
||||||
sortBiomeFeatures(biome.value());
|
//sortBiomeFeatures(biome.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortBiomeFeatures(Biome biome) {
|
static void sortBiomeFeatures(Biome biome) {
|
||||||
|
@ -879,7 +875,6 @@ public class BiomeAPI {
|
||||||
.flatMap(HolderSet::stream)
|
.flatMap(HolderSet::stream)
|
||||||
.map(Holder::value)
|
.map(Holder::value)
|
||||||
.collect(Collectors.toSet()));
|
.collect(Collectors.toSet()));
|
||||||
|
|
||||||
accessor.bclib_setFeatures(allFeatures);
|
accessor.bclib_setFeatures(allFeatures);
|
||||||
accessor.bclib_setFeatureSet(featureSet);
|
accessor.bclib_setFeatureSet(featureSet);
|
||||||
accessor.bclib_setFlowerFeatures(flowerFeatures);
|
accessor.bclib_setFlowerFeatures(flowerFeatures);
|
||||||
|
|
|
@ -111,8 +111,8 @@ public class InternalBiomeAPI {
|
||||||
BIOMES_TO_SORT.forEach(id -> {
|
BIOMES_TO_SORT.forEach(id -> {
|
||||||
Biome b = biomeRegistry.get(id);
|
Biome b = biomeRegistry.get(id);
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
BCLib.LOGGER.info("Found non fabric/bclib Biome: " + id + "(" + b + ")");
|
// BCLib.LOGGER.info("Found non fabric/bclib Biome: " + id + "(" + b + ")");
|
||||||
BiomeAPI.sortBiomeFeatures(b);
|
// BiomeAPI.sortBiomeFeatures(b);
|
||||||
} else {
|
} else {
|
||||||
BCLib.LOGGER.info("Unknown Biome: " + id);
|
BCLib.LOGGER.info("Unknown Biome: " + id);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ public class InternalBiomeAPI {
|
||||||
bclBiome._setIntendedType(type);
|
bclBiome._setIntendedType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
BiomeAPI.registerBiome(bclBiome);
|
registerBuiltinBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,4 +396,19 @@ public class InternalBiomeAPI {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerBCLBiomeData(BCLBiome biome) {
|
||||||
|
BCLBiomeRegistry.register(registryAccess, biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
|
||||||
|
*
|
||||||
|
* @param bclbiome {@link BCLBiome}
|
||||||
|
* @return {@link BCLBiome}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static BCLBiome registerBuiltinBiome(BCLBiome bclbiome) {
|
||||||
|
return BiomeAPI.registerBiome(bclbiome, BuiltinRegistries.BIOME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,9 +112,9 @@ public class TogetherWorldPreset extends WorldPreset {
|
||||||
if (!presetNBT.contains("dimensions")) {
|
if (!presetNBT.contains("dimensions")) {
|
||||||
return DEFAULT_DIMENSIONS_WRAPPER.dimensions;
|
return DEFAULT_DIMENSIONS_WRAPPER.dimensions;
|
||||||
}
|
}
|
||||||
|
Dynamic<Tag> dynamicOps = new Dynamic<>(registryOps);
|
||||||
Optional<DimensionsWrapper> oLevelStem = DimensionsWrapper.CODEC
|
Optional<DimensionsWrapper> oLevelStem = DimensionsWrapper.CODEC
|
||||||
.parse(new Dynamic<>(registryOps, presetNBT))
|
.parse(NbtOps.INSTANCE, presetNBT)
|
||||||
.resultOrPartial(WorldsTogether.LOGGER::error);
|
.resultOrPartial(WorldsTogether.LOGGER::error);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue