| 1 | package net.minecraft.world.level.block.entity;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.core.Holder;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.world.level.Level;
|
| 8 | import net.minecraft.world.level.block.CalibratedSculkSensorBlock;
|
| 9 | import net.minecraft.world.level.block.state.BlockState;
|
| 10 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 11 | import net.minecraft.world.level.gameevent.vibrations.VibrationSystem;
|
| 12 | import org.jspecify.annotations.Nullable;
|
| 13 |
|
| 14 | public class CalibratedSculkSensorBlockEntity extends SculkSensorBlockEntity {
|
| 15 | public CalibratedSculkSensorBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 16 | super(BlockEntityTypes.CALIBRATED_SCULK_SENSOR, worldPosition, blockState);
|
| 17 | }
|
| 18 |
|
| 19 | @Override
|
| 20 | public VibrationSystem.User createVibrationUser() {
|
| 21 | return new CalibratedSculkSensorBlockEntity.VibrationUser(this.getBlockPos());
|
| 22 | }
|
| 23 |
|
| 24 | protected class VibrationUser extends SculkSensorBlockEntity.VibrationUser {
|
| 25 | public VibrationUser(final BlockPos blockPos) {
|
| 26 | super(blockPos);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public int getListenerRadius() {
|
| 31 | return 16;
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public boolean canReceiveVibration(final ServerLevel level, final BlockPos pos, final Holder<GameEvent> event, final GameEvent.@Nullable Context context) {
|
| 36 | int comparisonType = this.getBackSignal(level, this.blockPos, CalibratedSculkSensorBlockEntity.this.getBlockState());
|
| 37 | return comparisonType != 0 && VibrationSystem.getGameEventFrequency(event) != comparisonType ? false : super.canReceiveVibration(level, pos, event, context);
|
| 38 | }
|
| 39 |
|
| 40 | private int getBackSignal(final Level level, final BlockPos pos, final BlockState state) {
|
| 41 | Direction direction = state.getValue(CalibratedSculkSensorBlock.FACING).getOpposite();
|
| 42 | return level.getSignal(pos.relative(direction), direction);
|
| 43 | }
|
| 44 | }
|
| 45 | }
|
| 46 |
|