Search in sources :

Example 6 with OnChunkLoaded

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

the class LocalChunkProvider method processReadyChunk.

private void processReadyChunk(final Chunk chunk) {
    Vector3ic chunkPos = chunk.getPosition();
    if (chunkCache.get(chunkPos) != null) {
        // TODO move it in pipeline;
        return;
    }
    chunkCache.put(new Vector3i(chunkPos), chunk);
    chunk.markReady();
    // TODO, it is not clear if the activate/addedBlocks event logic is correct.
    // See https://github.com/MovingBlocks/Terasology/issues/3244
    ChunkStore store = this.storageManager.loadChunkStore(chunkPos);
    TShortObjectMap<TIntList> mappings = createBatchBlockEventMappings(chunk);
    if (store != null) {
        store.restoreEntities();
        PerformanceMonitor.startActivity("Sending OnAddedBlocks");
        mappings.forEachEntry((id, positions) -> {
            if (positions.size() > 0) {
                blockManager.getBlock(id).getEntity().send(new OnAddedBlocks(positions, registry));
            }
            return true;
        });
        PerformanceMonitor.endActivity();
        // send on activate
        PerformanceMonitor.startActivity("Sending OnActivateBlocks");
        mappings.forEachEntry((id, positions) -> {
            if (positions.size() > 0) {
                blockManager.getBlock(id).getEntity().send(new OnActivatedBlocks(positions, registry));
            }
            return true;
        });
        PerformanceMonitor.endActivity();
    } else {
        PerformanceMonitor.startActivity("Generating queued Entities");
        generateQueuedEntities.remove(chunkPos).forEach(this::generateQueuedEntities);
        PerformanceMonitor.endActivity();
        // send on activate
        PerformanceMonitor.startActivity("Sending OnActivateBlocks");
        mappings.forEachEntry((id, positions) -> {
            if (positions.size() > 0) {
                blockManager.getBlock(id).getEntity().send(new OnActivatedBlocks(positions, registry));
            }
            return true;
        });
        PerformanceMonitor.endActivity();
        worldEntity.send(new OnChunkGenerated(chunkPos));
    }
    worldEntity.send(new OnChunkLoaded(chunkPos));
}
Also used : OnChunkLoaded(org.terasology.engine.world.chunks.event.OnChunkLoaded) OnActivatedBlocks(org.terasology.engine.world.block.OnActivatedBlocks) OnChunkGenerated(org.terasology.engine.world.chunks.event.OnChunkGenerated) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) OnAddedBlocks(org.terasology.engine.world.block.OnAddedBlocks) TIntList(gnu.trove.list.TIntList) ChunkStore(org.terasology.engine.persistence.ChunkStore)

Example 7 with OnChunkLoaded

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

the class RemoteChunkProvider method update.

@Override
public void update() {
    if (listener != null) {
        checkForUnload();
    }
    Chunk chunk;
    while ((chunk = readyChunks.poll()) != null) {
        Chunk oldChunk = chunkCache.put(chunk.getPosition(new Vector3i()), chunk);
        if (oldChunk != null) {
            oldChunk.dispose();
        }
        chunk.markReady();
        if (listener != null) {
            listener.onChunkReady(chunk.getPosition(new Vector3i()));
        }
        worldEntity.send(new OnChunkLoaded(chunk.getPosition(new Vector3i())));
    }
}
Also used : OnChunkLoaded(org.terasology.engine.world.chunks.event.OnChunkLoaded) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)7 Vector3i (org.joml.Vector3i)6 Test (org.junit.jupiter.api.Test)4 Event (org.terasology.engine.entitySystem.event.Event)4 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)3 OnActivatedBlocks (org.terasology.engine.world.block.OnActivatedBlocks)3 Chunk (org.terasology.engine.world.chunks.Chunk)3 OnChunkGenerated (org.terasology.engine.world.chunks.event.OnChunkGenerated)3 OnAddedBlocks (org.terasology.engine.world.block.OnAddedBlocks)2 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)2 TIntList (gnu.trove.list.TIntList)1 Vector3ic (org.joml.Vector3ic)1 BaseEntityRef (org.terasology.engine.entitySystem.entity.internal.BaseEntityRef)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 ChunkStore (org.terasology.engine.persistence.ChunkStore)1