use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onPrevItem.
@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onPrevItem(ToolbarPrevButton event, EntityRef entity, SelectedInventorySlotComponent selectedInventorySlotComponent) {
int prevSlot = (selectedInventorySlotComponent.slot + 9) % 10;
localPlayer.getCharacterEntity().send(new ChangeSelectedInventorySlotRequest(prevSlot));
event.consume();
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onGiveItemToEntity.
@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void onGiveItemToEntity(GiveItemEvent event, EntityRef entity) {
if (event.getTargetEntity().hasComponent(InventoryComponent.class)) {
if (inventoryManager.giveItem(event.getTargetEntity(), entity, entity)) {
event.getTargetEntity().send(new PlaySoundForOwnerEvent(Assets.getSound("engine:Loot").get(), 1.0f));
event.setHandled(true);
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onStartSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
blockSelectionComponent.startPosition = startPosition;
Vector3i endPosition = startPosition;
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onEndSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
Vector3i startPosition = blockSelectionComponent.startPosition;
if (null == startPosition) {
startPosition = endPosition;
}
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockEntitySystem method defaultDropsHandling.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, BlockComponent blockComponent) {
Vector3i location = blockComponent.getPosition();
commonDefaultDropsHandling(event, entity, location, blockComponent.getBlock());
}
Aggregations