Search in sources :

Example 6 with DropItemEvent

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)));
        }
    }
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) FastRandom(org.terasology.utilities.random.FastRandom) ImpulseEvent(org.terasology.physics.events.ImpulseEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)3 ClientComponent (org.terasology.network.ClientComponent)3 ImpulseEvent (org.terasology.physics.events.ImpulseEvent)3 BlockFamily (org.terasology.world.block.family.BlockFamily)3 BlockItemFactory (org.terasology.world.block.items.BlockItemFactory)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 FastRandom (org.terasology.utilities.random.FastRandom)1