Search in sources :

Example 1 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    AABBfc aabb = chunk.getAABB();
    Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3f(org.joml.Vector3f) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 2 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkView method getValueAt.

@Override
public byte getValueAt(Vector3ic pos) {
    int index = chunkIndexOf(pos);
    if (index < 0) {
        return UNAVAILABLE;
    }
    Chunk chunk = chunks[index];
    if (chunk != null) {
        return rules.getValue(chunk, Chunks.toRelative(pos, new Vector3i()));
    }
    return UNAVAILABLE;
}
Also used : Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 3 with Chunk

use of org.terasology.engine.world.chunks.Chunk 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)

Example 4 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class ChunkViewCoreImpl method setDirtyAround.

@Override
public void setDirtyAround(BlockRegionc region) {
    BlockRegion tmp = new BlockRegion(region).expand(1, 1, 1);
    for (Vector3ic pos : Chunks.toChunkRegion(tmp, tmp)) {
        int px = pos.x() + offset.x;
        int py = pos.y() + offset.y;
        int pz = pos.z() + offset.z;
        Chunk chunk = chunks[px + chunkRegion.getSizeX() * (pz + chunkRegion.getSizeZ() * py)];
        if (chunk != null) {
            chunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 5 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBlocks.

@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Set<BlockChange> changedBlocks = new HashSet<>();
    Map<Vector3ic, Block> result = new HashMap<>(blocks.size());
    Vector3i chunkPos = new Vector3i();
    Vector3i relativePos = new Vector3i();
    for (Map.Entry<? extends Vector3ic, Block> entry : blocks.entrySet()) {
        Vector3ic worldPos = entry.getKey();
        Chunks.toChunkPos(worldPos, chunkPos);
        Chunk chunk = chunkProvider.getChunk(chunkPos);
        if (chunk != null) {
            Block type = entry.getValue();
            Chunks.toRelative(worldPos, relativePos);
            Block oldBlockType = chunk.setBlock(relativePos, type);
            if (oldBlockType != type) {
                BlockChange oldChange = blockChanges.get(worldPos);
                if (oldChange == null) {
                    blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
                } else {
                    oldChange.setTo(type);
                }
                setDirtyChunksNear(worldPos);
                changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
            }
            result.put(worldPos, oldBlockType);
        } else {
            result.put(worldPos, null);
        }
    }
    for (BlockChange change : changedBlocks) {
        notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
    }
    return result;
}
Also used : BlockChange(org.terasology.engine.world.propagation.BlockChange) Vector3ic(org.joml.Vector3ic) HashMap(java.util.HashMap) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Chunk (org.terasology.engine.world.chunks.Chunk)67 Vector3i (org.joml.Vector3i)36 Vector3ic (org.joml.Vector3ic)33 Test (org.junit.jupiter.api.Test)29 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)25 BlockRegion (org.terasology.engine.world.block.BlockRegion)24 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 Map (java.util.Map)7 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 Comparator (java.util.Comparator)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6 TimeUnit (java.util.concurrent.TimeUnit)6 TimeoutException (java.util.concurrent.TimeoutException)6 Assertions (org.junit.jupiter.api.Assertions)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 BlockManager (org.terasology.engine.world.block.BlockManager)6