Search in sources :

Example 1 with SetBlockSelectionStartingPointEvent

use of org.terasology.engine.world.selection.event.SetBlockSelectionStartingPointEvent in project Terasology by MovingBlocks.

the class LocalPlayerBlockSelectionByItemSystem method onPlaced.

@ReceiveEvent(components = OnItemActivateSelectionComponent.class)
public void onPlaced(ActivateEvent event, EntityRef itemEntity) {
    if (event.getTargetLocation() == null) {
        return;
    }
    EntityRef targetLocationEntity = event.getTarget();
    this.blockSelectionComponentEntity = itemEntity;
    BlockSelectionComponent blockSelectionComponent = itemEntity.getComponent(BlockSelectionComponent.class);
    if (null == blockSelectionComponent.startPosition) {
        // on the first item click, we start selecting blocks
        targetLocationEntity.send(new SetBlockSelectionStartingPointEvent(itemEntity));
        blockSelectionComponent.shouldRender = true;
    } else {
        // on the second item click, we will set the ending selection point and send an ApplyBlockSelectionEvent
        targetLocationEntity.send(new SetBlockSelectionEndingPointEvent(itemEntity));
        localPlayer.getCharacterEntity().send(new ApplyBlockSelectionEvent(itemEntity, blockSelectionComponent.currentSelection));
        blockSelectionComponent.shouldRender = false;
        blockSelectionComponent.currentSelection = null;
        blockSelectionComponent.startPosition = null;
    }
}
Also used : SetBlockSelectionEndingPointEvent(org.terasology.engine.world.selection.event.SetBlockSelectionEndingPointEvent) BlockSelectionComponent(org.terasology.engine.world.selection.BlockSelectionComponent) SetBlockSelectionStartingPointEvent(org.terasology.engine.world.selection.event.SetBlockSelectionStartingPointEvent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 BlockSelectionComponent (org.terasology.engine.world.selection.BlockSelectionComponent)1 SetBlockSelectionEndingPointEvent (org.terasology.engine.world.selection.event.SetBlockSelectionEndingPointEvent)1 SetBlockSelectionStartingPointEvent (org.terasology.engine.world.selection.event.SetBlockSelectionStartingPointEvent)1