Add configurable smooth snow accumulation (#1651)

This commit is contained in:
Josh
2025-04-12 15:20:22 -07:00
committed by GitHub
parent 96f0ee1ea3
commit d4af79471c
2 changed files with 50 additions and 0 deletions

View File

@@ -109,6 +109,45 @@
skeletonHorse.setAge(0);
skeletonHorse.setPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
this.addFreshEntity(skeletonHorse, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
@@ -986,9 +_,35 @@
if (blockState.is(Blocks.SNOW)) {
int layersValue = blockState.getValue(SnowLayerBlock.LAYERS);
if (layersValue < Math.min(_int, 8)) {
- BlockState blockState1 = blockState.setValue(SnowLayerBlock.LAYERS, Integer.valueOf(layersValue + 1));
- Block.pushEntitiesUp(blockState, blockState1, this, heightmapPos);
- org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, heightmapPos, blockState1, null); // CraftBukkit
+ // Purpur start - Smooth snow accumulation
+ boolean canSnow = true;
+ // Ensure snow doesn't get more than N layers taller than its neighbors
+ // We only need to check blocks that are taller than the minimum step height
+ if (layersValue >= org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep && org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep > 0) {
+ int layersValueMin = layersValue - org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep;
+ for (Direction direction : Direction.Plane.HORIZONTAL) {
+ BlockPos blockPosNeighbor = heightmapPos.relative(direction);
+ BlockState blockStateNeighbor = this.getBlockState(blockPosNeighbor);
+ if (blockStateNeighbor.is(Blocks.SNOW)) {
+ // Special check for snow layers, if neighbors are too short, don't accumulate
+ int layersValueNeighbor = blockStateNeighbor.getValue(SnowLayerBlock.LAYERS);
+ if (layersValueNeighbor <= layersValueMin) {
+ canSnow = false;
+ break;
+ }
+ } else if (!Block.isFaceFull(blockStateNeighbor.getCollisionShape(this, blockPosNeighbor), direction.getOpposite())) {
+ // Since our layer is tall enough already, if we have a non-full neighbor block, don't accumulate
+ canSnow = false;
+ break;
+ }
+ }
+ }
+ if (canSnow) {
+ BlockState blockState1 = blockState.setValue(SnowLayerBlock.LAYERS, Integer.valueOf(layersValue + 1));
+ Block.pushEntitiesUp(blockState, blockState1, this, heightmapPos);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, heightmapPos, blockState1, null); // CraftBukkit
+ }
+ // Purpur end - Smooth snow accumulation
}
} else {
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, heightmapPos, Blocks.SNOW.defaultBlockState(), null); // CraftBukkit
@@ -1009,7 +_,7 @@
pointOfInterestType -> pointOfInterestType.is(PoiTypes.LIGHTNING_ROD),
blockPos -> blockPos.getY() == this.getHeight(Heightmap.Types.WORLD_SURFACE, blockPos.getX(), blockPos.getZ()) - 1,