Search in sources :

Example 1 with OnEnterBlockEvent

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)));
        }
    }
}
Also used : Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) OnEnterBlockEvent(org.terasology.engine.logic.characters.events.OnEnterBlockEvent)

Aggregations

Vector3i (org.joml.Vector3i)1 OnEnterBlockEvent (org.terasology.engine.logic.characters.events.OnEnterBlockEvent)1 Block (org.terasology.engine.world.block.Block)1