Search in sources :

Example 6 with BlockRegionComponent

use of org.terasology.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method onBlockRegionChanged.

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

Example 7 with BlockRegionComponent

use of org.terasology.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class DoorSystem method openDoor.

@ReceiveEvent
public void openDoor(OpenDoorEvent event, EntityRef player) {
    EntityRef entity = event.getDoorEntity();
    DoorComponent door = entity.getComponent(DoorComponent.class);
    Side newSide = door.openSide;
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    Block bottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.min(), newSide, Side.TOP);
    worldProvider.setBlock(regionComp.region.min(), bottomBlock);
    Block topBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.max(), newSide, Side.TOP);
    worldProvider.setBlock(regionComp.region.max(), topBlock);
    if (door.openSound != null) {
        entity.send(new PlaySoundEvent(door.openSound, 1f));
    }
    door.isOpen = true;
}
Also used : Side(org.terasology.math.Side) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Block(org.terasology.world.block.Block) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 8 with BlockRegionComponent

use of org.terasology.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class BlockDamageRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (blockSelectionRenderer == null) {
        Texture texture = Assets.getTextureRegion("core:blockdamageeffects#1").get().getTexture();
        blockSelectionRenderer = new BlockSelectionRenderer(texture);
    }
    // group the entities into what texture they will use so that there is less recreating meshes (changing a texture region on the BlockSelectionRenderer
    // will recreate the mesh to use the different UV coordinates).  Also this allows
    Multimap<Integer, Vector3i> groupedEntitiesByEffect = ArrayListMultimap.create();
    for (EntityRef entity : entityManager.getEntitiesWith(HealthComponent.class, BlockComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
        groupedEntitiesByEffect.put(getEffectsNumber(health), blockComponent.getPosition());
    }
    for (EntityRef entity : entityManager.getEntitiesWith(BlockRegionComponent.class, HealthComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
        for (Vector3i blockPos : blockRegion.region) {
            groupedEntitiesByEffect.put(getEffectsNumber(health), blockPos);
        }
    }
    // we know that the texture will be the same for each block effect,  just differnt UV coordinates.  Bind the texture already
    blockSelectionRenderer.beginRenderOverlay();
    for (Integer effectsNumber : groupedEntitiesByEffect.keySet()) {
        Optional<TextureRegionAsset> texture = Assets.getTextureRegion("core:blockdamageeffects#" + effectsNumber);
        if (texture.isPresent()) {
            blockSelectionRenderer.setEffectsTexture(texture.get());
            for (Vector3i position : groupedEntitiesByEffect.get(effectsNumber)) {
                blockSelectionRenderer.renderMark(position);
            }
        }
    }
    blockSelectionRenderer.endRenderOverlay();
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) BlockSelectionRenderer(org.terasology.rendering.world.selection.BlockSelectionRenderer) Texture(org.terasology.rendering.assets.texture.Texture) EntityRef(org.terasology.entitySystem.entity.EntityRef) TextureRegionAsset(org.terasology.rendering.assets.texture.TextureRegionAsset)

Aggregations

BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)8 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 Vector3i (org.terasology.math.geom.Vector3i)5 Block (org.terasology.world.block.Block)5 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)3 LocationComponent (org.terasology.logic.location.LocationComponent)3 Side (org.terasology.math.Side)3 BlockComponent (org.terasology.world.block.BlockComponent)3 Vector3f (org.terasology.math.geom.Vector3f)2 HashMap (java.util.HashMap)1 Region3i (org.terasology.math.Region3i)1 Texture (org.terasology.rendering.assets.texture.Texture)1 TextureRegionAsset (org.terasology.rendering.assets.texture.TextureRegionAsset)1 MeshComponent (org.terasology.rendering.logic.MeshComponent)1 BlockSelectionRenderer (org.terasology.rendering.world.selection.BlockSelectionRenderer)1 PlaceBlocks (org.terasology.world.block.entity.placement.PlaceBlocks)1