Search in sources :

Example 1 with OnActivatedBlocks

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

the class LocalChunkProviderTest method testCompleteUpdateSendsBlockActivatedEvents.

@Test
public void testCompleteUpdateSendsBlockActivatedEvents() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final TShortObjectHashMap<TIntList> blockPositionMappings = new TShortObjectHashMap<>();
    final short blockId = 42;
    final EntityRef blockEntity = mock(EntityRef.class);
    registerBlockWithIdAndEntity(blockId, blockEntity, blockManager);
    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(1);
    assertThat(event, instanceOf(OnActivatedBlocks.class));
    assertThat(((OnActivatedBlocks) event).getBlockPositions(), hasItem(new Vector3i(1, 2, 3)));
}
Also used : OnActivatedBlocks(org.terasology.world.block.OnActivatedBlocks) 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) 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 OnActivatedBlocks

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

the class LocalChunkProvider method sendOnActivatedBlocks.

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

Aggregations

OnActivatedBlocks (org.terasology.world.block.OnActivatedBlocks)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