Search in sources :

Example 1 with ChangeHeldItemRequest

use of org.terasology.logic.characters.events.ChangeHeldItemRequest in project Terasology by MovingBlocks.

the class BuilderHeldItemAuthoritySystem method onGiveItemToCharacterHoldItem.

@ReceiveEvent
public void onGiveItemToCharacterHoldItem(GiveItemEvent event, EntityRef item, ItemComponent itemComponent) {
    if (event.getTargetEntity().hasComponent(CharacterHeldItemComponent.class)) {
        event.getTargetEntity().addOrSaveComponent(new CharacterOwnedItemComponent(item));
        event.getTargetEntity().send(new ChangeHeldItemRequest(item));
        event.setHandled(true);
    }
}
Also used : ChangeHeldItemRequest(org.terasology.logic.characters.events.ChangeHeldItemRequest) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with ChangeHeldItemRequest

use of org.terasology.logic.characters.events.ChangeHeldItemRequest 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)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 ChangeHeldItemRequest (org.terasology.logic.characters.events.ChangeHeldItemRequest)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)1