|
4 | 4 | import net.minecraft.core.Direction; |
5 | 5 | import net.minecraft.server.level.ServerLevel; |
6 | 6 | import net.minecraft.util.RandomSource; |
| 7 | +import net.minecraft.world.entity.Entity; |
| 8 | +import net.minecraft.world.entity.InsideBlockEffectApplier; |
7 | 9 | import net.minecraft.world.level.BlockGetter; |
| 10 | +import net.minecraft.world.level.Level; |
8 | 11 | import net.minecraft.world.level.block.Block; |
9 | 12 | import net.minecraft.world.level.block.state.BlockState; |
10 | 13 | import net.minecraft.world.level.block.state.StateDefinition; |
11 | 14 | import net.minecraft.world.level.block.state.properties.BooleanProperty; |
12 | 15 | import net.minecraft.world.level.levelgen.structure.BoundingBox; |
| 16 | +import net.minecraft.world.phys.AABB; |
13 | 17 | import one.devos.nautical.losing_my_marbles.content.marble.MarbleEntity; |
14 | 18 | import one.devos.nautical.losing_my_marbles.content.piece.StraightPieceBlock; |
15 | | -import one.devos.nautical.losing_my_marbles.framework.block.MarbleListeningBlock; |
16 | 19 |
|
17 | | -public final class DetectorPieceBlock extends StraightPieceBlock implements MarbleListeningBlock { |
| 20 | +public final class DetectorPieceBlock extends StraightPieceBlock { |
18 | 21 | public static final int ACTIVE_TICKS = 10; |
19 | 22 | public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); |
20 | 23 |
|
| 24 | + public static final AABB DETECTION_AREA = box(4, 8, 6, 12, 14, 10).toAabbs().getFirst(); |
| 25 | + |
21 | 26 | public DetectorPieceBlock(Properties properties) { |
22 | 27 | super(properties); |
23 | 28 | this.registerDefaultState(this.defaultBlockState().setValue(ACTIVE, false)); |
@@ -46,14 +51,21 @@ protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direc |
46 | 51 | } |
47 | 52 |
|
48 | 53 | @Override |
49 | | - public void marbleEntered(ServerLevel level, BlockState state, BlockPos pos, MarbleEntity entity) { |
| 54 | + protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier applier) { |
| 55 | + if (!(level instanceof ServerLevel serverLevel) || !(entity instanceof MarbleEntity)) |
| 56 | + return; |
| 57 | + |
| 58 | + AABB detectionArea = DETECTION_AREA.move(pos); |
| 59 | + if (!entity.getBoundingBox().intersects(detectionArea)) |
| 60 | + return; |
| 61 | + |
50 | 62 | if (!state.getValue(ACTIVE)) { |
51 | | - toggle(level, state, pos); |
| 63 | + toggle(serverLevel, state, pos); |
52 | 64 | } |
53 | 65 |
|
54 | 66 | // cancel any previous scheduled ticks |
55 | | - level.getBlockTicks().clearArea(new BoundingBox(pos)); |
56 | | - level.scheduleTick(pos, this, ACTIVE_TICKS); |
| 67 | + serverLevel.getBlockTicks().clearArea(new BoundingBox(pos)); |
| 68 | + serverLevel.scheduleTick(pos, this, ACTIVE_TICKS); |
57 | 69 | } |
58 | 70 |
|
59 | 71 | private static void toggle(ServerLevel level, BlockState state, BlockPos pos) { |
|
0 commit comments