use of org.terasology.engine.logic.characters.events.OnEnterBlockEvent in project Terasology by MovingBlocks.
the class KinematicCharacterMover method checkBlockEntry.
/*
* Figure out if our position has put us into a new set of blocks and fire the appropriate events.
*/
private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i newPosition, float characterHeight) {
if (!oldPosition.equals(newPosition)) {
int characterHeightInBlocks = (int) Math.ceil(characterHeight);
// get the old position's blocks
Block[] oldBlocks = new Block[characterHeightInBlocks];
for (int y = 0; y < characterHeightInBlocks; y++) {
oldBlocks[y] = worldProvider.getBlock(oldPosition.x, oldPosition.y + y, oldPosition.z);
}
// get the new position's blocks
Block[] newBlocks = new Block[characterHeightInBlocks];
for (int y = 0; y < characterHeightInBlocks; y++) {
newBlocks[y] = worldProvider.getBlock(newPosition.x, newPosition.y + y, newPosition.z);
}
for (int y = 0; y < characterHeightInBlocks; y++) {
// send a block enter/leave event for this character
entity.send(new OnEnterBlockEvent(oldBlocks[y], newBlocks[y], new Vector3i(0, y, 0)));
}
}
}
Aggregations