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