Search in sources :

Example 36 with ReceiveEvent

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();
}
Also used : ChangeSelectedInventorySlotRequest(org.terasology.logic.inventory.events.ChangeSelectedInventorySlotRequest) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 37 with ReceiveEvent

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);
        }
    }
}
Also used : PlaySoundForOwnerEvent(org.terasology.audio.events.PlaySoundForOwnerEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 38 with ReceiveEvent

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);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 39 with ReceiveEvent

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);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 40 with ReceiveEvent

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());
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2