Search in sources :

Example 81 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class NeighbourBlockFamilyUpdateSystem method onBlockPlaced.

/**
 * Notifies the adjacent block families when a block is placed next to them.
 * @param event
 * @param entity
 */
@ReceiveEvent
public void onBlockPlaced(OnBlockItemPlaced event, EntityRef entity) {
    BlockComponent blockComponent = event.getPlacedBlock().getComponent(BlockComponent.class);
    if (blockComponent == null) {
        return;
    }
    processUpdateForBlockLocation(blockComponent.getPosition());
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 82 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method onBlockRegionChanged.

@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionChanged(OnChangedComponent event, EntityRef entity) {
    BlockRegion oldRegion = blockRegions.get(entity);
    for (Vector3ic pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3ic pos : regionComp.region) {
        blockRegionLookup.put(new Vector3i(pos), entity);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 83 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onEndSelectionAtEntity.

@ReceiveEvent
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity, LocationComponent locationComponent) {
    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;
    }
    Vector3i endPosition = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR);
    Vector3i startPosition = blockSelectionComponent.startPosition;
    if (null == startPosition) {
        startPosition = endPosition;
    }
    blockSelectionComponent.currentSelection = new BlockRegion(startPosition).union(endPosition);
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2