From 64a8f331884bfa34b3fc81de981b2b30dd6b5b20 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 15 Oct 2024 16:36:41 +0800 Subject: [PATCH] feat: reset entity motion if entity is moving into unloaded chunk --- .../server/entity/component/EntityBaseComponentImpl.java | 2 +- .../server/world/service/AllayEntityPhysicsService.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java index 66f38f723..2f3dd1014 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java @@ -339,7 +339,7 @@ protected boolean checkChunk(Location3fc oldLoc, Location3fc newLoc) { if (newChunk == null) { // Moving into an unloaded chunk is not allowed. Because the chunk holds the entity, // moving to an unloaded chunk will result in the loss of the entity - log.warn("New chunk {} {} is null while moving entity!", newChunkX, newChunkZ); + log.warn("Entity {} is trying to move into unloaded chunk {} {}", runtimeId, newChunkX, newChunkZ); return false; } diff --git a/server/src/main/java/org/allaymc/server/world/service/AllayEntityPhysicsService.java b/server/src/main/java/org/allaymc/server/world/service/AllayEntityPhysicsService.java index f3117080f..440ebbb9d 100644 --- a/server/src/main/java/org/allaymc/server/world/service/AllayEntityPhysicsService.java +++ b/server/src/main/java/org/allaymc/server/world/service/AllayEntityPhysicsService.java @@ -501,6 +501,9 @@ protected boolean updateEntityLocation(Entity entity, Location3fc newLoc) { baseComponent.broadcastMoveToViewers(newLoc, false); return true; } else { + // Entity is moving into unloaded chunk, and we need to reset the motion + // to prevent the entity from moving into unloaded chunk continuously + entity.setMotion(0, 0, 0); return false; } }