Search in sources :

Example 46 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class PlayerSystem method respawnPlayer.

private void respawnPlayer(EntityRef clientEntity) {
    ClientComponent client = clientEntity.getComponent(ClientComponent.class);
    EntityRef playerCharacter = client.character;
    LocationComponent location = playerCharacter.getComponent(LocationComponent.class);
    PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
    Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
    playerCharacter.addComponent(new AliveCharacterComponent());
    playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
    logger.debug("Re-spawing player at: {}", spawnPosition);
    Client clientListener = networkSystem.getOwner(clientEntity);
    Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
    updateRelevanceEntity(clientEntity, distance);
    playerCharacter.send(new OnPlayerRespawnedEvent());
}
Also used : CharacterTeleportEvent(org.terasology.engine.logic.characters.CharacterTeleportEvent) Vector3ic(org.joml.Vector3ic) Vector3f(org.joml.Vector3f) Client(org.terasology.engine.network.Client) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) OnPlayerRespawnedEvent(org.terasology.engine.logic.players.event.OnPlayerRespawnedEvent) AliveCharacterComponent(org.terasology.engine.logic.characters.AliveCharacterComponent)

Example 47 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class LocalPlayerBlockSelectionByItemSystem method onCamTargetChanged.

@ReceiveEvent(components = LocationComponent.class)
public void onCamTargetChanged(CameraTargetChangedEvent event, EntityRef entity) {
    // This method will update the block selection to whatever block is targeted in the players view
    if (null == blockSelectionComponentEntity) {
        return;
    }
    BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
    if (blockSelectionComponent == null) {
        return;
    }
    EntityRef target = event.getNewTarget();
    LocationComponent locationComponent = target.getComponent(LocationComponent.class);
    if (locationComponent == null) {
        return;
    }
    Vector3f targetLocation = locationComponent.getWorldPosition(new Vector3f());
    if (blockSelectionComponent.isMovable) {
        Vector3i pos = new Vector3i(targetLocation, RoundingMode.FLOOR);
        Vector3i size = blockSelectionComponent.currentSelection.getSize(new Vector3i());
        blockSelectionComponent.currentSelection.set(pos, pos).expand(size.x() / 2, 0, size.z() / 2);
        blockSelectionComponentEntity.saveComponent(blockSelectionComponent);
        return;
    }
    if (blockSelectionComponent.startPosition == null) {
        return;
    }
    target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
Also used : SetBlockSelectionEndingPointEvent(org.terasology.engine.world.selection.event.SetBlockSelectionEndingPointEvent) BlockSelectionComponent(org.terasology.engine.world.selection.BlockSelectionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 48 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class AudioSystem method onPlaySound.

/**
 * Receives the sound played event and calls on the AudioManager to play it.
 *
 * @param playSoundEvent The sound event.
 * @param entity The entity that instigated the event.
 */
@ReceiveEvent
public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    if (location != null) {
        Vector3f pos = location.getWorldPosition(new Vector3f());
        if (pos.isFinite()) {
            audioManager.playSound(playSoundEvent.getSound(), pos, playSoundEvent.getVolume(), AudioManager.PRIORITY_NORMAL);
            return;
        } else {
            logger.warn("Can't play sound with non-finite position/rotation?! Entity: {}", entity);
        }
    }
    audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 49 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class TargetSystem method updateTarget.

public boolean updateTarget(Vector3f pos, Vector3f dir, float maxDist) {
    if (targetBlockPos != null && !target.exists()) {
        target = blockRegistry.getEntityAt(targetBlockPos);
    }
    HitResult hitInfo = physics.rayTrace(pos, dir, maxDist, filter);
    EntityRef newTarget = hitInfo.getEntity();
    if (hitInfo.isWorldHit()) {
        if (targetBlockPos != null) {
            if (targetBlockPos.equals(hitInfo.getBlockPosition())) {
                return false;
            }
        }
        targetBlockPos = hitInfo.getBlockPosition();
    } else {
        if (target.equals(newTarget)) {
            return false;
        }
        targetBlockPos = null;
    }
    prevTarget = target;
    target = newTarget;
    LocationComponent location = target.getComponent(LocationComponent.class);
    if (location != null && targetBlockPos != null) {
        location.setLocalPosition(new Vector3f(targetBlockPos));
    }
    return true;
}
Also used : HitResult(org.terasology.engine.physics.HitResult) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 50 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class ActivateEvent method getInstigatorLocation.

public Vector3f getInstigatorLocation() {
    LocationComponent loc = instigator.getComponent(LocationComponent.class);
    if (loc != null) {
        Vector3f result = loc.getWorldPosition(new Vector3f());
        if (result.isFinite()) {
            return result;
        }
        result.set(0, 0, 0);
        return result;
    }
    return new Vector3f();
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Aggregations

LocationComponent (org.terasology.engine.logic.location.LocationComponent)65 Vector3f (org.joml.Vector3f)46 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)40 Quaternionf (org.joml.Quaternionf)18 ClientComponent (org.terasology.engine.network.ClientComponent)17 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)9 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)9 Matrix4f (org.joml.Matrix4f)7 Vector3i (org.joml.Vector3i)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)5 Vector3fc (org.joml.Vector3fc)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)4 CharacterHeldItemComponent (org.terasology.engine.logic.characters.CharacterHeldItemComponent)4 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)4 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)4 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 Bone (org.terasology.engine.rendering.assets.skeletalmesh.Bone)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Component (org.terasology.gestalt.entitysystem.component.Component)4