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