Changes related to Biome-Holders and Features

This commit is contained in:
Frank 2022-03-14 16:42:54 +01:00
parent 86a3480ce0
commit ff70a2b1a8
30 changed files with 200 additions and 222 deletions

View file

@ -1,5 +1,6 @@
package ru.bclib.api;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
@ -49,7 +50,7 @@ public class LifeCycleAPI {
LevelStorageSource.LevelStorageAccess levelStorageAccess,
ServerLevelData serverLevelData,
ResourceKey<Level> resourceKey,
DimensionType dimensionType,
Holder<DimensionType> dimensionType,
ChunkProgressListener chunkProgressListener,
ChunkGenerator chunkGenerator,
boolean bl,
@ -114,7 +115,7 @@ public class LifeCycleAPI {
LevelStorageSource.LevelStorageAccess levelStorageAccess,
ServerLevelData serverLevelData,
ResourceKey<Level> resourceKey,
DimensionType dimensionType,
Holder<DimensionType> dimensionType,
ChunkProgressListener chunkProgressListener,
ChunkGenerator chunkGenerator,
boolean bl,

View file

@ -2,9 +2,12 @@ package ru.bclib.api.biomes;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
@ -546,8 +549,8 @@ public class BCLBiomeBuilder {
* @param structure {@link ConfiguredStructureFeature} to add.
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder structure(ConfiguredStructureFeature<?, ?> structure) {
structures.add(structure);
public BCLBiomeBuilder structure(Holder<ConfiguredStructureFeature<?, ?>> structure) {
structures.add(structure.value());
return this;
}
@ -672,7 +675,7 @@ public class BCLBiomeBuilder {
builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());
Map<Decoration, List<Supplier<PlacedFeature>>> defferedFeatures = new HashMap<>();
Map<Decoration, HolderSet<PlacedFeature>> defferedFeatures = new HashMap<>();
BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build());
if (acc != null) {
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
@ -701,7 +704,8 @@ public class BCLBiomeBuilder {
.setVertical(vertical)
.build();
final T res = biomeConstructor.apply(biomeID, builder.build(), settings);
final Biome biome = builder.build();
final T res = biomeConstructor.apply(biomeID, biome, settings);
res.attachStructures(structures);
res.setSurface(surfaceRule);
res.setFeatures(defferedFeatures);

View file

@ -10,6 +10,7 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
@ -74,27 +75,27 @@ public class BiomeAPI {
private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap();
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
private static Registry<Biome> biomeRegistry;
private static Registry<Holder<Biome>> biomeRegistry;
private static final Map<PlacedFeature, Integer> FEATURE_ORDER = Maps.newHashMap();
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Biome>>> MODIFICATIONS = Maps.newHashMap();
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
private static final Map<ResourceLocation, SurfaceRules.RuleSource> SURFACE_RULES = Maps.newHashMap();
private static final Set<SurfaceRuleProvider> MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8);
public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES));
public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST));
public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST));
public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY));
public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS));
public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES).value());
public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST).value());
public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST).value());
public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY).value());
public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS).value());
public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END));
public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS), 0.5F);
public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS), 0.5F);
public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END).value());
public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F);
public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F);
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")).value());
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).value());
private static void initFeatureOrder() {
if (!FEATURE_ORDER.isEmpty()) {
@ -113,7 +114,7 @@ public class BiomeAPI {
.map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings())
.map(BiomeGenerationSettingsAccessor::bclib_getFeatures)
.forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> {
PlacedFeature feature = featureSupplier.get();
PlacedFeature feature = featureSupplier.value();
FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement());
})));
}
@ -122,7 +123,7 @@ public class BiomeAPI {
* Initialize registry for current server.
* @param biomeRegistry - {@link Registry} for {@link Biome}.
*/
public static void initRegistry(Registry<Biome> biomeRegistry) {
public static void initRegistry(Registry<Holder<Biome>> biomeRegistry) {
if (biomeRegistry != BiomeAPI.biomeRegistry) {
BiomeAPI.biomeRegistry = biomeRegistry;
CLIENT.clear();
@ -185,7 +186,7 @@ public class BiomeAPI {
MHelper.randRange(-1.5F, 1.5F, random),
random.nextFloat()
);
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder());
NetherBiomeData.addNetherBiome(key, parameters);
return biome;
}
@ -215,7 +216,7 @@ public class BiomeAPI {
END_LAND_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
ResourceKey<Biome> key = BiomeAPI.getBiomeKey(biome.getBiome());
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight);
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight);
return biome;
@ -261,7 +262,7 @@ public class BiomeAPI {
END_VOID_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder());
TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
return biome;
}
@ -300,7 +301,7 @@ public class BiomeAPI {
* @param biome - {@link Biome} from world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/
public static BCLBiome getFromBiome(Biome biome) {
public static BCLBiome getFromBiome(Holder<Biome> biome) {
if (biomeRegistry == null) {
return EMPTY_BIOME;
}
@ -333,7 +334,7 @@ public class BiomeAPI {
public static ResourceKey getBiomeKey(Biome biome) {
return BuiltinRegistries.BIOME
.getResourceKey(biome)
.orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null);
.orElse(null);
}
/**
@ -343,9 +344,9 @@ public class BiomeAPI {
*/
public static ResourceLocation getBiomeID(Biome biome) {
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
if (id == null && biomeRegistry != null) {
id = biomeRegistry.getKey(biome);
}
// if (id == null && biomeRegistry != null) {
// id = biomeRegistry.getKey(biome);
//}
return id == null ? EMPTY_BIOME.getID() : id;
}
@ -362,6 +363,14 @@ public class BiomeAPI {
return null;
}
public static ResourceKey getBiomeKey(Holder<Biome> biome) {
return biome.unwrapKey().orElse(null);
}
public static ResourceKey getBiomeKeyOrThrow(Holder<Biome> biome) {
return biome.unwrapKey().orElseThrow();
}
/**
* Get {@link BCLBiome} from given {@link ResourceLocation}.
* @param biomeID - biome {@link ResourceLocation}.
@ -404,31 +413,31 @@ public class BiomeAPI {
public static void loadFabricAPIBiomes() {
FabricBiomesData.NETHER_BIOMES.forEach((key) -> {
if (!hasBiome(key.location())) {
registerNetherBiome(BuiltinRegistries.BIOME.get(key.location()));
registerNetherBiome(BuiltinRegistries.BIOME.get(key));
}
});
FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> {
if (!hasBiome(key.location())) {
registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
registerEndLandBiome(BuiltinRegistries.BIOME.get(key), weight);
}
});
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
if (!hasBiome(key.location())) {
registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
registerEndVoidBiome(BuiltinRegistries.BIOME.get(key), weight);
}
});
}
@Nullable
public static Biome getFromRegistry(ResourceLocation key) {
return BuiltinRegistries.BIOME.get(key);
public static Holder<Biome> getFromRegistry(ResourceLocation key) {
return BuiltinRegistries.BIOME.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, key)).orElseThrow();
}
@Nullable
public static Biome getFromRegistry(ResourceKey<Biome> key) {
return BuiltinRegistries.BIOME.get(key);
public static Holder<Biome> getFromRegistry(ResourceKey<Biome> key) {
return BuiltinRegistries.BIOME.getOrCreateHolder(key);
}
public static boolean isDatapackBiome(ResourceLocation biomeID) {
@ -452,8 +461,8 @@ public class BiomeAPI {
* @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld".
* @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters.
*/
public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer<ResourceLocation, Biome> modification) {
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList());
public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer<ResourceLocation, Holder<Biome>> modification) {
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList());
modifications.add(modification);
}
@ -461,7 +470,7 @@ public class BiomeAPI {
* Registers new biome modification for the Overworld. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/
public static void registerOverworldBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
public static void registerOverworldBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
registerBiomeModification(Level.OVERWORLD, modification);
}
@ -469,7 +478,7 @@ public class BiomeAPI {
* Registers new biome modification for the Nether. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/
public static void registerNetherBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
public static void registerNetherBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
registerBiomeModification(Level.NETHER, modification);
}
@ -477,7 +486,7 @@ public class BiomeAPI {
* Registers new biome modification for the End. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/
public static void registerEndBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
public static void registerEndBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
registerBiomeModification(Level.END, modification);
}
@ -524,10 +533,10 @@ public class BiomeAPI {
}
}
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.get(level.dimension());
for (Holder<Biome> biomeHolder : biomes) {
if (biomeHolder.isBound()) {
applyModificationsAndUpdateFeatures(modifications, biomeHolder.value());
applyModificationsAndUpdateFeatures(modifications, biomeHolder);
}
}
@ -547,7 +556,7 @@ public class BiomeAPI {
((BiomeSourceAccessor) source).bclRebuildFeatures();
}
private static void applyModificationsAndUpdateFeatures(List<BiConsumer<ResourceLocation, Biome>> modifications, Biome biome) {
private static void applyModificationsAndUpdateFeatures(List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications, Holder<Biome> biome) {
ResourceLocation biomeID = getBiomeID(biome);
if (modifications!=null) {
modifications.forEach(consumer -> {
@ -567,8 +576,8 @@ public class BiomeAPI {
* Create a unique sort order for all Features of the Biome
* @param biome The {@link Biome} to sort the features for
*/
public static void sortBiomeFeatures(Biome biome) {
BiomeGenerationSettings settings = biome.getGenerationSettings();
public static void sortBiomeFeatures(Holder<Biome> biome) {
BiomeGenerationSettings settings = biome.value().getGenerationSettings();
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings;
List<List<Supplier<PlacedFeature>>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
final int size = featureList.size();
@ -623,7 +632,7 @@ public class BiomeAPI {
* @param feature {@link ConfiguredFeature} to add.
*
*/
public static void addBiomeFeature(Biome biome, BCLFeature feature) {
public static void addBiomeFeature(Holder<Biome> biome, BCLFeature feature) {
addBiomeFeature(biome, feature.getDecoration(), feature.getPlacedFeature());
}
@ -633,7 +642,7 @@ public class BiomeAPI {
* @param step a {@link Decoration} step for the feature.
* @param featureList {@link ConfiguredFeature} to add.
*/
public static void addBiomeFeature(Biome biome, Decoration step, PlacedFeature... featureList) {
public static void addBiomeFeature(Holder<Biome> biome, Decoration step, Holder<PlacedFeature>... featureList) {
addBiomeFeature(biome, step, List.of(featureList));
}
@ -643,12 +652,13 @@ public class BiomeAPI {
* @param step a {@link Decoration} step for the feature.
* @param featureList List of {@link ConfiguredFeature} to add.
*/
private static void addBiomeFeature(Biome biome, Decoration step, List<PlacedFeature> featureList) {
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
private static void addBiomeFeature(Holder<Biome> biome, Decoration step, List<Holder<PlacedFeature>> featureList) {
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings();
List<HolderSet<PlacedFeature>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get());
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
HolderSet<PlacedFeature> features = getFeaturesList(allFeatures, step);
for (var feature : featureList) {
features.
features.add(() -> feature);
set.add(feature);
}
@ -659,13 +669,13 @@ public class BiomeAPI {
/**
* For internal use only!
*
* Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Biome)} when the Biome is
* Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Holder)}} when the Biome is
* present in any {@link BiomeSource}
* @param biome {@link Biome} to add features in.
* @param featureMap Map of {@link ConfiguredFeature} to add.
*/
private static void addStepFeaturesToBiome(Biome biome, Map<Decoration, List<Supplier<PlacedFeature>>> featureMap) {
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
private static void addStepFeaturesToBiome(Holder<Biome> biome, Map<Decoration, List<Supplier<PlacedFeature>>> featureMap) {
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings();
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get());
@ -690,8 +700,8 @@ public class BiomeAPI {
*/
public static void addBiomeCarver(Biome biome, ConfiguredWorldCarver carver, Carving stage) {
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
Map<Carving, List<Supplier<ConfiguredWorldCarver<?>>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
List<Supplier<ConfiguredWorldCarver<?>>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>()));
Map<Carving, HolderSet<ConfiguredWorldCarver<?>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers());
HolderSet<ConfiguredWorldCarver<?>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>()));
carvers.put(stage, carverList);
carverList.add(() -> carver);
accessor.bclib_setCarvers(carvers);
@ -769,6 +779,10 @@ public class BiomeAPI {
return findTopMaterial(getBiome(world.getBiome(pos)));
}
public static Optional<BlockState> findTopMaterial(Holder<Biome> biome){
return findTopMaterial(getBiome(biome.value()));
}
public static Optional<BlockState> findTopMaterial(Biome biome){
return findTopMaterial(getBiome(biome));
}
@ -784,6 +798,10 @@ public class BiomeAPI {
return findUnderMaterial(getBiome(world.getBiome(pos)));
}
public static Optional<BlockState> findUnderMaterial(Holder<Biome> biome){
return findUnderMaterial(getBiome(biome.value()));
}
public static Optional<BlockState> findUnderMaterial(Biome biome){
return findUnderMaterial(getBiome(biome));
}
@ -887,12 +905,12 @@ public class BiomeAPI {
return list;
}
private static List<Supplier<PlacedFeature>> getFeaturesList(List<List<Supplier<PlacedFeature>>> features, Decoration step) {
private static HolderSet<PlacedFeature> getFeaturesList(List<HolderSet<PlacedFeature>> features, Decoration step) {
int index = step.ordinal();
while (features.size() <= index) {
features.add(Lists.newArrayList());
features.add(HolderSet.direct(Lists.newArrayList()));
}
List<Supplier<PlacedFeature>> mutable = CollectionsUtil.getMutable(features.get(index));
HolderSet<PlacedFeature> mutable = features.get(index);
features.set(index, mutable);
return mutable;
}

View file

@ -75,7 +75,7 @@ public class SurfaceRuleBuilder {
public SurfaceRuleBuilder subsurface(BlockState state, int depth) {
entryInstance = getFromCache("subsurface_" + depth + "_" + state.toString(), () -> {
RuleSource rule = SurfaceRules.state(state);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule);
return new SurfaceRuleEntry(3, rule);
});
rules.add(entryInstance);
@ -117,7 +117,7 @@ public class SurfaceRuleBuilder {
public SurfaceRuleBuilder belowFloor(BlockState state, int height, NoiseCondition noise) {
entryInstance = getFromCache("below_floor_" + height + "_" + state.toString() + "_" + noise.getClass().getSimpleName(), () -> {
RuleSource rule = SurfaceRules.state(state);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule));
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule));
return new SurfaceRuleEntry(3, rule);
});
rules.add(entryInstance);
@ -133,7 +133,7 @@ public class SurfaceRuleBuilder {
public SurfaceRuleBuilder belowFloor(BlockState state, int height) {
entryInstance = getFromCache("below_floor_" + height + "_" + state.toString(), () -> {
RuleSource rule = SurfaceRules.state(state);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), rule);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), rule);
return new SurfaceRuleEntry(3, rule);
});
rules.add(entryInstance);
@ -163,7 +163,7 @@ public class SurfaceRuleBuilder {
public SurfaceRuleBuilder aboveCeil(BlockState state, int height) {
entryInstance = getFromCache("above_ceil_" + height + "_" + state.toString(), () -> {
RuleSource rule = SurfaceRules.state(state);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.CEILING), rule);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.CEILING), rule);
return new SurfaceRuleEntry(3, rule);
});
rules.add(entryInstance);
@ -179,7 +179,7 @@ public class SurfaceRuleBuilder {
public SurfaceRuleBuilder steep(BlockState state, int depth) {
entryInstance = getFromCache("steep_" + depth + "_" + state.toString(), () -> {
RuleSource rule = SurfaceRules.state(state);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule);
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule);
rule = SurfaceRules.ifTrue(SurfaceRules.steep(), rule);
int priority = depth < 1 ? 0 : 1;
return new SurfaceRuleEntry(priority, rule);

View file

@ -39,7 +39,8 @@ public class BaseCropBlock extends BasePlantBlock {
public BaseCropBlock(Item drop, Block... terrain) {
this(
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission(),

View file

@ -31,6 +31,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.items.tool.BaseShearsItem;
import ru.bclib.util.BlocksHelper;
import java.util.List;
@ -54,7 +55,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
public BaseDoublePlantBlock(int light) {
this(
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
.noCollission()
@ -117,7 +119,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
}
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
//TODO: 1.18.2 Test if shearing still works
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -39,6 +39,7 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseShearsItem;
import java.util.List;
import java.util.Optional;
@ -70,7 +71,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
this(
FabricBlockSettings
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission()
@ -116,7 +118,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
//TODO: 1.18.2 Test if shearing still works
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -20,7 +20,8 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public BasePlantWithAgeBlock() {
this(
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission()

View file

@ -18,7 +18,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im
this(
FabricBlockSettings
.of(Material.WATER_PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission()
);
@ -28,7 +29,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im
this(
FabricBlockSettings
.of(Material.WATER_PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission()

View file

@ -30,6 +30,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.blocks.BlockProperties.TripleShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.items.tool.BaseShearsItem;
import ru.bclib.util.BlocksHelper;
import java.util.List;
@ -110,7 +111,8 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
//TODO: Test if shearing still works
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -39,7 +39,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
this(
FabricBlockSettings
.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission()
);
@ -49,7 +50,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
this(
FabricBlockSettings
.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission()

View file

@ -44,7 +44,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv
public FeatureSaplingBlock(Function<BlockState, Feature<?>> featureSupplier) {
this(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.collidable(false)
.instabreak()
.sound(SoundType.GRASS)
@ -55,7 +56,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv
public FeatureSaplingBlock(int light, Function<BlockState, Feature<?>> featureSupplier) {
this(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.collidable(false)
.luminance(light)
.instabreak()

View file

@ -35,6 +35,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseShearsItem;
import java.util.List;
import java.util.Random;
@ -57,7 +58,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
this(
FabricBlockSettings
.of(Material.WATER_PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission()
@ -105,7 +107,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
//TODO: Test is shearing still works
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -20,7 +20,8 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
super(
FabricBlockSettings
.of(Material.WATER_PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//.breakByHand(true)
.sound(SoundType.WET_GRASS)
.randomTicks()
.noCollission()

View file

@ -29,6 +29,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseShearsItem;
import java.util.List;
@ -83,7 +84,8 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
//TODO: 1.18.2 Test if shearing still works
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -19,7 +19,8 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock {
this(
FabricBlockSettings
.of(Material.PLANT)
.breakByHand(true)
//TODO: 1.18.2 Check if this is still ok
//..breakByHand(true)
.luminance(light)
.destroyTime(0.2F)
.sound(SoundType.GRASS)

View file

@ -108,12 +108,12 @@ public class CustomFogRenderer {
}
private static boolean shouldIgnore(Level level, int x, int y, int z) {
Biome biome = level.getBiome(MUT_POS.set(x, y, z));
Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value();
return BiomeAPI.getRenderBiome(biome) == BiomeAPI.EMPTY_BIOME;
}
private static float getFogDensityI(Level level, int x, int y, int z) {
Biome biome = level.getBiome(MUT_POS.set(x, y, z));
Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value();
BCLBiome renderBiome = BiomeAPI.getRenderBiome(biome);
return renderBiome.getFogDensity();
}

View file

@ -1,6 +1,7 @@
package ru.bclib.integration;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
@ -38,6 +39,10 @@ public abstract class ModIntegration {
return new ResourceLocation(modID, name);
}
public ResourceKey<PlacedFeature> getFeatureKey(String name) {
return ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, getID(name));
}
public Block getBlock(String name) {
return Registry.BLOCK.get(getID(name));
}
@ -61,7 +66,7 @@ public abstract class ModIntegration {
public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) {
ResourceLocation id = getID(featureID);
Feature<?> feature = Registry.FEATURE.get(id);
PlacedFeature featureConfigured = BuiltinRegistries.PLACED_FEATURE.get(getID(placedFeatureID));
Holder<PlacedFeature> featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null);
return new BCLFeature(id, feature, featureStep, featureConfigured);
}

View file

@ -1,5 +1,6 @@
package ru.bclib.mixin.common;
import net.minecraft.core.HolderSet;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.GenerationStep.Carving;
@ -17,11 +18,11 @@ import java.util.function.Supplier;
@Mixin(BiomeGenerationSettings.class)
public interface BiomeGenerationSettingsAccessor {
@Accessor("features")
List<List<Supplier<PlacedFeature>>> bclib_getFeatures();
List<HolderSet<PlacedFeature>> bclib_getFeatures();
@Accessor("features")
@Mutable
void bclib_setFeatures(List<List<Supplier<PlacedFeature>>> value);
void bclib_setFeatures(List<HolderSet<PlacedFeature>> value);
@Accessor("featureSet")
Supplier<Set<PlacedFeature>> bclib_getFeatureSet();
@ -30,8 +31,8 @@ public interface BiomeGenerationSettingsAccessor {
void bclib_setFeatureSet(Supplier<Set<PlacedFeature>> features);
@Accessor("carvers")
Map<Carving, List<Supplier<ConfiguredWorldCarver<?>>>> bclib_getCarvers();
Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> bclib_getCarvers();
@Accessor("carvers")
void bclib_setCarvers(Map<GenerationStep.Carving, List<Supplier<ConfiguredWorldCarver<?>>>> features);
void bclib_setCarvers(Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> features);
}

View file

@ -1,5 +1,6 @@
package ru.bclib.mixin.common;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
@ -9,6 +10,7 @@ import net.minecraft.world.level.CustomSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WritableLevelData;
@ -28,12 +30,12 @@ import java.util.function.Supplier;
public abstract class ServerLevelMixin extends Level {
private static String bclib_lastWorld = null;
protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l) {
protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, Holder<DimensionType> dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l) {
super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l);
}
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List<CustomSpawner> list, boolean bl2, CallbackInfo info) {
private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, Holder<DimensionType> dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List list, boolean bl2, CallbackInfo ci) {
ServerLevel level = ServerLevel.class.cast(this);
LifeCycleAPI._runLevelLoad(level, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2);

View file

@ -5,11 +5,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.NonNullList;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
@ -116,7 +118,8 @@ public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory
public boolean matches(Container craftingInventory) {
ItemStack hammer = craftingInventory.getItem(1);
if (hammer.isEmpty() || !CommonItemTags.HAMMERS.contains(hammer.getItem())) {
//TODO: 1.18.2 Test if hammer still works
if (hammer.isEmpty() || !hammer.is(CommonItemTags.HAMMERS)) {
return false;
}
ItemStack material = craftingInventory.getItem(0);
@ -209,7 +212,7 @@ public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory
return this;
}
public Builder setInput(Tag<Item> inputTag) {
public Builder setInput(TagKey<Item> inputTag) {
this.setInput(Ingredient.of(inputTag));
return this;
}

View file

@ -4,6 +4,7 @@ import com.google.common.collect.Maps;
import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
@ -74,7 +75,7 @@ public class GridRecipe {
return this;
}
public GridRecipe addMaterial(char key, Tag<Item> value) {
public GridRecipe addMaterial(char key, TagKey<Item> value) {
return addMaterial(key, Ingredient.of(value));
}

View file

@ -2,6 +2,7 @@ package ru.bclib.recipes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
@ -59,7 +60,7 @@ public class SmithingTableRecipe {
return this;
}
public SmithingTableRecipe setBase(Tag<Item> tag) {
public SmithingTableRecipe setBase(TagKey<Item> tag) {
this.base = (Ingredient.of(tag));
return this;
}
@ -70,7 +71,7 @@ public class SmithingTableRecipe {
return this;
}
public SmithingTableRecipe setAddition(Tag<Item> tag) {
public SmithingTableRecipe setAddition(TagKey<Item> tag) {
this.addition = (Ingredient.of(tag));
return this;
}

View file

@ -2,6 +2,7 @@ package ru.bclib.world.biomes;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
@ -31,9 +32,9 @@ public class BCLBiome extends BCLBiomeSettings {
private final ResourceLocation biomeID;
private final Biome biome;
private Consumer<Biome> surfaceInit;
private Consumer<Holder<Biome>> surfaceInit;
private BCLBiome biomeParent;
private Biome actualBiome;
private Holder<Biome> actualBiome;
/**
* Create wrapper for existing biome using its {@link ResourceLocation} identifier.
@ -65,7 +66,7 @@ public class BCLBiome extends BCLBiomeSettings {
* @param settings The Settings for this Biome or {@code null} if you want to apply default settings
*/
public BCLBiome(Biome biome, VanillaBiomeSettings settings) {
this(BuiltinRegistries.BIOME.getKey(biome), biome, settings);
this(BiomeAPI.getBiomeID(biome), biome, settings);
}
public BCLBiome(ResourceLocation biomeID, Biome biome) {
@ -165,6 +166,9 @@ public class BCLBiome extends BCLBiomeSettings {
}
public Holder<Biome> getBiomeHolder() {
return BuiltinRegistries.BIOME.getOrCreateHolder(BiomeAPI.getBiomeKey(biome));
}
/**
* Getter for biome from buil-in registry. For datapack biomes will be same as actual biome.
* @return {@link Biome}.
@ -177,7 +181,7 @@ public class BCLBiome extends BCLBiomeSettings {
* Getter for actual biome (biome from current world registry with same {@link ResourceLocation} id).
* @return {@link Biome}.
*/
public Biome getActualBiome() {
public Holder<Biome> getActualBiome() {
return this.actualBiome;
}
@ -196,7 +200,7 @@ public class BCLBiome extends BCLBiomeSettings {
if (edge != null && edge != this) {
edge.updateActualBiomes(biomeRegistry);
}
this.actualBiome = biomeRegistry.get(biomeID);
this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null);
if (actualBiome==null) {
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
}

View file

@ -5,32 +5,25 @@ import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
import ru.bclib.api.features.BCLCommonFeatures;
import java.util.Map.Entry;
import java.util.Optional;
public class BCLFeature {
private PlacedFeature placedFeature;
private Holder<PlacedFeature> placedFeature;
private Decoration featureStep;
private Feature<?> feature;
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, PlacedFeature placedFeature) {
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, Holder<PlacedFeature> placedFeature) {
this.placedFeature = placedFeature;
this.featureStep = featureStep;
this.feature = feature;
if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature);
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value());
}
if (!Registry.FEATURE.containsKey(id) && !containsObj(Registry.FEATURE, feature)) {
Registry.register(Registry.FEATURE, id, feature);
@ -58,7 +51,7 @@ public class BCLFeature {
* Get configured feature.
* @return {@link PlacedFeature}.
*/
public PlacedFeature getPlacedFeature() {
public Holder<PlacedFeature> getPlacedFeature() {
return placedFeature;
}
@ -69,92 +62,4 @@ public class BCLFeature {
public Decoration getDecoration() {
return featureStep;
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
return BCLCommonFeatures.makeVegetationFeature(id, feature, density);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density, boolean allHeight) {
return BCLCommonFeatures.makeVegetationFeature(id, feature, density, allHeight);
}
/**
* Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) {
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, HeightRangePlacement.uniform(minY, maxY), rare);
}
/**
* Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) {
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, HeightRangePlacement.uniform(minY, maxY), rare);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, PlacementModifier placement, boolean rare) {
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, placement, rare);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, PlacementModifier placement, boolean rare) {
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, placement, rare);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature) {
return BCLCommonFeatures.makeChunkFeature(id, step, feature);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int chance) {
return BCLCommonFeatures.makeChancedFeature(id, step, feature, chance);
}
/**
* Deprecated, use function from {@link BCLCommonFeatures} instead.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int count) {
return BCLCommonFeatures.makeCountFeature(id, step, feature, count);
}
/**
* Deprecated, use {@link ru.bclib.api.features.BCLFeatureBuilder} instead.
*
* Creates and configures new BCLib feature.
* @param id {@link ResourceLocation} feature ID.
* @param step {@link Decoration} feature step.
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
* @param placementModifiers array of {@link PlacementModifier}
* @return new BCLFeature instance.
*/
@Deprecated(forRemoval = true)
public static BCLFeature makeFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, PlacementModifier... placementModifiers) {
PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(placementModifiers);
return new BCLFeature(id, feature, step, configured);
}
}

View file

@ -3,6 +3,7 @@ package ru.bclib.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
@ -50,7 +51,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
protected abstract void addStructureData(StructurePlaceSettings data);
protected BlockPos getGround(WorldGenLevel world, BlockPos center) {
Biome biome = world.getBiome(center);
Holder<Biome> biome = world.getBiome(center);
ResourceLocation id = BiomeAPI.getBiomeID(biome);
if (id.getNamespace().contains("moutain") || id.getNamespace().contains("lake")) {
int y = getAverageY(world, center);
@ -148,7 +149,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
if (!isTerrain(stateSt)) {
if (merge == TerrainMerge.SURFACE) {
boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
Biome b = world.getBiome(mut);
Holder<Biome> b = world.getBiome(mut);
BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, top);
}
@ -159,7 +160,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
else {
if (isTerrain(state) && state.getMaterial().isSolidBlocking()) {
if (merge == TerrainMerge.SURFACE) {
Biome b = world.getBiome(mut);
Holder<Biome> b = world.getBiome(mut);
BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, bottom);
}

View file

@ -1,5 +1,6 @@
package ru.bclib.world.generator;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
@ -8,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI;
import java.util.List;
public abstract class BCLBiomeSource extends BiomeSource {
protected final Registry<Biome> biomeRegistry;
protected final Registry<Holder<Biome>> biomeRegistry;
protected final long seed;
private static List<Biome> preInit(Registry<Biome> biomeRegistry, List<Biome> biomes){
private static List<Holder<Biome>> preInit(Registry<Holder<Biome>> biomeRegistry, List<Holder<Biome>> biomes){
biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome));
return biomes;
}
protected BCLBiomeSource(Registry<Biome> biomeRegistry, long seed, List<Biome> list) {
protected BCLBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed, List<Holder<Biome>> list) {
super(preInit(biomeRegistry, list));
this.seed = seed;

View file

@ -2,6 +2,7 @@ package ru.bclib.world.generator;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceLocation;
@ -19,6 +20,7 @@ import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.mixin.common.BiomeAccessor;
import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.map.hex.HexBiomeMap;
@ -29,14 +31,14 @@ import java.util.List;
import java.util.function.Function;
public class BCLibEndBiomeSource extends BCLBiomeSource {
public static final Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps
public static Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps
.retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new)));
private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324);
private Function<Point, Boolean> endLandFunction;
private final SimplexNoise noise;
private final Biome centerBiome;
private final Biome barrens;
private final Holder<Biome> centerBiome;
private final Holder<Biome> barrens;
private BiomeMap mapLand;
private BiomeMap mapVoid;
private final Point pos;
@ -49,7 +51,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue();
this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome);
ResourceLocation key = biomeRegistry.getKey(biome.value());
String group = key.getNamespace() + "." + key.getPath();
if (!BiomeAPI.hasBiome(key)) {
@ -94,8 +96,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
}
this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END);
this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS);
this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END);
this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS);
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed));
chunkRandom.consumeCount(17292);
@ -116,9 +118,15 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
return true;
}
if (GeneratorOptions.addEndBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.THEEND) {
final boolean isEndBiome;
if ((Object)biome instanceof BiomeAccessor bacc) {
isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND;
if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) {
return true;
}
} else {
isEndBiome = false;
}
BCLBiome bclBiome = BiomeAPI.getBiome(key);
if (bclBiome != BiomeAPI.EMPTY_BIOME) {
@ -127,12 +135,12 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
}
key = bclBiome.getID();
}
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.THEEND && BiomeAPI.isDatapackBiome(key));
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key));
}).toList();
}
@Override
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
long posX = biomeX << 2;
long posZ = biomeZ << 2;
long farEndBiomes = GeneratorOptions.getFarEndBiomes();

View file

@ -71,7 +71,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
BiomeAPI.NETHER_BIOME_PICKER.clearMutables();
this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome);
ResourceLocation key = biomeRegistry.getKey(biome.value());
if (!BiomeAPI.hasBiome(key)) {
BCLBiome bclBiome = new BCLBiome(key, biome);

View file

@ -94,7 +94,7 @@ public class BCLStructureFeature {
return structure;
}
public ConfiguredStructureFeature<?, ?> getFeatureConfigured() {
public Holder<ConfiguredStructureFeature<?, ?>> getFeatureConfigured() {
return featureConfigured;
}