| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 6 | import net.minecraft.world.level.BlockGetter;
|
| 7 | import net.minecraft.world.level.Level;
|
| 8 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 9 | import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
| 10 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
| 11 | import net.minecraft.world.level.block.entity.BlockEntityTypes;
|
| 12 | import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
|
| 13 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 16 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 17 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 18 | import net.minecraft.world.level.gameevent.vibrations.VibrationSystem;
|
| 19 | import org.jspecify.annotations.Nullable;
|
| 20 |
|
| 21 | public class CalibratedSculkSensorBlock extends SculkSensorBlock {
|
| 22 | public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
|
| 23 |
|
| 24 | public CalibratedSculkSensorBlock(final BlockBehaviour.Properties properties) {
|
| 25 | super(properties);
|
| 26 | this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH));
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public @Nullable BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 31 | return new CalibratedSculkSensorBlockEntity(worldPosition, blockState);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
|
| 36 | return !level.isClientSide()
|
| 37 | ? createTickerHelper(
|
| 38 | type,
|
| 39 | BlockEntityTypes.CALIBRATED_SCULK_SENSOR,
|
| 40 | (innerLevel, pos, state, entity) -> VibrationSystem.Ticker.tick(innerLevel, entity.getVibrationData(), entity.getVibrationUser())
|
| 41 | )
|
| 42 | : null;
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 47 | return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection());
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | public int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction) {
|
| 52 | return direction != state.getValue(FACING) ? super.ownSignal(state, level, pos) : 0;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 57 | super.createBlockStateDefinition(builder);
|
| 58 | builder.add(FACING);
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 63 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 64 | }
|
| 65 |
|
| 66 | @Override
|
| 67 | public BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 68 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 69 | }
|
| 70 |
|
| 71 | @Override
|
| 72 | public int getActiveTicks() {
|
| 73 | return 10;
|
| 74 | }
|
| 75 | }
|
| 76 |
|