Search in sources :

Example 1 with SetBlockSelectionEndingPointEvent

use of org.terasology.world.selection.event.SetBlockSelectionEndingPointEvent 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.world.selection.event.SetBlockSelectionEndingPointEvent) BlockSelectionComponent(org.terasology.world.selection.BlockSelectionComponent) SetBlockSelectionStartingPointEvent(org.terasology.world.selection.event.SetBlockSelectionStartingPointEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with SetBlockSelectionEndingPointEvent

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

the class LocalPlayerBlockSelectionByItemSystem method onCamTargetChanged.

@ReceiveEvent(components = { LocationComponent.class })
public void onCamTargetChanged(CameraTargetChangedEvent event, EntityRef entity) {
    // This method will update the block selection to whatever block is targeted in the players view
    if (null == blockSelectionComponentEntity) {
        return;
    }
    BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
    if (blockSelectionComponent.startPosition == null) {
        return;
    }
    EntityRef target = event.getNewTarget();
    target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
Also used : SetBlockSelectionEndingPointEvent(org.terasology.world.selection.event.SetBlockSelectionEndingPointEvent) BlockSelectionComponent(org.terasology.world.selection.BlockSelectionComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

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