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)));
}
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)));
}
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;
}
Aggregations