Started Magma Land Migration

This commit is contained in:
Frank 2022-06-18 20:30:51 +02:00
parent a1d6de908c
commit 8a41656182
7 changed files with 89 additions and 37 deletions

View file

@ -147,7 +147,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
private static boolean isValidNetherBiome(Holder<Biome> 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) ||

View file

@ -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);
}
}

View file

@ -35,7 +35,7 @@ public class BCLConfigureFeature<F extends Feature<FC>, FC extends FeatureConfig
return place(this.id);
}
BCLPlacedFeatureBuilder<F, FC> place(ResourceLocation id) {
public BCLPlacedFeatureBuilder<F, FC> place(ResourceLocation id) {
return BCLPlacedFeatureBuilder.place(id, this);
}

View file

@ -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<F extends Feature<FC>, 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<PlacedFeature> featureToPlace
@ -109,6 +118,7 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
return builder;
}
public static WithTemplates<Feature<TemplateFeatureConfig>> startWithTemplates(
ResourceLocation featureID
) {
@ -382,16 +392,28 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
public AsBlockColumn<FF> 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<FF> 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<FF> addBottomShapeUpsideDown(BlockState state, IntProvider midHeight) {
return this
.add(midHeight, state.setValue(BlockProperties.BOTTOM, false))
.add(1, state.setValue(BlockProperties.BOTTOM, true));
}
public AsBlockColumn<FF> addBottomShape(BlockState state, IntProvider midHeight) {
return this
.add(1, state.setValue(BlockProperties.BOTTOM, true))
.add(midHeight, state.setValue(BlockProperties.BOTTOM, false));
}
public AsBlockColumn<FF> direction(Direction dir) {
@ -593,6 +615,43 @@ public abstract class BCLFeatureBuilder<F extends Feature<FC>, FC extends Featur
return new SimpleBlockConfiguration(provider);
}
}
public static class WeightedBlock extends BCLFeatureBuilder<SimpleBlockFeature, SimpleBlockConfiguration> {
SimpleWeightedRandomList.Builder<BlockState> 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<BlockState> 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<Integer> 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()));
}
}
}

View file

@ -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)
);
}

View file

@ -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<BlockProperties.TripleShape> 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;
}

View file

@ -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);