Search in sources :

Example 51 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion 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 52 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion 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

BlockRegion (org.terasology.engine.world.block.BlockRegion)52 Vector3i (org.joml.Vector3i)29 Vector3ic (org.joml.Vector3ic)26 Test (org.junit.jupiter.api.Test)26 Chunk (org.terasology.engine.world.chunks.Chunk)23 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)11 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)7 ChunkViewCore (org.terasology.engine.world.internal.ChunkViewCore)5 Vector3f (org.joml.Vector3f)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)4 Border3D (org.terasology.engine.world.generation.Border3D)4 WorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary)4 ElevationFacet (org.terasology.engine.world.generation.facets.ElevationFacet)3 Vector2ic (org.joml.Vector2ic)2 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)2 PreLodChunk (org.terasology.engine.world.chunks.internal.PreLodChunk)2 Region (org.terasology.engine.world.generation.Region)2 World (org.terasology.engine.world.generation.World)2 JsonElement (com.google.gson.JsonElement)1