use of org.terasology.logic.inventory.events.DropItemEvent 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