50 lines
1.6 KiB
Java
50 lines
1.6 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.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.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public abstract class BaseTorchBlock extends Block {
|
|
private static final VoxelShape SHAPE = Block.column(4.0, 0.0, 10.0);
|
|
|
|
protected BaseTorchBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
}
|
|
|
|
@Override
|
|
protected abstract MapCodec<? extends BaseTorchBlock> codec();
|
|
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return SHAPE;
|
|
}
|
|
|
|
@Override
|
|
protected BlockState updateShape(
|
|
BlockState state,
|
|
LevelReader level,
|
|
ScheduledTickAccess scheduledTickAccess,
|
|
BlockPos pos,
|
|
Direction direction,
|
|
BlockPos neighborPos,
|
|
BlockState neighborState,
|
|
RandomSource random
|
|
) {
|
|
return direction == Direction.DOWN && !this.canSurvive(state, level, pos)
|
|
? Blocks.AIR.defaultBlockState()
|
|
: super.updateShape(state, level, scheduledTickAccess, pos, direction, neighborPos, neighborState, random);
|
|
}
|
|
|
|
@Override
|
|
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
|
return canSupportCenter(level, pos.below(), Direction.UP);
|
|
}
|
|
}
|