Search in sources :

Example 46 with ReceiveEvent

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);
    }
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 47 with ReceiveEvent

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));
        }
    }
}
Also used : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 48 with ReceiveEvent

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();
    }
}
Also used : NUIMouseWheelEvent(org.terasology.nui.events.NUIMouseWheelEvent) Vector2i(org.joml.Vector2i) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 49 with ReceiveEvent

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));
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 50 with ReceiveEvent

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);
        }
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2