From d63d773bb841d8dc17b970f3957cfa990e3f31a2 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 19 Jun 2022 01:08:15 +0200 Subject: [PATCH] New Feature Types for builder --- .../v2/generator/BCLibNetherBiomeSource.java | 4 +- .../levelgen/features/BCLFeatureBuilder.java | 165 +++++++++++++----- .../features/CommonPlacedFeatureBuilder.java | 15 +- 3 files changed, 131 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java index 27d02d01..d453e3c2 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java @@ -147,7 +147,9 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { private static boolean isValidNetherBiome(Holder biome, ResourceLocation location) { - return biome.unwrapKey().get().location().toString().contains("magma_land"); + return biome.unwrapKey().get().location().toString().equals("betternether:crimson_glowing_woods") + || biome.unwrapKey().get().location().toString().equals("minecraft:crimson_forest") + || biome.unwrapKey().get().location().toString().equals("betternether:crimson_pinewood"); // return NetherBiomes.canGenerateInNether(biome.unwrapKey().get()) || // biome.is(BiomeTags.IS_NETHER) || 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 1404fabf..73748a6d 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 @@ -2,9 +2,12 @@ package org.betterx.bclib.api.v3.levelgen.features; import org.betterx.bclib.api.v2.levelgen.features.BCLFeature; import org.betterx.bclib.api.v2.levelgen.features.config.PillarFeatureConfig; +import org.betterx.bclib.api.v2.levelgen.features.config.PlaceFacingBlockConfig; import org.betterx.bclib.api.v2.levelgen.features.config.SequenceFeatureConfig; import org.betterx.bclib.api.v2.levelgen.features.config.TemplateFeatureConfig; import org.betterx.bclib.api.v2.levelgen.features.features.PillarFeature; +import org.betterx.bclib.api.v2.levelgen.features.features.PlaceBlockFeature; +import org.betterx.bclib.api.v2.levelgen.features.features.SequenceFeature; import org.betterx.bclib.api.v2.levelgen.features.features.TemplateFeature; import org.betterx.bclib.api.v2.levelgen.structures.StructurePlacementType; import org.betterx.bclib.api.v2.levelgen.structures.StructureWorldNBT; @@ -25,6 +28,7 @@ import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; import net.minecraft.world.level.levelgen.feature.*; import net.minecraft.world.level.levelgen.feature.configurations.*; import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; +import net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider; import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; @@ -57,118 +61,118 @@ public abstract class BCLFeatureBuilder, FC extends Featur ResourceLocation featureID, F feature ) { - return new WithConfiguration(featureID, feature); + return new WithConfiguration<>(featureID, feature); } - public static ForSimpleBlock start( + public static ForSimpleBlock start( ResourceLocation featureID, Block block ) { return start(featureID, BlockStateProvider.simple(block)); } - public static ForSimpleBlock start( + public static ForSimpleBlock start( ResourceLocation featureID, BlockState state ) { return start(featureID, BlockStateProvider.simple(state)); } - public static ForSimpleBlock start( + public static ForSimpleBlock start( ResourceLocation featureID, BlockStateProvider provider ) { - ForSimpleBlock builder = new ForSimpleBlock( + return new ForSimpleBlock( featureID, - Feature.SIMPLE_BLOCK, + (SimpleBlockFeature) Feature.SIMPLE_BLOCK, provider ); - return builder; } public static WeightedBlock startWeighted( ResourceLocation featureID ) { - WeightedBlock builder = new WeightedBlock( + return new WeightedBlock( featureID, (SimpleBlockFeature) Feature.SIMPLE_BLOCK ); - return builder; } public static RandomPatch startRandomPatch( ResourceLocation featureID, Holder featureToPlace ) { - RandomPatch builder = new RandomPatch( + return new RandomPatch( featureID, - Feature.RANDOM_PATCH, + (RandomPatchFeature) Feature.RANDOM_PATCH, featureToPlace ); - return builder; } public static NetherForrestVegetation startNetherVegetation( ResourceLocation featureID ) { - NetherForrestVegetation builder = new NetherForrestVegetation( + return new NetherForrestVegetation( featureID, - Feature.NETHER_FOREST_VEGETATION + (NetherForestVegetationFeature) Feature.NETHER_FOREST_VEGETATION ); - return builder; } - public static WithTemplates> startWithTemplates( + public static WithTemplates startWithTemplates( ResourceLocation featureID ) { - WithTemplates> builder = new WithTemplates<>( + return new WithTemplates( featureID, - (TemplateFeature) org.betterx.bclib.api.v3.levelgen.features.BCLFeature.TEMPLATE + (TemplateFeature) BCLFeature.TEMPLATE ); - return builder; } public static AsBlockColumn startColumn( ResourceLocation featureID ) { - AsBlockColumn builder = new AsBlockColumn<>( + return new AsBlockColumn<>( featureID, (BlockColumnFeature) Feature.BLOCK_COLUMN ); - return builder; } public static AsPillar startPillar( ResourceLocation featureID, PillarFeatureConfig.KnownTransformers transformer ) { - AsPillar builder = new AsPillar( + return new AsPillar( featureID, (PillarFeature) BCLFeature.PILLAR, transformer ); - return builder; } - public static AsSequence> startSequence( + public static AsSequence startSequence( ResourceLocation featureID ) { - AsSequence> builder = new AsSequence<>( + return new AsSequence( featureID, - org.betterx.bclib.api.v3.levelgen.features.BCLFeature.SEQUENCE + (SequenceFeature) BCLFeature.SEQUENCE ); - return builder; } public static AsOre startOre( ResourceLocation featureID ) { - AsOre builder = new AsOre( + return new AsOre( featureID, (OreFeature) Feature.ORE ); - return builder; + } + + public static FacingBlock startFacing( + ResourceLocation featureID + ) { + return new FacingBlock( + featureID, + (PlaceBlockFeature) BCLFeature.PLACE_BLOCK + ); } /** @@ -199,7 +203,7 @@ public abstract class BCLFeatureBuilder, FC extends Featur if (config == null) { throw new IllegalStateException("Feature configuration for " + featureID + " can not be null!"); } - ConfiguredFeature cFeature = new ConfiguredFeature(feature, config); + ConfiguredFeature cFeature = new ConfiguredFeature<>(feature, config); Holder> holder = holderBuilder.apply(featureID, cFeature); return new BCLConfigureFeature<>(featureID, holder, true); } @@ -268,8 +272,6 @@ public abstract class BCLFeatureBuilder, FC extends Featur } public static class AsPillar extends BCLFeatureBuilder { - private final List> features = new LinkedList<>(); - private IntProvider height; private BlockStateProvider stateProvider; @@ -332,10 +334,10 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class AsSequence> extends BCLFeatureBuilder { + public static class AsSequence extends BCLFeatureBuilder { private final List> features = new LinkedList<>(); - private AsSequence(ResourceLocation featureID, FF feature) { + private AsSequence(ResourceLocation featureID, SequenceFeature feature) { super(featureID, feature); } @@ -441,14 +443,14 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class WithTemplates> extends BCLFeatureBuilder { + public static class WithTemplates extends BCLFeatureBuilder, TemplateFeatureConfig> { private final List templates = new LinkedList<>(); - private WithTemplates(ResourceLocation featureID, FF feature) { + private WithTemplates(ResourceLocation featureID, TemplateFeature feature) { super(featureID, feature); } - public WithTemplates add( + public WithTemplates add( ResourceLocation location, int offsetY, StructurePlacementType type, @@ -464,13 +466,13 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class NetherForrestVegetation> extends BCLFeatureBuilder { + public static class NetherForrestVegetation extends BCLFeatureBuilder { private SimpleWeightedRandomList.Builder blocks; private WeightedStateProvider stateProvider; private int spreadWidth = 8; private int spreadHeight = 4; - private NetherForrestVegetation(ResourceLocation featureID, FF feature) { + private NetherForrestVegetation(ResourceLocation featureID, NetherForestVegetationFeature feature) { super(featureID, feature); } @@ -530,7 +532,7 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class RandomPatch> extends BCLFeatureBuilder { + public static class RandomPatch extends BCLFeatureBuilder { private final Holder featureToPlace; private int tries = 96; private int xzSpread = 7; @@ -538,7 +540,7 @@ public abstract class BCLFeatureBuilder, FC extends Featur private RandomPatch( @NotNull ResourceLocation featureID, - @NotNull FF feature, + @NotNull RandomPatchFeature feature, @NotNull Holder featureToPlace ) { super(featureID, feature); @@ -598,12 +600,89 @@ public abstract class BCLFeatureBuilder, FC extends Featur } } - public static class ForSimpleBlock> extends BCLFeatureBuilder { + public static class FacingBlock extends BCLFeatureBuilder, PlaceFacingBlockConfig> { + private SimpleWeightedRandomList.Builder stateBuilder = SimpleWeightedRandomList.builder(); + BlockState firstState; + private int count = 0; + private List directions = PlaceFacingBlockConfig.HORIZONTAL; + + private FacingBlock(ResourceLocation featureID, PlaceBlockFeature feature) { + super(featureID, feature); + } + + + public FacingBlock allHorizontal() { + directions = PlaceFacingBlockConfig.HORIZONTAL; + return this; + } + + public FacingBlock allVertical() { + directions = PlaceFacingBlockConfig.VERTICAL; + return this; + } + + public FacingBlock allDirections() { + directions = PlaceFacingBlockConfig.ALL; + return this; + } + + public FacingBlock add(Block block) { + return add(block, 1); + } + + public FacingBlock add(BlockState state) { + return this.add(state, 1); + } + + public FacingBlock add(Block block, int weight) { + return add(block.defaultBlockState(), weight); + } + + public FacingBlock add(BlockState state, int weight) { + if (firstState == null) firstState = state; + count++; + stateBuilder.add(state, weight); + return this; + } + + public FacingBlock 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 FacingBlock 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 PlaceFacingBlockConfig createConfiguration() { + BlockStateProvider provider = null; + if (count == 1) { + provider = SimpleStateProvider.simple(firstState); + } else { + SimpleWeightedRandomList list = stateBuilder.build(); + if (!list.isEmpty()) { + provider = new WeightedStateProvider(list); + } + } + + if (provider == null) { + throw new IllegalStateException("Facing Blocks need a State Provider."); + } + return new PlaceFacingBlockConfig(provider, directions); + } + } + + public static class ForSimpleBlock extends BCLFeatureBuilder { private final BlockStateProvider provider; private ForSimpleBlock( @NotNull ResourceLocation featureID, - @NotNull FF feature, + @NotNull SimpleBlockFeature feature, @NotNull BlockStateProvider provider ) { super(featureID, feature); 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 ded3fec9..76cf740c 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 @@ -1,7 +1,6 @@ package org.betterx.bclib.api.v3.levelgen.features; import org.betterx.bclib.api.v2.levelgen.features.config.PlaceFacingBlockConfig; -import org.betterx.bclib.api.v2.levelgen.features.features.SequenceFeature; import org.betterx.bclib.api.v2.levelgen.features.placement.*; import org.betterx.bclib.api.v2.tag.CommonBlockTags; @@ -16,8 +15,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.RandomPatchFeature; -import net.minecraft.world.level.levelgen.feature.SimpleBlockFeature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; import net.minecraft.world.level.levelgen.placement.*; @@ -27,7 +24,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; -abstract class CommonPlacedFeatureBuilder, FC extends FeatureConfiguration, T extends CommonPlacedFeatureBuilder> { +abstract class CommonPlacedFeatureBuilder, FC extends FeatureConfiguration, T extends CommonPlacedFeatureBuilder> { protected final List modifications = new LinkedList<>(); @@ -443,23 +440,23 @@ abstract class CommonPlacedFeatureBuilder, FC extends Feat */ abstract Holder build(); - public BCLFeatureBuilder.RandomPatch inRandomPatch(ResourceLocation id) { + public BCLFeatureBuilder.RandomPatch inRandomPatch(ResourceLocation id) { return BCLFeatureBuilder.startRandomPatch(id, build()); } - public BCLFeatureBuilder.AsSequence then(ResourceLocation id) { + public BCLFeatureBuilder.AsSequence then(ResourceLocation id) { return BCLFeatureBuilder.startSequence(id).add(build()); } - public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, Block block) { + public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, Block block) { return BCLFeatureBuilder.start(id, block); } - public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, BlockState state) { + public BCLFeatureBuilder.ForSimpleBlock putBlock(ResourceLocation id, BlockState state) { return BCLFeatureBuilder.start(id, state); } - public BCLFeatureBuilder.ForSimpleBlock putBlock( + public BCLFeatureBuilder.ForSimpleBlock putBlock( ResourceLocation id, BlockStateProvider provider ) {