Search in sources :

Example 1 with InventorySlotStackSizeChangedEvent

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

the class InventoryUtils method adjustStackSize.

static void adjustStackSize(EntityRef entity, int slot, int newCount) {
    InventoryComponent inventory = entity.getComponent(InventoryComponent.class);
    EntityRef item = inventory.itemSlots.get(slot);
    ItemComponent itemComponent = item.getComponent(ItemComponent.class);
    byte oldSize = itemComponent.stackCount;
    itemComponent.stackCount = (byte) newCount;
    item.saveComponent(itemComponent);
    entity.send(new InventorySlotStackSizeChangedEvent(slot, oldSize, newCount));
}
Also used : InventorySlotStackSizeChangedEvent(org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)1 InventorySlotStackSizeChangedEvent (org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent)1