From b0bc389efda9f5d66c52abcfb7b8e6e8b1886f39 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 2 Feb 2025 04:45:26 +0800 Subject: [PATCH] feat: entity will be push out from block by default now --- .../entity/component/EntityBaseComponent.java | 2 +- .../EntityPickableBaseComponentImpl.java | 5 --- .../service/AllayEntityPhysicsService.java | 38 ++++++++++++------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/api/src/main/java/org/allaymc/api/entity/component/EntityBaseComponent.java b/api/src/main/java/org/allaymc/api/entity/component/EntityBaseComponent.java index e7f3aa5f3e..e883238fff 100644 --- a/api/src/main/java/org/allaymc/api/entity/component/EntityBaseComponent.java +++ b/api/src/main/java/org/allaymc/api/entity/component/EntityBaseComponent.java @@ -337,7 +337,7 @@ default boolean computeEntityCollisionMotion() { * @return {@code true} if the entity has block collision motion. */ default boolean computeBlockCollisionMotion() { - return false; + return true; } /** diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityPickableBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityPickableBaseComponentImpl.java index 773bccc0b0..982b61e06e 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityPickableBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityPickableBaseComponentImpl.java @@ -67,11 +67,6 @@ public NbtMap saveNBT() { return builder.build(); } - @Override - public boolean computeBlockCollisionMotion() { - return true; - } - @Override public float getGravity() { return 0.04f; 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 ca68b64f66..274b2bb3b8 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 @@ -59,7 +59,8 @@ public class AllayEntityPhysicsService implements EntityPhysicsService { public static final float BLOCK_COLLISION_MOTION; /** * When the min distance of entity to the collision shape of block is smaller than FAT_AABB_MARGIN, - * the entity will be considered as collided with the block. This is what the vanilla actually does. + * the entity will be considered as collided with the block. This is used to prevent floating point + * number overflow problem and is what the vanilla actually does. *
* This value is actually the value of the y coordinate decimal point when the player stands on the
* full block (such as the grass block)
@@ -418,7 +419,9 @@ protected boolean applyMotion(Entity entity) {
*/
private float applyMotion0(float stepHeight, Location3f pos, float motion, AABBf aabb, boolean enableStepping, int axis) {
if (motion == 0) return motion;
- if (axis < X || axis > Z) throw new IllegalArgumentException("Invalid axis: " + axis);
+ if (axis < X || axis > Z) {
+ throw new IllegalArgumentException("Invalid axis: " + axis);
+ }
var resultAABB = new AABBf(aabb);
var resultPos = new Vector3f(pos);
@@ -456,33 +459,36 @@ private float applyMotion0(float stepHeight, Location3f pos, float motion, AABBf
* @throws IllegalArgumentException if an invalid axis is provided.
*/
private Pair