Skip to content

Commit 5675d9f

Browse files
committed
make detector stay active instead of pulsing
1 parent 6116809 commit 5675d9f

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

common/src/main/java/one/devos/nautical/losing_my_marbles/content/piece/logic/DetectorPieceBlock.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
import net.minecraft.core.Direction;
55
import net.minecraft.server.level.ServerLevel;
66
import net.minecraft.util.RandomSource;
7+
import net.minecraft.world.entity.Entity;
8+
import net.minecraft.world.entity.InsideBlockEffectApplier;
79
import net.minecraft.world.level.BlockGetter;
10+
import net.minecraft.world.level.Level;
811
import net.minecraft.world.level.block.Block;
912
import net.minecraft.world.level.block.state.BlockState;
1013
import net.minecraft.world.level.block.state.StateDefinition;
1114
import net.minecraft.world.level.block.state.properties.BooleanProperty;
1215
import net.minecraft.world.level.levelgen.structure.BoundingBox;
16+
import net.minecraft.world.phys.AABB;
1317
import one.devos.nautical.losing_my_marbles.content.marble.MarbleEntity;
1418
import one.devos.nautical.losing_my_marbles.content.piece.StraightPieceBlock;
15-
import one.devos.nautical.losing_my_marbles.framework.block.MarbleListeningBlock;
1619

17-
public final class DetectorPieceBlock extends StraightPieceBlock implements MarbleListeningBlock {
20+
public final class DetectorPieceBlock extends StraightPieceBlock {
1821
public static final int ACTIVE_TICKS = 10;
1922
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
2023

24+
public static final AABB DETECTION_AREA = box(4, 8, 6, 12, 14, 10).toAabbs().getFirst();
25+
2126
public DetectorPieceBlock(Properties properties) {
2227
super(properties);
2328
this.registerDefaultState(this.defaultBlockState().setValue(ACTIVE, false));
@@ -46,14 +51,21 @@ protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direc
4651
}
4752

4853
@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+
5062
if (!state.getValue(ACTIVE)) {
51-
toggle(level, state, pos);
63+
toggle(serverLevel, state, pos);
5264
}
5365

5466
// 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);
5769
}
5870

5971
private static void toggle(ServerLevel level, BlockState state, BlockPos pos) {

0 commit comments

Comments
 (0)