Search in sources :

Example 1 with ImpulseEvent

use of org.terasology.physics.events.ImpulseEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method onDropItemRequest.

@ReceiveEvent(components = { CharacterComponent.class, LocationComponent.class }, netFilter = RegisterMode.AUTHORITY)
public void onDropItemRequest(DropItemRequest event, EntityRef character) {
    // make sure we own the item and it exists
    if (!event.getItem().exists() || !networkSystem.getOwnerEntity(event.getItem()).equals(networkSystem.getOwnerEntity(character))) {
        return;
    }
    int count = event.getCount();
    // remove 'count' items from the stack
    EntityRef pickupItem = event.getItem();
    EntityRef owner = pickupItem.getOwner();
    if (owner.hasComponent(InventoryComponent.class)) {
        final EntityRef removedItem = inventoryManager.removeItem(owner, EntityRef.NULL, pickupItem, false, count);
        if (removedItem != null) {
            pickupItem = removedItem;
        }
    }
    pickupItem.send(new DropItemEvent(event.getNewPosition()));
    if (pickupItem.hasComponent(PickupComponent.class)) {
        PickupComponent pickupComponent = pickupItem.getComponent(PickupComponent.class);
        pickupComponent.timeDropped = time.getGameTimeInMs();
        pickupItem.saveComponent(pickupComponent);
    }
    pickupItem.send(new ImpulseEvent(event.getImpulse()));
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) ImpulseEvent(org.terasology.physics.events.ImpulseEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with ImpulseEvent

use of org.terasology.physics.events.ImpulseEvent in project Terasology by MovingBlocks.

the class BlockEntitySystem method processDropping.

private void processDropping(EntityRef item, Vector3i location, float impulsePower) {
    item.send(new DropItemEvent(location.toVector3f()));
    item.send(new ImpulseEvent(random.nextVector3f(impulsePower)));
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) ImpulseEvent(org.terasology.physics.events.ImpulseEvent)

Example 3 with ImpulseEvent

use of org.terasology.physics.events.ImpulseEvent 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)3 ImpulseEvent (org.terasology.physics.events.ImpulseEvent)3 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3f (org.terasology.math.geom.Vector3f)1 FastRandom (org.terasology.utilities.random.FastRandom)1