Search in sources :

Example 1 with TShortObjectHashMap

use of gnu.trove.map.hash.TShortObjectHashMap 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 TShortObjectHashMap

use of gnu.trove.map.hash.TShortObjectHashMap 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 3 with TShortObjectHashMap

use of gnu.trove.map.hash.TShortObjectHashMap in project Terasology by MovingBlocks.

the class LocalChunkProvider method createBatchBlockEventMappings.

private TShortObjectMap<TIntList> createBatchBlockEventMappings(Chunk chunk) {
    TShortObjectMap<TIntList> batchBlockMap = new TShortObjectHashMap<>();
    blockManager.listRegisteredBlocks().stream().filter(Block::isLifecycleEventsRequired).forEach(block -> batchBlockMap.put(block.getId(), new TIntArrayList()));
    ChunkBlockIterator i = chunk.getBlockIterator();
    while (i.next()) {
        if (i.getBlock().isLifecycleEventsRequired()) {
            TIntList positionList = batchBlockMap.get(i.getBlock().getId());
            positionList.add(i.getBlockPos().x);
            positionList.add(i.getBlockPos().y);
            positionList.add(i.getBlockPos().z);
        }
    }
    return batchBlockMap;
}
Also used : TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) ChunkBlockIterator(org.terasology.world.chunks.ChunkBlockIterator)

Aggregations

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