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