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