From 8a416561823bac11cef6fa97d0ef37c1c1e96817 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 18 Jun 2022 20:30:51 +0200 Subject: [PATCH] Started Magma Land Migration --- .../v2/generator/BCLibNetherBiomeSource.java | 2 +- .../features/config/PillarFeatureConfig.java | 31 ++++---- .../features/BCLConfigureFeature.java | 2 +- .../levelgen/features/BCLFeatureBuilder.java | 73 +++++++++++++++++-- .../v3/levelgen/features/BlockPredicates.java | 4 + .../bclib/blocks/BCLBlockProperties.java | 12 --- .../betterx/bclib/blocks/BlockProperties.java | 2 + 7 files changed, 89 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/org/betterx/bclib/blocks/BCLBlockProperties.java 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 21bd09ef..27d02d01 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,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { private static boolean isValidNetherBiome(Holder biome, ResourceLocation location) { - return biome.unwrapKey().get().location().toString().contains("bone_reef"); + return biome.unwrapKey().get().location().toString().contains("magma_land"); // return NetherBiomes.canGenerateInNether(biome.unwrapKey().get()) || // biome.is(BiomeTags.IS_NETHER) || diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/PillarFeatureConfig.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/PillarFeatureConfig.java index 0d853b3c..9c17485e 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/PillarFeatureConfig.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/PillarFeatureConfig.java @@ -1,6 +1,6 @@ package org.betterx.bclib.api.v2.levelgen.features.config; -import org.betterx.bclib.blocks.BCLBlockProperties; +import org.betterx.bclib.blocks.BlockProperties; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; @@ -10,7 +10,6 @@ import net.minecraft.util.RandomSource; import net.minecraft.util.StringRepresentable; import net.minecraft.util.valueproviders.IntProvider; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; @@ -18,19 +17,24 @@ import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvi public class PillarFeatureConfig implements FeatureConfiguration { @FunctionalInterface public interface StateTransform { - int apply(int height, int maxHeight, BlockState inputState, BlockPos pos, RandomSource rnd); + BlockState apply(int height, int maxHeight, BlockState inputState, BlockPos pos, RandomSource rnd); } public enum KnownTransformers implements StringRepresentable { SIZE_DECREASE( "size_decrease", - BCLBlockProperties.SIZE, - (height, maxHeight, state, pos, rnd) -> Math.max(0, Math.min(7, maxHeight - height)) + (height, maxHeight, state, pos, rnd) -> state + .setValue(BlockProperties.SIZE, Math.max(0, Math.min(7, maxHeight - height))) ), SIZE_INCREASE( "size_increase", - BCLBlockProperties.SIZE, - (height, maxHeight, state, pos, rnd) -> Math.max(0, Math.min(7, height)) + (height, maxHeight, state, pos, rnd) -> state + .setValue(BlockProperties.SIZE, Math.max(0, Math.min(7, height))) + ), + BOTTOM_GROW( + "bottom_grow", + (height, maxHeight, state, pos, rnd) -> state + .setValue(BlockProperties.BOTTOM, height == maxHeight) ); @@ -39,13 +43,11 @@ public class PillarFeatureConfig implements FeatureConfiguration { public final String name; - public final IntegerProperty property; - public final StateTransform transform; + public final StateTransform stateTransform; - KnownTransformers(String name, IntegerProperty property, StateTransform transform) { + KnownTransformers(String name, StateTransform stateTransform) { this.name = name; - this.property = property; - this.transform = transform; + this.stateTransform = stateTransform; } @Override @@ -93,9 +95,6 @@ public class PillarFeatureConfig implements FeatureConfiguration { public BlockState transform(int currentHeight, int maxHeight, BlockPos pos, RandomSource rnd) { BlockState state = stateProvider.getState(rnd, pos); - return state.setValue( - transformer.property, - transformer.transform.apply(currentHeight, maxHeight, state, pos, rnd) - ); + return transformer.stateTransform.apply(currentHeight, maxHeight, state, pos, rnd); } } diff --git a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLConfigureFeature.java b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLConfigureFeature.java index b3932c62..07ca36be 100644 --- a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLConfigureFeature.java +++ b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BCLConfigureFeature.java @@ -35,7 +35,7 @@ public class BCLConfigureFeature, FC extends FeatureConfig return place(this.id); } - BCLPlacedFeatureBuilder place(ResourceLocation id) { + public BCLPlacedFeatureBuilder place(ResourceLocation id) { return BCLPlacedFeatureBuilder.place(id, this); } 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 ccb9c381..1404fabf 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 @@ -9,7 +9,6 @@ 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; import org.betterx.bclib.api.v2.poi.BCLPoiType; -import org.betterx.bclib.blocks.BCLBlockProperties; import org.betterx.bclib.blocks.BlockProperties; import net.minecraft.core.Direction; @@ -87,6 +86,16 @@ public abstract class BCLFeatureBuilder, FC extends Featur return builder; } + public static WeightedBlock startWeighted( + ResourceLocation featureID + ) { + WeightedBlock builder = new WeightedBlock( + featureID, + (SimpleBlockFeature) Feature.SIMPLE_BLOCK + ); + return builder; + } + public static RandomPatch startRandomPatch( ResourceLocation featureID, Holder featureToPlace @@ -109,6 +118,7 @@ public abstract class BCLFeatureBuilder, FC extends Featur return builder; } + public static WithTemplates> startWithTemplates( ResourceLocation featureID ) { @@ -382,16 +392,28 @@ public abstract class BCLFeatureBuilder, FC extends Featur public AsBlockColumn addTripleShape(BlockState state, IntProvider midHeight) { return this - .add(1, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.BOTTOM)) - .add(midHeight, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.MIDDLE)) - .add(1, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.TOP)); + .add(1, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.BOTTOM)) + .add(midHeight, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.MIDDLE)) + .add(1, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.TOP)); } public AsBlockColumn addTripleShapeUpsideDown(BlockState state, IntProvider midHeight) { return this - .add(1, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.TOP)) - .add(midHeight, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.MIDDLE)) - .add(1, state.setValue(BCLBlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.BOTTOM)); + .add(1, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.TOP)) + .add(midHeight, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.MIDDLE)) + .add(1, state.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.BOTTOM)); + } + + public AsBlockColumn addBottomShapeUpsideDown(BlockState state, IntProvider midHeight) { + return this + .add(midHeight, state.setValue(BlockProperties.BOTTOM, false)) + .add(1, state.setValue(BlockProperties.BOTTOM, true)); + } + + public AsBlockColumn addBottomShape(BlockState state, IntProvider midHeight) { + return this + .add(1, state.setValue(BlockProperties.BOTTOM, true)) + .add(midHeight, state.setValue(BlockProperties.BOTTOM, false)); } public AsBlockColumn direction(Direction dir) { @@ -593,6 +615,43 @@ public abstract class BCLFeatureBuilder, FC extends Featur return new SimpleBlockConfiguration(provider); } } + + public static class WeightedBlock extends BCLFeatureBuilder { + SimpleWeightedRandomList.Builder stateBuilder = SimpleWeightedRandomList.builder(); + + private WeightedBlock( + @NotNull ResourceLocation featureID, + @NotNull SimpleBlockFeature feature + ) { + 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())); + } + } } diff --git a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BlockPredicates.java b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BlockPredicates.java index 2976af17..583d2dc1 100644 --- a/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BlockPredicates.java +++ b/src/main/java/org/betterx/bclib/api/v3/levelgen/features/BlockPredicates.java @@ -12,4 +12,8 @@ public class BlockPredicates { public static final BlockPredicate ONLY_GROUND = BlockPredicate.matchesTag(CommonBlockTags.TERRAIN); public static final BlockPredicate ONLY_LAVA = BlockPredicate.matchesFluids(Fluids.LAVA); + public static final BlockPredicate ONLY_GROUND_OR_LAVA = BlockPredicate.anyOf( + BlockPredicate.matchesTag(CommonBlockTags.TERRAIN), + BlockPredicate.matchesFluids(Fluids.LAVA) + ); } diff --git a/src/main/java/org/betterx/bclib/blocks/BCLBlockProperties.java b/src/main/java/org/betterx/bclib/blocks/BCLBlockProperties.java deleted file mode 100644 index d793a0ec..00000000 --- a/src/main/java/org/betterx/bclib/blocks/BCLBlockProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.betterx.bclib.blocks; - -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; - -public class BCLBlockProperties { - public static final EnumProperty TRIPLE_SHAPE = BlockProperties.TRIPLE_SHAPE; - public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7); - public static final IntegerProperty AGE_THREE = BlockStateProperties.AGE_2; - public static final IntegerProperty AGE_FOUR = BlockStateProperties.AGE_3; -} diff --git a/src/main/java/org/betterx/bclib/blocks/BlockProperties.java b/src/main/java/org/betterx/bclib/blocks/BlockProperties.java index bc9f423a..13be5a87 100644 --- a/src/main/java/org/betterx/bclib/blocks/BlockProperties.java +++ b/src/main/java/org/betterx/bclib/blocks/BlockProperties.java @@ -24,6 +24,8 @@ public class BlockProperties { public static final IntegerProperty COLOR = IntegerProperty.create("color", 0, 7); public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7); public static final IntegerProperty AGE = BlockStateProperties.AGE_3; + public static final IntegerProperty AGE_THREE = BlockStateProperties.AGE_2; + public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom"); public enum TripleShape implements StringRepresentable { TOP("top", 0), MIDDLE("middle", 1), BOTTOM("bottom", 2);