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.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.Builder; 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.jetbrains.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(BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH)); } @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new CalibratedSculkSensorBlockEntity(pos, state); } @Nullable @Override public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType blockEntityType) { return !level.isClientSide ? createTickerHelper( blockEntityType, BlockEntityType.CALIBRATED_SCULK_SENSOR, (levelx, blockPos, blockState, calibratedSculkSensorBlockEntity) -> VibrationSystem.Ticker.tick( levelx, calibratedSculkSensorBlockEntity.getVibrationData(), calibratedSculkSensorBlockEntity.getVibrationUser() ) ) : null; } @Nullable @Override public BlockState getStateForPlacement(BlockPlaceContext context) { return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection()); } @Override public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return direction != state.getValue(FACING) ? super.getSignal(state, level, pos, direction) : 0; } @Override protected void createBlockStateDefinition(Builder builder) { super.createBlockStateDefinition(builder); builder.add(FACING); } @Override public BlockState rotate(BlockState state, Rotation rotation) { return state.setValue(FACING, rotation.rotate(state.getValue(FACING))); } @Override public BlockState mirror(BlockState state, Mirror mirror) { return state.rotate(mirror.getRotation(state.getValue(FACING))); } @Override public int getActiveTicks() { return 10; } }