Skip to content

Commit

Permalink
Merge branch 'master' into 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Sep 18, 2024
2 parents e174d72 + 399ad70 commit b73b564
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Put changelog here:
- Added the `CapeRegistry` class which can be used to register custom capes.
- Currently, these capes can only be accessed through FrozenLib's config.
- An optional list of allowed UUIDs can be defined for capes.
- Fixed the `ColumnWithDiskFeature` not generating as intended.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import java.util.Optional;
import net.frozenblock.lib.worldgen.feature.api.features.config.ColumnWithDiskFeatureConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.util.RandomSource;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.GrowingPlantBodyBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.Feature;
Expand All @@ -46,70 +45,69 @@ public boolean place(@NotNull FeaturePlaceContext<ColumnWithDiskFeatureConfig> c
ColumnWithDiskFeatureConfig config = context.config();
BlockPos blockPos = context.origin();
WorldGenLevel level = context.level();
BlockPos s = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
BlockPos surfacePos = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
RandomSource random = level.getRandom();
int radius = config.radius().sample(random);
Optional<Holder<Block>> diskOptional = config.diskBlocks().getRandomElement(random);
// DISK
if (diskOptional.isPresent()) {
BlockPos.MutableBlockPos mutableDisk = s.mutable();
BlockPos.MutableBlockPos mutableDisk = surfacePos.mutable();
BlockState disk = diskOptional.get().value().defaultBlockState();
int bx = s.getX();
int bz = s.getZ();
int bx = surfacePos.getX();
int bz = surfacePos.getZ();
for (int x = bx - radius; x <= bx + radius; x++) {
for (int z = bz - radius; z <= bz + radius; z++) {
double distance = ((bx - x) * (bx - x) + ((bz - z) * (bz - z)));
if (distance < radius * radius) {
mutableDisk.set(x, level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, x, z) - 1, z);
boolean fade = !mutableDisk.closerThan(s, radius * 0.8);
boolean fade = !mutableDisk.closerThan(surfacePos, radius * 0.8D);
if (level.getBlockState(mutableDisk).is(config.replaceableBlocks())) {
generated = true;
if (fade) {
if (random.nextFloat() > 0.65F) {
level.setBlock(mutableDisk, disk, 3);
level.setBlock(mutableDisk, disk, Block.UPDATE_ALL);
}
} else {
level.setBlock(mutableDisk, disk, 3);
level.setBlock(mutableDisk, disk, Block.UPDATE_ALL);
}
}
}
}
}
}
// COLUMN
BlockPos startPos = blockPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) - 1);
BlockState column = config.state();
BlockPos.MutableBlockPos pos = startPos.mutable();
for (int i = 0; i < config.height().sample(random); i++) {
pos.set(pos.above());
BlockState state = level.getBlockState(pos);
if (level.getBlockState(pos.below()).is(Blocks.WATER)) {
break;
}
if (state.getBlock() instanceof GrowingPlantBodyBlock || state.getBlock() instanceof BushBlock || state.isAir()) {
level.setBlock(pos, column, 3);
generated = true;
BlockState columnState = config.state();
BlockPos.MutableBlockPos mutablePos = blockPos.mutable();
int pillarHeight = config.height().sample(random);
generated = placeAtPos(level, blockPos, mutablePos, columnState, pillarHeight) || generated;

int maxSurroundingPillarHeight = pillarHeight - 1;
if (maxSurroundingPillarHeight > 0) {
for (Direction direction : Direction.Plane.HORIZONTAL) {
if (random.nextFloat() < config.surroundingPillarChance()) {
generated = placeAtPos(level, blockPos.relative(direction), mutablePos, columnState, UniformInt.of(1, maxSurroundingPillarHeight).sample(random)) || generated;
}
}
}
startPos = startPos.offset(-1, 0, 0);
generated = generated || place(config, level, random, startPos, column, pos);
startPos = startPos.offset(1, 0, 1);
generated = generated || place(config, level, random, startPos, column, pos);
return generated;
}

private boolean place(@NotNull ColumnWithDiskFeatureConfig config, @NotNull WorldGenLevel level, RandomSource random, @NotNull BlockPos startPos, BlockState column, BlockPos.@NotNull MutableBlockPos pos) {
private boolean placeAtPos(
@NotNull WorldGenLevel level,
@NotNull BlockPos startPos,
BlockPos.@NotNull MutableBlockPos mutablePos,
BlockState columnState,
int height
) {
boolean generated = false;
pos.set(startPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, startPos.getX(), startPos.getZ()) - 1).mutable());
for (int i = 0; i < config.additionalHeight().sample(random); i++) {
pos.set(pos.above());
BlockState state = level.getBlockState(pos);
if (level.getBlockState(pos.below()).is(Blocks.WATER)) {
break;
}
if (state.getBlock() instanceof GrowingPlantBodyBlock || state.getBlock() instanceof BushBlock || state.isAir()) {
level.setBlock(pos, column, 3);
generated = true;
mutablePos.set(startPos.atY(level.getHeight(Types.MOTION_BLOCKING_NO_LEAVES, startPos.getX(), startPos.getZ()) - 1));
if (level.getBlockState(mutablePos).getFluidState().isEmpty()) {
for (int i = 0; i < height; i++) {
BlockState state = level.getBlockState(mutablePos.move(Direction.UP));
if (state.canBeReplaced()) {
level.setBlock(mutablePos, columnState, Block.UPDATE_ALL);
generated = true;
}
}
}
return generated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;

public record ColumnWithDiskFeatureConfig(BlockState state, IntProvider radius, IntProvider height,
IntProvider additionalHeight, HolderSet<Block> replaceableBlocks,
HolderSet<Block> diskBlocks) implements FeatureConfiguration {
public record ColumnWithDiskFeatureConfig(
BlockState state, IntProvider radius, IntProvider height, float surroundingPillarChance, HolderSet<Block> replaceableBlocks, HolderSet<Block> diskBlocks
) implements FeatureConfiguration {
public static final Codec<ColumnWithDiskFeatureConfig> CODEC = RecordCodecBuilder.create((instance) ->
instance.group(
BlockState.CODEC.fieldOf("state").forGetter((config) -> config.state),
IntProvider.NON_NEGATIVE_CODEC.fieldOf("radius").forGetter((config) -> config.radius),
IntProvider.NON_NEGATIVE_CODEC.fieldOf("height").forGetter((config) -> config.height),
IntProvider.NON_NEGATIVE_CODEC.fieldOf("additional_height").forGetter((config) -> config.additionalHeight),
Codec.FLOAT.fieldOf("surrounding_pillar_chance").forGetter((config) -> config.surroundingPillarChance),
RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("replaceable_blocks").forGetter((config) -> config.replaceableBlocks),
RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("disk_blocks").forGetter((config) -> config.diskBlocks)
).apply(instance, ColumnWithDiskFeatureConfig::new));
Expand Down

0 comments on commit b73b564

Please sign in to comment.