Search in sources :

Example 91 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method onSlotButton.

@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onSlotButton(ToolbarSlotButton event, EntityRef entity) {
    localPlayer.getCharacterEntity().send(new ChangeSelectedInventorySlotRequest(event.getSlot()));
    event.consume();
}
Also used : ChangeSelectedInventorySlotRequest(org.terasology.logic.inventory.events.ChangeSelectedInventorySlotRequest) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 92 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method ensureTransferSlotIsCreated.

@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void ensureTransferSlotIsCreated(OnAddedComponent event, EntityRef entityRef, CharacterComponent characterComponent) {
    EntityRef transferSlot = entityManager.create("core:transferSlot");
    characterComponent.movingItem = transferSlot;
    entityRef.saveComponent(characterComponent);
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 93 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method onDropItemRequest.

@ReceiveEvent(components = { CharacterComponent.class, InventoryComponent.class }, netFilter = RegisterMode.CLIENT)
public void onDropItemRequest(DropItemButton event, EntityRef entity) {
    CharacterHeldItemComponent characterHeldItemComponent = entity.getComponent(CharacterHeldItemComponent.class);
    EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
    if (selectedItemEntity.equals(EntityRef.NULL)) {
        return;
    }
    // this is a repeating event.
    if (event.isDown() && lastTimeThrowInteraction == 0) {
        lastTimeThrowInteraction = time.getGameTimeInMs();
        return;
    }
    // resize the crosshair
    InventoryHud toolbar = nuiManager.getHUD().getHUDElement("core:InventoryHud", InventoryHud.class);
    if (toolbar != null) {
        toolbar.setChargeAmount(getDropPower());
    }
    float dropPower = getDropPower();
    // handle when we finally let go
    if (!event.isDown()) {
        // Compute new position
        dropPower *= 150f;
        Vector3f position = localPlayer.getViewPosition();
        Vector3f direction = localPlayer.getViewDirection();
        Vector3f maxAllowedDistanceInDirection = direction.mul(1.5f);
        HitResult hitResult = physics.rayTrace(position, direction, 1.5f, StandardCollisionGroup.CHARACTER, StandardCollisionGroup.WORLD);
        if (hitResult.isHit()) {
            Vector3f possibleNewPosition = hitResult.getHitPoint();
            maxAllowedDistanceInDirection = possibleNewPosition.sub(position);
        }
        Vector3f newPosition = position;
        newPosition.add(maxAllowedDistanceInDirection.mul(0.9f));
        // send DropItemRequest
        Vector3f impulseVector = new Vector3f(direction);
        impulseVector.scale(dropPower);
        entity.send(new DropItemRequest(selectedItemEntity, entity, impulseVector, newPosition));
        characterHeldItemComponent.lastItemUsedTime = time.getGameTimeInMs();
        entity.saveComponent(characterHeldItemComponent);
        resetDropMark();
    }
    event.consume();
}
Also used : HitResult(org.terasology.physics.HitResult) DropItemRequest(org.terasology.logic.inventory.events.DropItemRequest) Vector3f(org.terasology.math.geom.Vector3f) InventoryHud(org.terasology.rendering.nui.layers.hud.InventoryHud) CharacterHeldItemComponent(org.terasology.logic.characters.CharacterHeldItemComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 94 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method onChangeSelectedInventorySlotRequested.

@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void onChangeSelectedInventorySlotRequested(ChangeSelectedInventorySlotRequest request, EntityRef character, SelectedInventorySlotComponent selectedInventorySlotComponent) {
    if (request.getSlot() >= 0 && request.getSlot() < 10 && request.getSlot() != selectedInventorySlotComponent.slot) {
        EntityRef newItem = InventoryUtils.getItemAt(character, request.getSlot());
        selectedInventorySlotComponent.slot = request.getSlot();
        character.saveComponent(selectedInventorySlotComponent);
        character.send(new ChangeHeldItemRequest(newItem));
    }
}
Also used : ChangeHeldItemRequest(org.terasology.logic.characters.events.ChangeHeldItemRequest) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 95 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class InventoryClientSystem method inventoryChangeAcknowledge.

@ReceiveEvent(components = { InventoryComponent.class })
public void inventoryChangeAcknowledge(InventoryChangeAcknowledgedRequest event, EntityRef entity) {
    // TODO: This does not ever get triggered because the event is sent to the client,  not the character.
    // If it did get triggered,  it causes a mess of question mark items.
    AbstractMoveItemRequest removedRequest = pendingMoves.remove(event.getChangeId());
    if (removedRequest != null) {
        destroyClientTempEntities(removedRequest);
    }
    recalculatePredictedState();
}
Also used : AbstractMoveItemRequest(org.terasology.logic.inventory.events.AbstractMoveItemRequest) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2