use of org.terasology.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) {
// is this a different position than previously
if (!oldPosition.equals(newPosition)) {
Biome oldBiome = worldProvider.getBiome(oldPosition);
Biome newBiome = worldProvider.getBiome(newPosition);
if (oldBiome != newBiome) {
entity.send(new OnEnterBiomeEvent(oldPosition, newPosition, oldBiome, newBiome));
}
// get the old position's blocks
Block[] oldBlocks = new Block[(int) Math.ceil(characterHeight)];
Vector3i currentPosition = new Vector3i(oldPosition);
for (int currentHeight = 0; currentHeight < oldBlocks.length; currentHeight++) {
oldBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
currentPosition.add(0, 1, 0);
}
// get the new position's blocks
Block[] newBlocks = new Block[(int) Math.ceil(characterHeight)];
currentPosition = new Vector3i(newPosition);
for (int currentHeight = 0; currentHeight < characterHeight; currentHeight++) {
newBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
currentPosition.add(0, 1, 0);
}
for (int i = 0; i < characterHeight; i++) {
// send a block enter/leave event for this character
entity.send(new OnEnterBlockEvent(oldBlocks[i], newBlocks[i], new Vector3i(0, i, 0)));
}
}
}
Aggregations