use of org.terasology.logic.inventory.events.GiveItemEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onBumpGiveItemToEntity.
@ReceiveEvent
public void onBumpGiveItemToEntity(CollideEvent event, EntityRef entity, PickupComponent pickupComponent) {
if (pickupComponent.timeDropped + pickupComponent.timeToPickUp < time.getGameTimeInMs()) {
GiveItemEvent giveItemEvent = new GiveItemEvent(event.getOtherEntity());
entity.send(giveItemEvent);
if (giveItemEvent.isHandled()) {
// remove all the components added from the pickup prefab
ItemComponent itemComponent = entity.getComponent(ItemComponent.class);
if (itemComponent != null) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
entity.removeComponent(component.getClass());
}
}
}
}
}
use of org.terasology.logic.inventory.events.GiveItemEvent in project Terasology by MovingBlocks.
the class BlockEntitySystem method giveItem.
private boolean giveItem(CreateBlockDropsEvent event, EntityRef item) {
GiveItemEvent giveItemEvent = new GiveItemEvent(event.getInstigator());
item.send(giveItemEvent);
return giveItemEvent.isHandled();
}
use of org.terasology.logic.inventory.events.GiveItemEvent in project Terasology by MovingBlocks.
the class BlockCommands method giveBlock.
/**
* Actual implementation of the giveBlock command.
*
* @param blockFamily the block family of the queried block
* @param quantity the number of blocks that are queried
*/
private String giveBlock(BlockFamily blockFamily, int quantity, EntityRef client) {
if (quantity < 1) {
return "Here, have these zero (0) blocks just like you wanted";
}
EntityRef playerEntity = client.getComponent(ClientComponent.class).character;
for (int quantityLeft = quantity; quantityLeft > 0; quantityLeft--) {
EntityRef item = blockItemFactory.newInstance(blockFamily, 1);
if (!item.exists()) {
throw new IllegalArgumentException("Unknown block or item");
}
GiveItemEvent giveItemEvent = new GiveItemEvent(playerEntity);
item.send(giveItemEvent);
if (!giveItemEvent.isHandled()) {
item.destroy();
quantity -= quantityLeft;
break;
}
}
return "You received " + quantity + " blocks of " + blockFamily.getDisplayName();
}
Aggregations