minecraft-src/net/minecraft/world/level/block/BushBlock.java
2025-07-04 02:00:41 +03:00

58 lines
1.9 KiB
Java

package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.ScheduledTickAccess;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.PathComputationType;
public abstract class BushBlock extends Block {
protected BushBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
protected abstract MapCodec<? extends BushBlock> codec();
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
return state.is(BlockTags.DIRT) || state.is(Blocks.FARMLAND);
}
@Override
protected BlockState updateShape(
BlockState blockState,
LevelReader levelReader,
ScheduledTickAccess scheduledTickAccess,
BlockPos blockPos,
Direction direction,
BlockPos blockPos2,
BlockState blockState2,
RandomSource randomSource
) {
return !blockState.canSurvive(levelReader, blockPos)
? Blocks.AIR.defaultBlockState()
: super.updateShape(blockState, levelReader, scheduledTickAccess, blockPos, direction, blockPos2, blockState2, randomSource);
}
@Override
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
BlockPos blockPos = pos.below();
return this.mayPlaceOn(level.getBlockState(blockPos), level, blockPos);
}
@Override
protected boolean propagatesSkylightDown(BlockState blockState) {
return blockState.getFluidState().isEmpty();
}
@Override
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
return pathComputationType == PathComputationType.AIR && !this.hasCollision ? true : super.isPathfindable(state, pathComputationType);
}
}