Skip to content

Commit b73b564

Browse files
Merge branch 'master' into 1.21.2
2 parents e174d72 + 399ad70 commit b73b564

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Put changelog here:
1818
- Added the `CapeRegistry` class which can be used to register custom capes.
1919
- Currently, these capes can only be accessed through FrozenLib's config.
2020
- An optional list of allowed UUIDs can be defined for capes.
21+
- Fixed the `ColumnWithDiskFeature` not generating as intended.

src/main/java/net/frozenblock/lib/worldgen/feature/api/features/ColumnWithDiskFeature.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
import java.util.Optional;
2222
import net.frozenblock.lib.worldgen.feature.api.features.config.ColumnWithDiskFeatureConfig;
2323
import net.minecraft.core.BlockPos;
24+
import net.minecraft.core.Direction;
2425
import net.minecraft.core.Holder;
2526
import net.minecraft.util.RandomSource;
27+
import net.minecraft.util.valueproviders.UniformInt;
2628
import net.minecraft.world.level.WorldGenLevel;
2729
import net.minecraft.world.level.block.Block;
28-
import net.minecraft.world.level.block.Blocks;
29-
import net.minecraft.world.level.block.BushBlock;
30-
import net.minecraft.world.level.block.GrowingPlantBodyBlock;
3130
import net.minecraft.world.level.block.state.BlockState;
3231
import net.minecraft.world.level.levelgen.Heightmap.Types;
3332
import net.minecraft.world.level.levelgen.feature.Feature;
@@ -46,70 +45,69 @@ public boolean place(@NotNull FeaturePlaceContext<ColumnWithDiskFeatureConfig> c
4645
ColumnWithDiskFeatureConfig config = context.config();
4746
BlockPos blockPos = context.origin();
4847
WorldGenLevel level = context.level();
49-
BlockPos s = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
48+
BlockPos surfacePos = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
5049
RandomSource random = level.getRandom();
5150
int radius = config.radius().sample(random);
5251
Optional<Holder<Block>> diskOptional = config.diskBlocks().getRandomElement(random);
5352
// DISK
5453
if (diskOptional.isPresent()) {
55-
BlockPos.MutableBlockPos mutableDisk = s.mutable();
54+
BlockPos.MutableBlockPos mutableDisk = surfacePos.mutable();
5655
BlockState disk = diskOptional.get().value().defaultBlockState();
57-
int bx = s.getX();
58-
int bz = s.getZ();
56+
int bx = surfacePos.getX();
57+
int bz = surfacePos.getZ();
5958
for (int x = bx - radius; x <= bx + radius; x++) {
6059
for (int z = bz - radius; z <= bz + radius; z++) {
6160
double distance = ((bx - x) * (bx - x) + ((bz - z) * (bz - z)));
6261
if (distance < radius * radius) {
6362
mutableDisk.set(x, level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, x, z) - 1, z);
64-
boolean fade = !mutableDisk.closerThan(s, radius * 0.8);
63+
boolean fade = !mutableDisk.closerThan(surfacePos, radius * 0.8D);
6564
if (level.getBlockState(mutableDisk).is(config.replaceableBlocks())) {
6665
generated = true;
6766
if (fade) {
6867
if (random.nextFloat() > 0.65F) {
69-
level.setBlock(mutableDisk, disk, 3);
68+
level.setBlock(mutableDisk, disk, Block.UPDATE_ALL);
7069
}
7170
} else {
72-
level.setBlock(mutableDisk, disk, 3);
71+
level.setBlock(mutableDisk, disk, Block.UPDATE_ALL);
7372
}
7473
}
7574
}
7675
}
7776
}
7877
}
7978
// COLUMN
80-
BlockPos startPos = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
81-
BlockState column = config.state();
82-
BlockPos.MutableBlockPos pos = startPos.mutable();
83-
for (int i = 0; i < config.height().sample(random); i++) {
84-
pos.set(pos.above());
85-
BlockState state = level.getBlockState(pos);
86-
if (level.getBlockState(pos.below()).is(Blocks.WATER)) {
87-
break;
88-
}
89-
if (state.getBlock() instanceof GrowingPlantBodyBlock || state.getBlock() instanceof BushBlock || state.isAir()) {
90-
level.setBlock(pos, column, 3);
91-
generated = true;
79+
BlockState columnState = config.state();
80+
BlockPos.MutableBlockPos mutablePos = blockPos.mutable();
81+
int pillarHeight = config.height().sample(random);
82+
generated = placeAtPos(level, blockPos, mutablePos, columnState, pillarHeight) || generated;
83+
84+
int maxSurroundingPillarHeight = pillarHeight - 1;
85+
if (maxSurroundingPillarHeight > 0) {
86+
for (Direction direction : Direction.Plane.HORIZONTAL) {
87+
if (random.nextFloat() < config.surroundingPillarChance()) {
88+
generated = placeAtPos(level, blockPos.relative(direction), mutablePos, columnState, UniformInt.of(1, maxSurroundingPillarHeight).sample(random)) || generated;
89+
}
9290
}
9391
}
94-
startPos = startPos.offset(-1, 0, 0);
95-
generated = generated || place(config, level, random, startPos, column, pos);
96-
startPos = startPos.offset(1, 0, 1);
97-
generated = generated || place(config, level, random, startPos, column, pos);
9892
return generated;
9993
}
10094

101-
private boolean place(@NotNull ColumnWithDiskFeatureConfig config, @NotNull WorldGenLevel level, RandomSource random, @NotNull BlockPos startPos, BlockState column, BlockPos.@NotNull MutableBlockPos pos) {
95+
private boolean placeAtPos(
96+
@NotNull WorldGenLevel level,
97+
@NotNull BlockPos startPos,
98+
BlockPos.@NotNull MutableBlockPos mutablePos,
99+
BlockState columnState,
100+
int height
101+
) {
102102
boolean generated = false;
103-
pos.set(startPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, startPos.getX(), startPos.getZ()) - 1).mutable());
104-
for (int i = 0; i < config.additionalHeight().sample(random); i++) {
105-
pos.set(pos.above());
106-
BlockState state = level.getBlockState(pos);
107-
if (level.getBlockState(pos.below()).is(Blocks.WATER)) {
108-
break;
109-
}
110-
if (state.getBlock() instanceof GrowingPlantBodyBlock || state.getBlock() instanceof BushBlock || state.isAir()) {
111-
level.setBlock(pos, column, 3);
112-
generated = true;
103+
mutablePos.set(startPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, startPos.getX(), startPos.getZ()) - 1));
104+
if (level.getBlockState(mutablePos).getFluidState().isEmpty()) {
105+
for (int i = 0; i < height; i++) {
106+
BlockState state = level.getBlockState(mutablePos.move(Direction.UP));
107+
if (state.canBeReplaced()) {
108+
level.setBlock(mutablePos, columnState, Block.UPDATE_ALL);
109+
generated = true;
110+
}
113111
}
114112
}
115113
return generated;

src/main/java/net/frozenblock/lib/worldgen/feature/api/features/config/ColumnWithDiskFeatureConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
import net.minecraft.world.level.block.state.BlockState;
2828
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
2929

30-
public record ColumnWithDiskFeatureConfig(BlockState state, IntProvider radius, IntProvider height,
31-
IntProvider additionalHeight, HolderSet<Block> replaceableBlocks,
32-
HolderSet<Block> diskBlocks) implements FeatureConfiguration {
30+
public record ColumnWithDiskFeatureConfig(
31+
BlockState state, IntProvider radius, IntProvider height, float surroundingPillarChance, HolderSet<Block> replaceableBlocks, HolderSet<Block> diskBlocks
32+
) implements FeatureConfiguration {
3333
public static final Codec<ColumnWithDiskFeatureConfig> CODEC = RecordCodecBuilder.create((instance) ->
3434
instance.group(
3535
BlockState.CODEC.fieldOf("state").forGetter((config) -> config.state),
3636
IntProvider.NON_NEGATIVE_CODEC.fieldOf("radius").forGetter((config) -> config.radius),
3737
IntProvider.NON_NEGATIVE_CODEC.fieldOf("height").forGetter((config) -> config.height),
38-
IntProvider.NON_NEGATIVE_CODEC.fieldOf("additional_height").forGetter((config) -> config.additionalHeight),
38+
Codec.FLOAT.fieldOf("surrounding_pillar_chance").forGetter((config) -> config.surroundingPillarChance),
3939
RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("replaceable_blocks").forGetter((config) -> config.replaceableBlocks),
4040
RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("disk_blocks").forGetter((config) -> config.diskBlocks)
4141
).apply(instance, ColumnWithDiskFeatureConfig::new));

0 commit comments

Comments
 (0)