diff --git a/src/main/java/net/minestom/server/collision/PhysicsUtils.java b/src/main/java/net/minestom/server/collision/PhysicsUtils.java index fa99622eb..76089299f 100644 --- a/src/main/java/net/minestom/server/collision/PhysicsUtils.java +++ b/src/main/java/net/minestom/server/collision/PhysicsUtils.java @@ -47,7 +47,7 @@ public final class PhysicsUtils { private static @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) { if (!positionChanged) { - if (entityOnGround || entityFlying) return Vec.ZERO; + if (entityFlying) return Vec.ZERO; return new Vec(0, entityNoGravity ? 0 : -aerodynamics.gravity() * aerodynamics.verticalAirResistance(), 0); } diff --git a/src/test/java/net/minestom/server/entity/EntityPhysicsIntegrationTest.java b/src/test/java/net/minestom/server/entity/EntityPhysicsIntegrationTest.java new file mode 100644 index 000000000..c5b04f65c --- /dev/null +++ b/src/test/java/net/minestom/server/entity/EntityPhysicsIntegrationTest.java @@ -0,0 +1,32 @@ +package net.minestom.server.entity; + +import net.minestom.server.coordinate.Pos; +import net.minestom.server.instance.block.Block; +import net.minestom.testing.Env; +import net.minestom.testing.EnvTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +@EnvTest +public class EntityPhysicsIntegrationTest +{ + @Test + public void onGround(Env env) { + var instance = env.createFlatInstance(); + instance.setBlock(1, 40, 1, Block.STONE); + + var entity = new Entity(EntityTypes.ZOMBIE); + entity.setInstance(instance, new Pos(1, 41, 1)).join(); + env.tick(); + + // Entity shouldn't be on ground because it intitially spawns in with onGround = false + // and a velocity of 0, it'll take 1 entity tick for gravity to be applied to their velocity + // and a downward block collision to occur + assertFalse(entity.onGround); + for (int i = 0; i < 10; i++) { + env.tick(); + assertTrue(entity.onGround, "entity needs to be grounded on tick: " + entity.getAliveTicks()); + } + } +}