use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerSystem method onRespawnRequest.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL, components = ClientComponent.class)
public void onRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
Vector3f spawnPosition = entity.getComponent(LocationComponent.class).getWorldPosition(new Vector3f());
if (worldProvider.isBlockRelevant(spawnPosition)) {
respawnPlayer(entity);
} else {
updateRelevanceEntity(entity, ViewDistance.LEGALLY_BLIND.getChunkDistance());
SpawningClientInfo info = new SpawningClientInfo(entity, spawnPosition);
clientsPreparingToRespawn.add(info);
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerSystem method onConnect.
@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
// for new clients, the player store will return default values
PlayerStore playerStore = connected.getPlayerStore();
Client owner = networkSystem.getOwner(entity);
Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
if (playerStore.hasCharacter()) {
Vector3fc storedLocation = playerStore.getRelevanceLocation();
loc.setWorldPosition(storedLocation);
entity.saveComponent(loc);
if (worldProvider.isBlockRelevant(storedLocation)) {
// chunk for spawning location is ready, so spawn right now
playerStore.restoreEntities();
EntityRef character = playerStore.getCharacter();
Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
addRelevanceEntity(entity, viewDist, owner);
restoreCharacter(entity, character);
} else {
// otherwise wait until chunk is ready
addRelevanceEntity(entity, minViewDist, owner);
clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
}
} else {
Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
loc.setWorldPosition(spawnPosition);
entity.saveComponent(loc);
addRelevanceEntity(entity, minViewDist, owner);
if (worldProvider.isBlockRelevant(spawnPosition)) {
spawnPlayer(entity);
} else {
clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
}
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class NUIManagerInternal method mouseWheelEvent.
// mouse wheel events
@ReceiveEvent(components = ClientComponent.class, priority = EventPriority.PRIORITY_HIGH)
public void mouseWheelEvent(MouseWheelEvent event, EntityRef entity) {
if (!mouse.isVisible()) {
return;
}
Vector2i mousePosition = event.getMousePosition();
if (focus != null) {
NUIMouseWheelEvent nuiEvent = new NUIMouseWheelEvent(mouse, keyboard, mousePosition, event.getWheelTurns());
focus.onMouseWheelEvent(nuiEvent);
if (nuiEvent.isConsumed()) {
event.consume();
return;
}
}
if (canvas.processMouseWheel(event.getWheelTurns(), mousePosition)) {
event.consume();
}
if (isReleasingMouse()) {
event.consume();
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onRespawn.
@ReceiveEvent
public void onRespawn(OnPlayerRespawnedEvent event, EntityRef character, CharacterSoundComponent characterSounds) {
if (characterSounds.respawnSounds.size() > 0) {
StaticSound sound = random.nextItem(characterSounds.respawnSounds);
character.send(new PlaySoundEvent(character, sound, characterSounds.respawnVolume));
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onEnterBlock.
@ReceiveEvent
public void onEnterBlock(OnEnterBlockEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
// only play this sound if the feet hit the water
if (event.getCharacterRelativePosition().y == 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
boolean oldBlockIsLiquid = event.getOldBlock().isLiquid();
boolean newBlockIsLiquid = event.getNewBlock().isLiquid();
StaticSound sound = null;
if (!oldBlockIsLiquid && newBlockIsLiquid) {
sound = random.nextItem(characterSounds.enterWaterSounds);
} else if (oldBlockIsLiquid && !newBlockIsLiquid) {
sound = random.nextItem(characterSounds.leaveWaterSounds);
}
if (sound != null) {
entity.send(new PlaySoundEvent(entity, sound, characterSounds.diveVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
Aggregations