fix: Entity#onGround returning true when entities aren't actually on ground

This commit is contained in:
DeidaraMC 2024-04-30 22:01:20 -04:00 committed by iam
parent 5bf4b4445a
commit 5c050c66ca
3 changed files with 5 additions and 20 deletions

View File

@ -271,7 +271,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
}
public boolean isOnGround() {
return onGround || EntityUtils.isOnGround(this) /* backup for levitating entities */;
return onGround;
}
/**

View File

@ -30,22 +30,4 @@ public final class 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;
}
}
}

View File

@ -158,7 +158,10 @@ public class EntityVelocityIntegrationTest {
// Only entities on the ground should ignore the default velocity.
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.
assertFalse(entity.hasVelocity());