mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-01 00:10:19 +01:00
fix: Entity#onGround returning true when entities aren't actually on ground
This commit is contained in:
parent
5bf4b4445a
commit
5c050c66ca
@ -271,7 +271,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnGround() {
|
public boolean isOnGround() {
|
||||||
return onGround || EntityUtils.isOnGround(this) /* backup for levitating entities */;
|
return onGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,22 +30,4 @@ public final class EntityUtils {
|
|||||||
|
|
||||||
private EntityUtils() {
|
private EntityUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOnGround(@NotNull Entity entity) {
|
|
||||||
final Chunk chunk = entity.getChunk();
|
|
||||||
if (chunk == null)
|
|
||||||
return false;
|
|
||||||
final Pos entityPosition = entity.getPosition();
|
|
||||||
// TODO: check entire bounding box
|
|
||||||
try {
|
|
||||||
final Block block;
|
|
||||||
synchronized (chunk) {
|
|
||||||
block = chunk.getBlock(entityPosition.sub(0, 1, 0));
|
|
||||||
}
|
|
||||||
return block.isSolid();
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
// Probably an entity at the border of an unloaded chunk
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,10 @@ public class EntityVelocityIntegrationTest {
|
|||||||
// Only entities on the ground should ignore the default velocity.
|
// Only entities on the ground should ignore the default velocity.
|
||||||
assertTrue(entity.hasVelocity());
|
assertTrue(entity.hasVelocity());
|
||||||
|
|
||||||
env.tick();
|
// Tick entity so it falls on the ground
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
entity.tick(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Now that the entity is on the ground, it should no longer have a velocity.
|
// Now that the entity is on the ground, it should no longer have a velocity.
|
||||||
assertFalse(entity.hasVelocity());
|
assertFalse(entity.hasVelocity());
|
||||||
|
Loading…
Reference in New Issue
Block a user