From 8f0ca99a1e84af7fdde934f64af8aba054f1d202 Mon Sep 17 00:00:00 2001 From: Connor <83981186+utfunderscore@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:05:24 +0000 Subject: [PATCH] Remove entity if it passes into void, and use chunk cache to prevent errors in unloaded chunks Signed-off-by: Connor <83981186+utfunderscore@users.noreply.github.com> --- .../pvp/entity/projectile/CustomEntityProjectile.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/togar2/pvp/entity/projectile/CustomEntityProjectile.java b/src/main/java/io/github/togar2/pvp/entity/projectile/CustomEntityProjectile.java index 4ffcf20..be8794b 100644 --- a/src/main/java/io/github/togar2/pvp/entity/projectile/CustomEntityProjectile.java +++ b/src/main/java/io/github/togar2/pvp/entity/projectile/CustomEntityProjectile.java @@ -14,6 +14,7 @@ import net.minestom.server.event.entity.projectile.ProjectileUncollideEvent; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.block.Block; +import net.minestom.server.utils.chunk.ChunkCache; import net.minestom.server.utils.chunk.ChunkUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -212,8 +213,15 @@ protected void movementTick() { if (!isStuck()) { Vec diff = velocity.div(ServerFlag.SERVER_TICKS_PER_SECOND); + // Prevent entity infinitely in the void + if(instance.isInVoid(position)) { + scheduler().scheduleNextProcess(this::remove); + return; + } + ChunkCache blockGetter = new ChunkCache(instance, instance.getChunkAt(position), Block.AIR); + PhysicsResult physicsResult = ProjectileUtil.simulateMovement(position, diff, POINT_BOX, - instance.getWorldBorder(), instance, hasPhysics, previousPhysicsResult, true); + instance.getWorldBorder(), blockGetter, hasPhysics, previousPhysicsResult, true); this.previousPhysicsResult = physicsResult; Pos newPosition = physicsResult.newPosition();