Search in sources :

Example 96 with ReceiveEvent

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

the class InventoryUIClientSystem method onToggleInventory.

/*
     * At the activation of the inventory the current dialog needs to be closed instantly.
     *
     * The close of the dialog triggers {@link #onScreenLayerClosed} which resets the
     * interactionTarget.
     */
@ReceiveEvent(components = ClientComponent.class, priority = EventPriority.PRIORITY_HIGH)
public void onToggleInventory(InventoryButton event, EntityRef entity, ClientComponent clientComponent) {
    if (event.getState() != ButtonState.DOWN) {
        return;
    }
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if (activeInteractionScreenUri != null) {
        InteractionUtil.cancelInteractionAsClient(character);
    // do not consume the event, so that the inventory will still open
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 97 with ReceiveEvent

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

the class BlockInventorySystem method copyBlockInventory.

@ReceiveEvent(components = { InventoryComponent.class, RetainBlockInventoryComponent.class })
public void copyBlockInventory(OnBlockToItem event, EntityRef blockEntity) {
    EntityRef inventoryItem = event.getItem();
    int slotCount = InventoryUtils.getSlotCount(blockEntity);
    inventoryItem.addComponent(new InventoryComponent(slotCount));
    for (int i = 0; i < slotCount; i++) {
        inventoryManager.switchItem(blockEntity, blockEntity, i, inventoryItem, i);
    }
    ItemComponent itemComponent = inventoryItem.getComponent(ItemComponent.class);
    if (itemComponent != null && !itemComponent.stackId.isEmpty()) {
        itemComponent.stackId = "";
        inventoryItem.saveComponent(itemComponent);
    }
}
Also used : InventoryComponent(org.terasology.logic.inventory.InventoryComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) BlockItemComponent(org.terasology.world.block.items.BlockItemComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 98 with ReceiveEvent

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

the class BlockInventorySystem method dropContentsOfInventory.

@ReceiveEvent(components = { InventoryComponent.class, DropBlockInventoryComponent.class, LocationComponent.class })
public void dropContentsOfInventory(DoDestroyEvent event, EntityRef entity) {
    Vector3f position = entity.getComponent(LocationComponent.class).getWorldPosition();
    FastRandom random = new FastRandom();
    int slotCount = InventoryUtils.getSlotCount(entity);
    for (int i = 0; i < slotCount; i++) {
        EntityRef itemInSlot = InventoryUtils.getItemAt(entity, i);
        if (itemInSlot.exists()) {
            inventoryManager.removeItem(entity, entity, itemInSlot, false);
            itemInSlot.send(new DropItemEvent(position));
            itemInSlot.send(new ImpulseEvent(random.nextVector3f(30.0f)));
        }
    }
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) FastRandom(org.terasology.utilities.random.FastRandom) ImpulseEvent(org.terasology.physics.events.ImpulseEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) 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