Search in sources :

Example 1 with OnAddedBlocks

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

the class LocalChunkProviderTest method testCompleteUpdateSendsBlockAddedEvents.

@Test
public void testCompleteUpdateSendsBlockAddedEvents() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final short blockId = 42;
    final EntityRef blockEntity = mock(EntityRef.class);
    registerBlockWithIdAndEntity(blockId, blockEntity, blockManager);
    final TShortObjectHashMap<TIntList> blockPositionMappings = new TShortObjectHashMap<>();
    blockPositionMappings.put(blockId, withPositions(new Vector3i(1, 2, 3)));
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForRestoredChunk(chunk, blockPositionMappings, mock(ChunkStore.class), Collections.emptyList());
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    chunkProvider.completeUpdate();
    final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
    verify(blockEntity, atLeastOnce()).send(eventArgumentCaptor.capture());
    final Event event = eventArgumentCaptor.getAllValues().get(0);
    assertThat(event, instanceOf(OnAddedBlocks.class));
    assertThat(((OnAddedBlocks) event).getBlockPositions(), hasItem(new Vector3i(1, 2, 3)));
}
Also used : TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) Vector3i(org.terasology.math.geom.Vector3i) ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Event(org.terasology.entitySystem.event.Event) OnAddedBlocks(org.terasology.world.block.OnAddedBlocks) Chunk(org.terasology.world.chunks.Chunk) TIntList(gnu.trove.list.TIntList) EntityRef(org.terasology.entitySystem.entity.EntityRef) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 2 with OnAddedBlocks

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

the class LocalChunkProvider method sendOnAddedBlocks.

private void sendOnAddedBlocks(final ReadyChunkInfo readyChunkInfo) {
    PerformanceMonitor.startActivity("Sending OnAddedBlocks");
    readyChunkInfo.getBlockPositionMapppings().forEachEntry((id, positions) -> {
        if (positions.size() > 0) {
            blockManager.getBlock(id).getEntity().send(new OnAddedBlocks(positions, registry));
        }
        return true;
    });
    PerformanceMonitor.endActivity();
}
Also used : OnAddedBlocks(org.terasology.world.block.OnAddedBlocks)

Aggregations

OnAddedBlocks (org.terasology.world.block.OnAddedBlocks)2 TIntList (gnu.trove.list.TIntList)1 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)1 Test (org.junit.Test)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 Event (org.terasology.entitySystem.event.Event)1 Vector3i (org.terasology.math.geom.Vector3i)1 ChunkStore (org.terasology.persistence.ChunkStore)1 Chunk (org.terasology.world.chunks.Chunk)1 ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)1