Search in sources :

Example 6 with ItemComponent

use of org.terasology.logic.inventory.ItemComponent in project Terasology by MovingBlocks.

the class HealthAuthoritySystem method damageEntity.

static void damageEntity(AttackEvent event, EntityRef targetEntity) {
    int damage = 1;
    Prefab damageType = EngineDamageTypes.PHYSICAL.get();
    // Calculate damage from item
    ItemComponent item = event.getDirectCause().getComponent(ItemComponent.class);
    if (item != null) {
        damage = item.baseDamage;
        if (item.damageType != null) {
            damageType = item.damageType;
        }
    }
    targetEntity.send(new DoDamageEvent(damage, damageType, event.getInstigator(), event.getDirectCause()));
    // consume the event so that the health system can take priority over default engine behavior
    event.consume();
}
Also used : ItemComponent(org.terasology.logic.inventory.ItemComponent) Prefab(org.terasology.entitySystem.prefab.Prefab)

Example 7 with ItemComponent

use of org.terasology.logic.inventory.ItemComponent 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)

Aggregations

ItemComponent (org.terasology.logic.inventory.ItemComponent)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)4 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 Component (org.terasology.entitySystem.Component)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)2 InventoryComponent (org.terasology.logic.inventory.InventoryComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1 BlockItemComponent (org.terasology.world.block.items.BlockItemComponent)1 BlockItemFactory (org.terasology.world.block.items.BlockItemFactory)1