mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-15 03:41:30 +01:00
fix: entity onGround applies correctly (#2059)
This commit is contained in:
parent
f95d73eca8
commit
f09d3db999
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user