| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.google.common.annotations.VisibleForTesting;
|
| 4 | import java.util.Optional;
|
| 5 | import java.util.function.BiPredicate;
|
| 6 | import java.util.function.Predicate;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.core.Direction;
|
| 9 | import net.minecraft.server.level.ServerLevel;
|
| 10 | import net.minecraft.tags.BlockTags;
|
| 11 | import net.minecraft.util.RandomSource;
|
| 12 | import net.minecraft.world.damagesource.DamageSource;
|
| 13 | import net.minecraft.world.entity.Entity;
|
| 14 | import net.minecraft.world.entity.item.FallingBlockEntity;
|
| 15 | import net.minecraft.world.entity.projectile.Projectile;
|
| 16 | import net.minecraft.world.entity.projectile.arrow.ThrownTrident;
|
| 17 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 18 | import net.minecraft.world.level.BlockGetter;
|
| 19 | import net.minecraft.world.level.Level;
|
| 20 | import net.minecraft.world.level.LevelAccessor;
|
| 21 | import net.minecraft.world.level.LevelReader;
|
| 22 | import net.minecraft.world.level.ScheduledTickAccess;
|
| 23 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 24 | import net.minecraft.world.level.block.state.BlockState;
|
| 25 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 26 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 27 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 28 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 29 | import net.minecraft.world.level.block.state.properties.SpeleothemThickness;
|
| 30 | import net.minecraft.world.level.material.FluidState;
|
| 31 | import net.minecraft.world.level.material.Fluids;
|
| 32 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 33 | import net.minecraft.world.phys.BlockHitResult;
|
| 34 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 35 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 36 | import org.jspecify.annotations.Nullable;
|
| 37 |
|
| 38 | public abstract class SpeleothemBlock extends Block implements SimpleWaterloggedBlock, Fallable {
|
| 39 | public static final EnumProperty<Direction> TIP_DIRECTION = BlockStateProperties.VERTICAL_DIRECTION;
|
| 40 | public static final EnumProperty<SpeleothemThickness> THICKNESS = BlockStateProperties.SPELEOTHEM_THICKNESS;
|
| 41 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
| 42 | private static final int DELAY_BEFORE_FALLING = 2;
|
| 43 | private static final double MIN_TRIDENT_VELOCITY_TO_BREAK_SPELEOTHEM = 0.6;
|
| 44 | private static final float STALACTITE_DAMAGE_PER_FALL_DISTANCE_AND_SIZE = 1.0F;
|
| 45 | private static final int STALACTITE_MAX_DAMAGE = 40;
|
| 46 | private static final int MAX_STALACTITE_HEIGHT_FOR_DAMAGE_CALCULATION = 6;
|
| 47 | private static final VoxelShape SHAPE_TIP_MERGE = Block.column(6.0, 0.0, 16.0);
|
| 48 | private static final VoxelShape SHAPE_TIP_UP = Block.column(6.0, 0.0, 11.0);
|
| 49 | protected static final VoxelShape SHAPE_TIP_DOWN = Block.column(6.0, 5.0, 16.0);
|
| 50 | private static final VoxelShape SHAPE_FRUSTUM = Block.column(8.0, 0.0, 16.0);
|
| 51 | private static final VoxelShape SHAPE_MIDDLE = Block.column(10.0, 0.0, 16.0);
|
| 52 | private static final VoxelShape SHAPE_BASE = Block.column(12.0, 0.0, 16.0);
|
| 53 | private static final float MAX_HORIZONTAL_OFFSET = (float)SHAPE_BASE.min(Direction.Axis.X);
|
| 54 | private static final float AVERAGE_DAYS_PER_GROWTH = 5.0F;
|
| 55 | private static final float GROWTH_PROBABILITY_PER_RANDOM_TICK = 0.011377778F;
|
| 56 | private static final int MAX_GROWTH_LENGTH = 7;
|
| 57 | private static final int MAX_STALAGMITE_SEARCH_RANGE_WHEN_GROWING = 10;
|
| 58 | protected final BlockState blockToGrowOn;
|
| 59 |
|
| 60 | public SpeleothemBlock(final BlockState blockToGrowOn, final BlockBehaviour.Properties properties) {
|
| 61 | super(properties);
|
| 62 | this.blockToGrowOn = blockToGrowOn;
|
| 63 | this.registerDefaultState(
|
| 64 | this.stateDefinition.any().setValue(TIP_DIRECTION, Direction.UP).setValue(THICKNESS, SpeleothemThickness.TIP).setValue(WATERLOGGED, false)
|
| 65 | );
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 70 | builder.add(TIP_DIRECTION, THICKNESS, WATERLOGGED);
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 75 | return this.isValidSpeleothemPlacement(level, pos, state.getValue(TIP_DIRECTION));
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | protected BlockState updateShape(
|
| 80 | final BlockState state,
|
| 81 | final LevelReader level,
|
| 82 | final ScheduledTickAccess ticks,
|
| 83 | final BlockPos pos,
|
| 84 | final Direction directionToNeighbour,
|
| 85 | final BlockPos neighbourPos,
|
| 86 | final BlockState neighbourState,
|
| 87 | final RandomSource random
|
| 88 | ) {
|
| 89 | if (state.getValue(WATERLOGGED)) {
|
| 90 | ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
| 91 | }
|
| 92 |
|
| 93 | if (directionToNeighbour != Direction.UP && directionToNeighbour != Direction.DOWN) {
|
| 94 | return state;
|
| 95 | }
|
| 96 |
|
| 97 | Direction tipDirection = state.getValue(TIP_DIRECTION);
|
| 98 | if (tipDirection == Direction.DOWN && ticks.getBlockTicks().hasScheduledTick(pos, this)) {
|
| 99 | return state;
|
| 100 | }
|
| 101 |
|
| 102 | if (directionToNeighbour == tipDirection.getOpposite() && !this.canSurvive(state, level, pos)) {
|
| 103 | if (tipDirection == Direction.DOWN) {
|
| 104 | ticks.scheduleTick(pos, this, 2);
|
| 105 | } else {
|
| 106 | ticks.scheduleTick(pos, this, 1);
|
| 107 | }
|
| 108 |
|
| 109 | return state;
|
| 110 | } else {
|
| 111 | boolean mergeOpposingTips = state.getValue(THICKNESS) == SpeleothemThickness.TIP_MERGE;
|
| 112 | SpeleothemThickness newThickness = this.calculateSpeleothemThickness(level, pos, tipDirection, mergeOpposingTips);
|
| 113 | return state.setValue(THICKNESS, newThickness);
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | @Override
|
| 118 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 119 | LevelAccessor level = context.getLevel();
|
| 120 | BlockPos pos = context.getClickedPos();
|
| 121 | Direction defaultTipDirection = context.getNearestLookingVerticalDirection().getOpposite();
|
| 122 | Direction tipDirection = this.calculateTipDirection(level, pos, defaultTipDirection);
|
| 123 | if (tipDirection == null) {
|
| 124 | return null;
|
| 125 | }
|
| 126 |
|
| 127 | boolean mergeOpposingTips = !context.isSecondaryUseActive();
|
| 128 | SpeleothemThickness thickness = this.calculateSpeleothemThickness(level, pos, tipDirection, mergeOpposingTips);
|
| 129 | return this.defaultBlockState()
|
| 130 | .setValue(TIP_DIRECTION, tipDirection)
|
| 131 | .setValue(THICKNESS, thickness)
|
| 132 | .setValue(WATERLOGGED, level.getFluidState(pos).is(Fluids.WATER));
|
| 133 | }
|
| 134 |
|
| 135 | private @Nullable Direction calculateTipDirection(final LevelReader level, final BlockPos pos, final Direction defaultTipDirection) {
|
| 136 | Direction tipDirection;
|
| 137 | if (this.isValidSpeleothemPlacement(level, pos, defaultTipDirection)) {
|
| 138 | tipDirection = defaultTipDirection;
|
| 139 | } else {
|
| 140 | if (!this.isValidSpeleothemPlacement(level, pos, defaultTipDirection.getOpposite())) {
|
| 141 | return null;
|
| 142 | }
|
| 143 |
|
| 144 | tipDirection = defaultTipDirection.getOpposite();
|
| 145 | }
|
| 146 |
|
| 147 | return tipDirection;
|
| 148 | }
|
| 149 |
|
| 150 | private SpeleothemThickness calculateSpeleothemThickness(
|
| 151 | final LevelReader level, final BlockPos pos, final Direction tipDirection, final boolean mergeOpposingTips
|
| 152 | ) {
|
| 153 | Direction baseDirection = tipDirection.getOpposite();
|
| 154 | BlockState inFrontState = level.getBlockState(pos.relative(tipDirection));
|
| 155 | if (isSpeleothemWithDirection(inFrontState, baseDirection) && inFrontState.is(this)) {
|
| 156 | return !mergeOpposingTips && inFrontState.getValue(THICKNESS) != SpeleothemThickness.TIP_MERGE ? SpeleothemThickness.TIP : SpeleothemThickness.TIP_MERGE;
|
| 157 | } else if (!isSpeleothemWithDirection(inFrontState, tipDirection)) {
|
| 158 | return SpeleothemThickness.TIP;
|
| 159 | } else {
|
| 160 | SpeleothemThickness inFrontThickness = inFrontState.getValue(THICKNESS);
|
| 161 | if (inFrontThickness != SpeleothemThickness.TIP && inFrontThickness != SpeleothemThickness.TIP_MERGE) {
|
| 162 | BlockState behindState = level.getBlockState(pos.relative(baseDirection));
|
| 163 | return !isSpeleothemWithDirection(behindState, tipDirection) ? SpeleothemThickness.BASE : SpeleothemThickness.MIDDLE;
|
| 164 | } else {
|
| 165 | return SpeleothemThickness.FRUSTUM;
|
| 166 | }
|
| 167 | }
|
| 168 | }
|
| 169 |
|
| 170 | private boolean isValidSpeleothemPlacement(final LevelReader level, final BlockPos pos, final Direction tipDirection) {
|
| 171 | BlockPos behindPos = pos.relative(tipDirection.getOpposite());
|
| 172 | BlockState behindState = level.getBlockState(behindPos);
|
| 173 | return behindState.isFaceSturdy(level, behindPos, tipDirection) || isSpeleothemWithDirection(behindState, tipDirection) && behindState.is(this);
|
| 174 | }
|
| 175 |
|
| 176 | private static boolean isSpeleothemWithDirection(final BlockState blockState, final Direction tipDirection) {
|
| 177 | return blockState.is(BlockTags.SPELEOTHEMS) && blockState.getValue(TIP_DIRECTION) == tipDirection;
|
| 178 | }
|
| 179 |
|
| 180 | @Override
|
| 181 | protected void onProjectileHit(final Level level, final BlockState state, final BlockHitResult blockHit, final Projectile projectile) {
|
| 182 | if (!level.isClientSide()) {
|
| 183 | BlockPos blockPos = blockHit.getBlockPos();
|
| 184 | if (level instanceof ServerLevel serverLevel
|
| 185 | && projectile.mayInteract(serverLevel, blockPos)
|
| 186 | && projectile.mayBreak(serverLevel, blockPos)
|
| 187 | && projectile instanceof ThrownTrident
|
| 188 | && projectile.getDeltaMovement().length() > 0.6) {
|
| 189 | level.destroyBlock(blockPos, true);
|
| 190 | }
|
| 191 | }
|
| 192 | }
|
| 193 |
|
| 194 | @Override
|
| 195 | protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
|
| 196 | if (isStalagmite(state) && !this.canSurvive(state, level, pos)) {
|
| 197 | level.destroyBlock(pos, true);
|
| 198 | } else {
|
| 199 | spawnFallingStalactite(state, level, pos);
|
| 200 | }
|
| 201 | }
|
| 202 |
|
| 203 | private static void spawnFallingStalactite(final BlockState state, final ServerLevel level, final BlockPos pos) {
|
| 204 | BlockPos.MutableBlockPos fallPos = pos.mutable();
|
| 205 | BlockState fallState = state;
|
| 206 |
|
| 207 | while (isStalactite(fallState)) {
|
| 208 | FallingBlockEntity entity = FallingBlockEntity.fall(level, fallPos, fallState);
|
| 209 | if (isTip(fallState, true)) {
|
| 210 | int size = Math.max(1 + pos.getY() - fallPos.getY(), 6);
|
| 211 | float damagePerFallDistance = 1.0F * size;
|
| 212 | entity.setHurtsEntities(damagePerFallDistance, 40);
|
| 213 | break;
|
| 214 | }
|
| 215 |
|
| 216 | fallPos.move(Direction.DOWN);
|
| 217 | fallState = level.getBlockState(fallPos);
|
| 218 | }
|
| 219 | }
|
| 220 |
|
| 221 | private static boolean isStalagmite(final BlockState state) {
|
| 222 | return isSpeleothemWithDirection(state, Direction.UP);
|
| 223 | }
|
| 224 |
|
| 225 | protected static boolean isStalactite(final BlockState state) {
|
| 226 | return isSpeleothemWithDirection(state, Direction.DOWN);
|
| 227 | }
|
| 228 |
|
| 229 | private static boolean isTip(final BlockState state, final boolean includeMergedTip) {
|
| 230 | if (!state.is(BlockTags.SPELEOTHEMS)) {
|
| 231 | return false;
|
| 232 | }
|
| 233 |
|
| 234 | SpeleothemThickness thickness = state.getValue(THICKNESS);
|
| 235 | return thickness == SpeleothemThickness.TIP || includeMergedTip && thickness == SpeleothemThickness.TIP_MERGE;
|
| 236 | }
|
| 237 |
|
| 238 | @Override
|
| 239 | public void onBrokenAfterFall(final Level level, final BlockPos pos, final FallingBlockEntity entity) {
|
| 240 | if (!entity.isSilent()) {
|
| 241 | level.levelEvent(this.getStalactiteLandingSound(), pos, 0);
|
| 242 | }
|
| 243 | }
|
| 244 |
|
| 245 | protected abstract @LevelEvent.Value int getStalactiteLandingSound();
|
| 246 |
|
| 247 | @Override
|
| 248 | public DamageSource getFallDamageSource(final Entity entity) {
|
| 249 | return entity.damageSources().fallingStalactite(entity);
|
| 250 | }
|
| 251 |
|
| 252 | @Override
|
| 253 | protected FluidState getFluidState(final BlockState state) {
|
| 254 | return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
|
| 255 | }
|
| 256 |
|
| 257 | @Override
|
| 258 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 259 | VoxelShape shape = switch ((SpeleothemThickness)state.getValue(THICKNESS)) {
|
| 260 | case TIP_MERGE -> SHAPE_TIP_MERGE;
|
| 261 | case TIP -> state.getValue(TIP_DIRECTION) == Direction.DOWN ? SHAPE_TIP_DOWN : SHAPE_TIP_UP;
|
| 262 | case FRUSTUM -> SHAPE_FRUSTUM;
|
| 263 | case MIDDLE -> SHAPE_MIDDLE;
|
| 264 | case BASE -> SHAPE_BASE;
|
| 265 | };
|
| 266 | return shape.move(state.getOffset(pos));
|
| 267 | }
|
| 268 |
|
| 269 | @Override
|
| 270 | protected boolean isCollisionShapeFullBlock(final BlockState state, final BlockGetter level, final BlockPos pos) {
|
| 271 | return false;
|
| 272 | }
|
| 273 |
|
| 274 | @Override
|
| 275 | protected float getMaxHorizontalOffset() {
|
| 276 | return MAX_HORIZONTAL_OFFSET;
|
| 277 | }
|
| 278 |
|
| 279 | @Override
|
| 280 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 281 | return false;
|
| 282 | }
|
| 283 |
|
| 284 | @Override
|
| 285 | protected void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
|
| 286 | if (random.nextFloat() < 0.011377778F && isStalactiteStartPos(state, level, pos)) {
|
| 287 | this.growStalactiteOrStalagmiteIfPossible(state, level, pos, random);
|
| 288 | }
|
| 289 | }
|
| 290 |
|
| 291 | protected static boolean isStalactiteStartPos(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 292 | return isStalactite(state) && !level.getBlockState(pos.above()).is(state.getBlock());
|
| 293 | }
|
| 294 |
|
| 295 | @VisibleForTesting
|
| 296 | public void growStalactiteOrStalagmiteIfPossible(
|
| 297 | final BlockState stalactiteStartState, final ServerLevel level, final BlockPos stalactiteStartPos, final RandomSource random
|
| 298 | ) {
|
| 299 | if (this.canGrow(level, stalactiteStartPos)) {
|
| 300 | BlockPos stalactiteTipPos = findTip(stalactiteStartState, level, stalactiteStartPos, this.getMaxGrowthLength(), false);
|
| 301 | if (stalactiteTipPos != null) {
|
| 302 | BlockState stalactiteTipState = level.getBlockState(stalactiteTipPos);
|
| 303 | if (isFreeHangingStalactite(stalactiteTipState) && this.canTipGrow(stalactiteTipState, level, stalactiteTipPos)) {
|
| 304 | if (random.nextBoolean()) {
|
| 305 | this.grow(level, stalactiteTipPos, Direction.DOWN);
|
| 306 | } else {
|
| 307 | this.growStalagmiteBelow(level, stalactiteTipPos);
|
| 308 | }
|
| 309 | }
|
| 310 | }
|
| 311 | }
|
| 312 | }
|
| 313 |
|
| 314 | protected boolean canGrow(final LevelReader level, final BlockPos pos) {
|
| 315 | return level.getBlockState(pos.above()).is(this.blockToGrowOn.getBlock());
|
| 316 | }
|
| 317 |
|
| 318 | protected static @Nullable BlockPos findTip(
|
| 319 | final BlockState speleothemState, final LevelAccessor level, final BlockPos speleothemPos, final int maxSearchLength, final boolean includeMergedTip
|
| 320 | ) {
|
| 321 | if (isTip(speleothemState, includeMergedTip)) {
|
| 322 | return speleothemPos;
|
| 323 | }
|
| 324 |
|
| 325 | Direction searchDirection = speleothemState.getValue(TIP_DIRECTION);
|
| 326 | BiPredicate<BlockPos, BlockState> pathPredicate = (pos, state) -> state.is(speleothemState.getBlock()) && state.getValue(TIP_DIRECTION) == searchDirection;
|
| 327 | return findBlockVertical(
|
| 328 | level, speleothemPos, searchDirection.getAxisDirection(), pathPredicate, speleothem -> isTip(speleothem, includeMergedTip), maxSearchLength
|
| 329 | )
|
| 330 | .orElse(null);
|
| 331 | }
|
| 332 |
|
| 333 | protected static Optional<BlockPos> findBlockVertical(
|
| 334 | final LevelAccessor level,
|
| 335 | final BlockPos pos,
|
| 336 | final Direction.AxisDirection axisDirection,
|
| 337 | final BiPredicate<BlockPos, BlockState> pathPredicate,
|
| 338 | final Predicate<BlockState> targetPredicate,
|
| 339 | final int maxSteps
|
| 340 | ) {
|
| 341 | Direction direction = Direction.get(axisDirection, Direction.Axis.Y);
|
| 342 | BlockPos.MutableBlockPos mutablePos = pos.mutable();
|
| 343 |
|
| 344 | for (int i = 1; i < maxSteps; i++) {
|
| 345 | mutablePos.move(direction);
|
| 346 | BlockState state = level.getBlockState(mutablePos);
|
| 347 | if (targetPredicate.test(state)) {
|
| 348 | return Optional.of(mutablePos.immutable());
|
| 349 | }
|
| 350 |
|
| 351 | if (level.isOutsideBuildHeight(mutablePos.getY()) || !pathPredicate.test(mutablePos, state)) {
|
| 352 | return Optional.empty();
|
| 353 | }
|
| 354 | }
|
| 355 |
|
| 356 | return Optional.empty();
|
| 357 | }
|
| 358 |
|
| 359 | private boolean canTipGrow(final BlockState tipState, final ServerLevel level, final BlockPos tipPos) {
|
| 360 | Direction growDirection = tipState.getValue(TIP_DIRECTION);
|
| 361 | BlockPos growPos = tipPos.relative(growDirection);
|
| 362 | BlockState stateAtGrowPos = level.getBlockState(growPos);
|
| 363 | if (!stateAtGrowPos.getFluidState().isEmpty()) {
|
| 364 | return false;
|
| 365 | } else {
|
| 366 | return stateAtGrowPos.isAir() ? true : this.isUnmergedTipWithDirection(stateAtGrowPos, growDirection.getOpposite());
|
| 367 | }
|
| 368 | }
|
| 369 |
|
| 370 | private boolean isUnmergedTipWithDirection(final BlockState state, final Direction tipDirection) {
|
| 371 | return isTip(state, false) && state.getValue(TIP_DIRECTION) == tipDirection && state.is(this);
|
| 372 | }
|
| 373 |
|
| 374 | private void grow(final ServerLevel level, final BlockPos growFromPos, final Direction growToDirection) {
|
| 375 | BlockPos targetPos = growFromPos.relative(growToDirection);
|
| 376 | BlockState existingStateAtTargetPos = level.getBlockState(targetPos);
|
| 377 | if (this.isUnmergedTipWithDirection(existingStateAtTargetPos, growToDirection.getOpposite())) {
|
| 378 | this.createMergedTips(existingStateAtTargetPos, level, targetPos);
|
| 379 | } else if (existingStateAtTargetPos.isAir() || existingStateAtTargetPos.is(Blocks.WATER)) {
|
| 380 | this.createSpeleothem(level, targetPos, growToDirection, SpeleothemThickness.TIP);
|
| 381 | }
|
| 382 | }
|
| 383 |
|
| 384 | private void createSpeleothem(final LevelAccessor level, final BlockPos pos, final Direction direction, final SpeleothemThickness thickness) {
|
| 385 | BlockState state = this.defaultBlockState()
|
| 386 | .setValue(TIP_DIRECTION, direction)
|
| 387 | .setValue(THICKNESS, thickness)
|
| 388 | .setValue(WATERLOGGED, level.getFluidState(pos).is(Fluids.WATER));
|
| 389 | level.setBlockAndUpdate(pos, state);
|
| 390 | }
|
| 391 |
|
| 392 | private void createMergedTips(final BlockState tipState, final LevelAccessor level, final BlockPos tipPos) {
|
| 393 | BlockPos stalactitePos;
|
| 394 | BlockPos stalagmitePos;
|
| 395 | if (tipState.getValue(TIP_DIRECTION) == Direction.UP) {
|
| 396 | stalagmitePos = tipPos;
|
| 397 | stalactitePos = tipPos.above();
|
| 398 | } else {
|
| 399 | stalactitePos = tipPos;
|
| 400 | stalagmitePos = tipPos.below();
|
| 401 | }
|
| 402 |
|
| 403 | this.createSpeleothem(level, stalactitePos, Direction.DOWN, SpeleothemThickness.TIP_MERGE);
|
| 404 | this.createSpeleothem(level, stalagmitePos, Direction.UP, SpeleothemThickness.TIP_MERGE);
|
| 405 | }
|
| 406 |
|
| 407 | private void growStalagmiteBelow(final ServerLevel level, final BlockPos posAboveStalagmite) {
|
| 408 | BlockPos.MutableBlockPos pos = posAboveStalagmite.mutable();
|
| 409 |
|
| 410 | for (int i = 0; i < 10; i++) {
|
| 411 | pos.move(Direction.DOWN);
|
| 412 | BlockState state = level.getBlockState(pos);
|
| 413 | if (!state.getFluidState().isEmpty()) {
|
| 414 | return;
|
| 415 | }
|
| 416 |
|
| 417 | if (this.isUnmergedTipWithDirection(state, Direction.UP) && this.canTipGrow(state, level, pos)) {
|
| 418 | this.grow(level, pos, Direction.UP);
|
| 419 | return;
|
| 420 | }
|
| 421 |
|
| 422 | if (this.isValidSpeleothemPlacement(level, pos, Direction.UP) && !level.isWaterAt(pos.below())) {
|
| 423 | this.grow(level, pos.below(), Direction.UP);
|
| 424 | return;
|
| 425 | }
|
| 426 |
|
| 427 | if (this.blocksStalagmiteScan(level, pos, state)) {
|
| 428 | return;
|
| 429 | }
|
| 430 | }
|
| 431 | }
|
| 432 |
|
| 433 | protected boolean blocksStalagmiteScan(final LevelReader level, final BlockPos pos, final BlockState state) {
|
| 434 | return false;
|
| 435 | }
|
| 436 |
|
| 437 | protected static boolean isFreeHangingStalactite(final BlockState state) {
|
| 438 | return isStalactite(state) && state.getValue(THICKNESS) == SpeleothemThickness.TIP && !state.getValue(WATERLOGGED);
|
| 439 | }
|
| 440 |
|
| 441 | protected int getMaxGrowthLength() {
|
| 442 | return 7;
|
| 443 | }
|
| 444 | }
|
| 445 |
|