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
}
}
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);
}
}
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)));
}
}
}
Aggregations