Search in sources :

Example 1 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class BlockRegionTypeHandlerTest method testSerializeBlockRegion.

@Test
public void testSerializeBlockRegion() {
    AABBBlockRegion1Test aabb1 = new AABBBlockRegion1Test();
    aabb1.a1 = new BlockRegion(5, 5, 5, 13, 12, 14);
    aabb1.a2 = new AABBi(3, 5, 5, 22, 12, 14);
    JsonElement tree = gson.toJsonTree(aabb1);
    JsonObject obj = tree.getAsJsonObject();
    assertTrue(obj.has("a1"));
    assertBlockRegion(obj.get("a1"), 5, 5, 5, 13, 12, 14);
    assertTrue(obj.has("a2"));
    assertAABBi(obj.get("a2"), 3, 5, 5, 22, 12, 14);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) BlockRegion(org.terasology.engine.world.block.BlockRegion) AABBi(org.terasology.joml.geom.AABBi) Test(org.junit.jupiter.api.Test)

Example 2 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class BlockRegionTypeHandler method deserialize.

@Override
public Optional<BlockRegion> deserialize(PersistedData data) {
    if (!data.isNull() && data.isValueMap()) {
        PersistedDataMap map = data.getAsValueMap();
        PersistedDataArray minDataArr = map.get(MIN_FIELD).getAsArray();
        TIntList minArr = minDataArr.getAsIntegerArray();
        if (map.has(SIZE_FIELD)) {
            PersistedDataArray sizedataArray = map.get(SIZE_FIELD).getAsArray();
            TIntList sizeArr = sizedataArray.getAsIntegerArray();
            return Optional.of(new BlockRegion(minArr.get(0), minArr.get(1), minArr.get(2), minArr.get(0) + sizeArr.get(0) - 1, minArr.get(1) + sizeArr.get(1) - 1, minArr.get(2) + sizeArr.get(2) - 1));
        }
        PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
        TIntList maxArr = maxDataArr.getAsIntegerArray();
        return Optional.of(new BlockRegion(minArr.get(0), minArr.get(1), minArr.get(2), maxArr.get(0), maxArr.get(1), maxArr.get(2)));
    }
    return Optional.empty();
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) PersistedDataMap(org.terasology.persistence.typeHandling.PersistedDataMap) BlockRegion(org.terasology.engine.world.block.BlockRegion) TIntList(gnu.trove.list.TIntList)

Example 3 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method onBlockRegionDeactivated.

@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionDeactivated(BeforeDeactivateComponent event, EntityRef entity) {
    BlockRegion oldRegion = blockRegions.get(entity);
    for (Vector3ic pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    blockRegions.remove(entity);
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onStartSelectionAtEntity.

@ReceiveEvent
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent 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 startPosition = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR);
    blockSelectionComponent.startPosition = startPosition;
    blockSelectionComponent.currentSelection = new BlockRegion(startPosition);
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 5 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class AbstractFullWorldView method setValueAt.

@Override
public void setValueAt(Vector3ic pos, byte value) {
    setValueAt(getChunk(pos), Chunks.toRelative(pos, new Vector3i()), value);
    BlockRegion chunkRegion = new BlockRegion(pos).expand(1, 1, 1);
    for (Vector3ic affectedChunkPos : Chunks.toChunkRegion(chunkRegion, chunkRegion)) {
        Chunk dirtiedChunk = chunkProvider.getChunk(affectedChunkPos);
        if (dirtiedChunk != null) {
            dirtiedChunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk)

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