use of org.terasology.engine.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.engine.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.engine.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;
int stackLimit = blockFamily.getArchetypeBlock().isStackable() ? 99 : 1;
int quantityLeft;
for (quantityLeft = quantity; quantityLeft > 0; quantityLeft = quantityLeft - stackLimit) {
EntityRef item = blockItemFactory.newInstance(blockFamily, Math.min(quantity, stackLimit));
if (!item.exists()) {
throw new IllegalArgumentException("Unknown block or item");
}
GiveItemEvent giveItemEvent = new GiveItemEvent(playerEntity);
item.send(giveItemEvent);
if (!giveItemEvent.isHandled()) {
item.destroy();
break;
}
}
return "You received " + (quantity - quantityLeft) + " blocks of " + blockFamily.getDisplayName();
}
Aggregations