diff --git a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLFeatureBuilder.java b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLFeatureBuilder.java index dd53e5bf..cbcc7349 100644 --- a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLFeatureBuilder.java +++ b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLFeatureBuilder.java @@ -44,7 +44,7 @@ import org.jetbrains.annotations.NotNull; @SuppressWarnings("unused") public abstract class BCLFeatureBuilder, FC extends FeatureConfiguration> { - private final ResourceLocation featureID; + protected final ResourceLocation featureID; private final F feature; private BCLFeatureBuilder(ResourceLocation featureID, F feature) { @@ -100,6 +100,22 @@ public abstract class BCLFeatureBuilder, FC extends Featur ); } + public static WeightedBlockPatch startWeightedRandomPatch( + ResourceLocation featureID + ) { + return new WeightedBlockPatch( + featureID, + (RandomPatchFeature) Feature.RANDOM_PATCH + ); + } + + public static WeightedBlockPatch startBonemealPatch( + ResourceLocation featureID + ) { + return startWeightedRandomPatch(featureID).likeDefaultBonemeal(); + } + + public static RandomPatch startRandomPatch( ResourceLocation featureID, Holder featureToPlace @@ -782,9 +798,86 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class WeightedBlock extends BCLFeatureBuilder { - SimpleWeightedRandomList.Builder stateBuilder = SimpleWeightedRandomList.builder(); + public static class WeightedBlockPatch extends WeightedBaseBlock { + private BlockPredicate groundType = null; + private boolean isEmpty = true; + private int tries = 96; + private int xzSpread = 7; + private int ySpread = 3; + + protected WeightedBlockPatch(@NotNull ResourceLocation featureID, @NotNull RandomPatchFeature feature) { + super(featureID, feature); + } + + public WeightedBlockPatch isEmpty() { + return this.isEmpty(true); + } + + public WeightedBlockPatch isEmpty(boolean value) { + this.isEmpty = value; + return this; + } + + public WeightedBlockPatch isOn(BlockPredicate predicate) { + this.groundType = predicate; + return this; + } + + public WeightedBlockPatch isEmptyAndOn(BlockPredicate predicate) { + return this.isEmpty().isOn(predicate); + } + + public WeightedBlockPatch likeDefaultNetherVegetation() { + return likeDefaultNetherVegetation(8, 4); + } + + public WeightedBlockPatch likeDefaultNetherVegetation(int xzSpread, int ySpread) { + this.xzSpread = xzSpread; + this.ySpread = ySpread; + tries = xzSpread * xzSpread; + return this; + } + + public WeightedBlockPatch likeDefaultBonemeal() { + return this.tries(9) + .spreadXZ(3) + .spreadY(1); + } + + public WeightedBlockPatch tries(int v) { + tries = v; + return this; + } + + public WeightedBlockPatch spreadXZ(int v) { + xzSpread = v; + return this; + } + + public WeightedBlockPatch spreadY(int v) { + ySpread = v; + return this; + } + + @Override + public RandomPatchConfiguration createConfiguration() { + BCLInlinePlacedBuilder, SimpleBlockConfiguration> blockFeature = BCLFeatureBuilder + .start( + new ResourceLocation(featureID.getNamespace(), "tmp_" + featureID.getPath()), + Feature.SIMPLE_BLOCK + ) + .configuration(new SimpleBlockConfiguration(new WeightedStateProvider(stateBuilder.build()))) + .inlinePlace(); + + if (isEmpty) blockFeature.isEmpty(); + if (groundType != null) blockFeature.isOn(groundType); + + return new RandomPatchConfiguration(tries, xzSpread, ySpread, blockFeature.build()); + } + } + + public static class WeightedBlock extends WeightedBaseBlock { private WeightedBlock( @NotNull ResourceLocation featureID, @NotNull SimpleBlockFeature feature @@ -792,33 +885,45 @@ public abstract class BCLFeatureBuilder, FC extends Featur super(featureID, feature); } - public WeightedBlock add(Block block, int weight) { - return add(block.defaultBlockState(), weight); - } - - public WeightedBlock add(BlockState state, int weight) { - stateBuilder.add(state, weight); - return this; - } - - public WeightedBlock addAllStates(Block block, int weight) { - Set states = BCLPoiType.getBlockStates(block); - states.forEach(s -> add(block.defaultBlockState(), Math.max(1, weight / states.size()))); - return this; - } - - public WeightedBlock addAllStatesFor(IntegerProperty prop, Block block, int weight) { - Collection values = prop.getPossibleValues(); - values.forEach(s -> add(block.defaultBlockState().setValue(prop, s), Math.max(1, weight / values.size()))); - return this; - } - @Override public SimpleBlockConfiguration createConfiguration() { return new SimpleBlockConfiguration(new WeightedStateProvider(stateBuilder.build())); } } + + private abstract static class WeightedBaseBlock, FC extends FeatureConfiguration, W extends WeightedBaseBlock> extends BCLFeatureBuilder { + SimpleWeightedRandomList.Builder stateBuilder = SimpleWeightedRandomList.builder(); + + protected WeightedBaseBlock( + @NotNull ResourceLocation featureID, + @NotNull F feature + ) { + super(featureID, feature); + } + + public W add(Block block, int weight) { + return add(block.defaultBlockState(), weight); + } + + public W add(BlockState state, int weight) { + stateBuilder.add(state, weight); + return (W) this; + } + + public W addAllStates(Block block, int weight) { + Set states = BCLPoiType.getBlockStates(block); + states.forEach(s -> add(block.defaultBlockState(), Math.max(1, weight / states.size()))); + return (W) this; + } + + public W addAllStatesFor(IntegerProperty prop, Block block, int weight) { + Collection values = prop.getPossibleValues(); + values.forEach(s -> add(block.defaultBlockState().setValue(prop, s), Math.max(1, weight / values.size()))); + return (W) this; + } + } + public static class AsRandomSelect extends BCLFeatureBuilder { private final List features = new LinkedList<>(); private Holder defaultFeature; diff --git a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/CommonPlacedFeatureBuilder.java b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/CommonPlacedFeatureBuilder.java index 781b0218..a668dfd0 100644 --- a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/CommonPlacedFeatureBuilder.java +++ b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/CommonPlacedFeatureBuilder.java @@ -354,6 +354,15 @@ abstract class CommonPlacedFeatureBuilder, FC extends Feat return modifier(Is.below(predicate)); } + + public T inBiomes(ResourceLocation... biomeID) { + return modifier(InBiome.matchingID(biomeID)); + } + + public T notInBiomes(ResourceLocation... biomeID) { + return modifier(InBiome.notMatchingID(biomeID)); + } + public T isEmptyAndOn(BlockPredicate predicate) { return (T) this.isEmpty().isOn(predicate); } diff --git a/src/main/java/org/betterx/bclib/api/v3/tag/BCLBlockTags.java b/src/main/java/org/betterx/bclib/api/v3/tag/BCLBlockTags.java index ca638a64..0f30054b 100644 --- a/src/main/java/org/betterx/bclib/api/v3/tag/BCLBlockTags.java +++ b/src/main/java/org/betterx/bclib/api/v3/tag/BCLBlockTags.java @@ -21,11 +21,18 @@ public class BCLBlockTags { public static final TagKey BONEMEAL_TARGET_END_STONE = TagManager.BLOCKS.makeTogetherTag( "bonemeal/target/end_stone" ); + public static final TagKey BONEMEAL_SOURCE_OBSIDIAN = TagManager.BLOCKS.makeTogetherTag( + "bonemeal/source/obsidian" + ); + public static final TagKey BONEMEAL_TARGET_OBSIDIAN = TagManager.BLOCKS.makeTogetherTag( + "bonemeal/target/obsidian" + ); @ApiStatus.Internal public static void ensureStaticallyLoaded() { TagManager.BLOCKS.add(BONEMEAL_SOURCE_NETHERRACK, Blocks.WARPED_NYLIUM, Blocks.CRIMSON_NYLIUM); TagManager.BLOCKS.add(BONEMEAL_TARGET_NETHERRACK, Blocks.NETHERRACK); TagManager.BLOCKS.add(BONEMEAL_TARGET_END_STONE, Blocks.END_STONE); + TagManager.BLOCKS.add(BONEMEAL_TARGET_OBSIDIAN, Blocks.OBSIDIAN); } }