use of org.terasology.engine.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) {
Vector3ic location = blockComponent.getPosition();
commonDefaultDropsHandling(event, entity, location, blockComponent.getBlock());
}
use of org.terasology.engine.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, ActAsBlockComponent blockComponent) {
if (blockComponent.block != null) {
if (entity.hasComponent(BlockRegionComponent.class)) {
BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
if (blockComponent.dropBlocksInRegion) {
// loop through all the blocks in this region and drop them
for (Vector3ic location : blockRegion.region) {
Block blockInWorld = worldProvider.getBlock(location);
commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
}
} else {
// just drop the ActAsBlock block
Vector3i location = new Vector3i(blockRegion.region.center(new Vector3f()), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
} else if (entity.hasComponent(LocationComponent.class)) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
Vector3i location = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockItemSystem method onPlaceBlock.
@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
if (!event.getTarget().exists()) {
event.consume();
return;
}
BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
BlockFamily blockFamily = blockItem.blockFamily;
Side surfaceSide = Side.inDirection(event.getHitNormal());
BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
if (blockComponent == null) {
// If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
event.consume();
return;
}
Vector3i targetBlock = new Vector3i(blockComponent.getPosition());
Vector3i placementPos = new Vector3i(targetBlock);
placementPos.add(surfaceSide.direction());
Vector2f relativeAttachmentPosition = getRelativeAttachmentPosition(event);
Block block = blockFamily.getBlockForPlacement(new BlockPlacementData(placementPos, surfaceSide, event.getDirection(), relativeAttachmentPosition));
if (canPlaceBlock(block, targetBlock, placementPos)) {
// TODO: Fix this for changes.
if (networkSystem.getMode().isAuthority()) {
PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
worldProvider.getWorldEntity().send(placeBlocks);
if (!placeBlocks.isConsumed()) {
item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos), event.getInstigator()));
} else {
event.consume();
}
}
recordBlockPlaced(event, blockFamily);
event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
} else {
event.consume();
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class AudioSystem method onPlaySound.
/**
* Receives an event send when a sound should be played for the entity owner as well. Calls on the AudioManager to
* play it.
*
* @param playSoundEvent The sound event.
* @param entity The entity that instigated the event.
*/
@ReceiveEvent
public void onPlaySound(PlaySoundForOwnerEvent playSoundEvent, EntityRef entity) {
ClientComponent clientComponent = networkSystem.getOwnerEntity(entity).getComponent(ClientComponent.class);
if (clientComponent != null && !clientComponent.local) {
return;
}
audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume(), AudioManager.PRIORITY_HIGH);
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class SectorSimulationSystem method chunkLoad.
/**
* Handles the OnChunkLoaded event for sector entities.
*
* Forwards the event to the appropriate sector-scope entities, if they are watching that chunk, and sends a
* {@link SectorEntityLoad} event if this is the first watched chunk to be loaded for that entity.
*
* @param event the event sent when any chunk is loaded
* @param worldEntity ignored
*/
@ReceiveEvent(components = WorldComponent.class)
public void chunkLoad(OnChunkLoaded event, EntityRef worldEntity) {
for (EntityRef entity : entityManager.getEntitiesWith(SectorSimulationComponent.class)) {
if (SectorUtil.getWatchedChunks(entity).contains(event.getChunkPos())) {
entity.send(new OnChunkLoaded(event.getChunkPos()));
if (SectorUtil.onlyWatchedChunk(entity, event.getChunkPos(), chunkProvider)) {
entity.send(new SectorEntityLoad());
}
sendLoadedSectorUpdateEvent(entity, simulationDelta(entity));
}
}
}
Aggregations