package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityTypes; import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.gameevent.vibrations.VibrationSystem; import org.jspecify.annotations.Nullable; public class CalibratedSculkSensorBlock extends SculkSensorBlock { public static final MapCodec CODEC = simpleCodec(CalibratedSculkSensorBlock::new); public static final EnumProperty FACING = BlockStateProperties.HORIZONTAL_FACING; @Override public MapCodec codec() { return CODEC; } public CalibratedSculkSensorBlock(final BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH)); } @Nullable @Override public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) { return new CalibratedSculkSensorBlockEntity(worldPosition, blockState); } @Nullable @Override public BlockEntityTicker getTicker(final Level level, final BlockState blockState, final BlockEntityType type) { return !level.isClientSide() ? createTickerHelper( type, BlockEntityTypes.CALIBRATED_SCULK_SENSOR, (innerLevel, pos, state, entity) -> VibrationSystem.Ticker.tick(innerLevel, entity.getVibrationData(), entity.getVibrationUser()) ) : null; } @Nullable @Override public BlockState getStateForPlacement(final BlockPlaceContext context) { return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection()); } @Override public int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction) { return direction != state.getValue(FACING) ? super.ownSignal(state, level, pos) : 0; } @Override protected void createBlockStateDefinition(final StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); builder.add(FACING); } @Override public BlockState rotate(final BlockState state, final Rotation rotation) { return state.setValue(FACING, rotation.rotate(state.getValue(FACING))); } @Override public BlockState mirror(final BlockState state, final Mirror mirror) { return state.rotate(mirror.getRotation(state.getValue(FACING))); } @Override public int getActiveTicks() { return 10; } }