}
// Handle block collisions
BlockFace hitFace;
Iterator<AxisAlignedBB> iter = collisionBuffer.iterator();
AxisAlignedBB blockBounds;
double dx, dz;
while (iter.hasNext()) {
blockBounds = iter.next();
// Convert to block and block coordinates
org.bukkit.block.Block block = entity.getWorld().getBlockAt(MathUtil.floor(blockBounds.a), MathUtil.floor(blockBounds.b), MathUtil.floor(blockBounds.c));
// Find out what direction the block is hit
if (bounds.e > blockBounds.e) {
hitFace = BlockFace.UP;
} else if (bounds.b < blockBounds.b) {
hitFace = BlockFace.DOWN;
} else {
dx = entity.loc.getX() - block.getX() - 0.5;
dz = entity.loc.getZ() - block.getZ() - 0.5;
hitFace = FaceUtil.getDirection(dx, dz, false);
}
// Block collision event
if (!controller.onBlockCollision(block, hitFace)) {
iter.remove();
}
}
// Handle and add entities
AxisAlignedBB entityBounds;
for (Entity collider : CommonNMS.getEntitiesIn(handle.world, handle, bounds.grow(0.25, 0.25, 0.25))) {
/*
* This part is completely pointless as E() always returns null May
* this ever change, make sure E() is handled correctly.
*
* entityBounds = entity.E(); if (entityBounds != null &&
* entityBounds.a(bounds)) { collisionBuffer.add(entityBounds); }
*/
entityBounds = collider.boundingBox;
// Entity collision event after the null/inBounds check
if (entityBounds != null && entityBounds.b(bounds) && controller.onEntityCollision(Conversion.toEntity.convert(collider))) {
collisionBuffer.add(entityBounds);
}
}
// Done