use of org.terasology.engine.world.chunks.event.OnChunkLoaded in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testGenerateSingleChunkWithBlockLifeCycle.
@Test
void testGenerateSingleChunkWithBlockLifeCycle() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
blockAtBlockManager.setLifecycleEventsRequired(true);
blockAtBlockManager.setEntity(mock(EntityRef.class));
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
final ArgumentCaptor<Event> worldEventCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(2)).send(worldEventCaptor.capture());
Assertions.assertAll("World Events not valid", () -> {
Event mustBeOnGeneratedEvent = worldEventCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnGeneratedEvent instanceof OnChunkGenerated, "First world event must be OnChunkGenerated");
Assertions.assertEquals(((OnChunkGenerated) mustBeOnGeneratedEvent).getChunkPos(), chunkPosition, "Chunk position at event not expected");
}, () -> {
Event mustBeOnLoadedEvent = worldEventCaptor.getAllValues().get(1);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
});
// TODO, it is not clear if the activate/addedBlocks event logic is correct.
// See https://github.com/MovingBlocks/Terasology/issues/3244
final ArgumentCaptor<Event> blockEventCaptor = ArgumentCaptor.forClass(Event.class);
verify(blockAtBlockManager.getEntity(), atLeast(1)).send(blockEventCaptor.capture());
Event mustBeOnActivatedBlocks = blockEventCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnActivatedBlocks instanceof OnActivatedBlocks, "First block event must be OnActivatedBlocks");
Assertions.assertTrue(((OnActivatedBlocks) mustBeOnActivatedBlocks).blockCount() > 0, "Block count on activate must be non zero");
}
use of org.terasology.engine.world.chunks.event.OnChunkLoaded in project Terasology by MovingBlocks.
the class SectorSimulationSystem method chunkLoad.
/**
* Handles the OnChunkLoaded event for sector entities.
*
* Forwards the event to the appropriate sector-scope entities, if they are watching that chunk, and sends a
* {@link SectorEntityLoad} event if this is the first watched chunk to be loaded for that entity.
*
* @param event the event sent when any chunk is loaded
* @param worldEntity ignored
*/
@ReceiveEvent(components = WorldComponent.class)
public void chunkLoad(OnChunkLoaded event, EntityRef worldEntity) {
for (EntityRef entity : entityManager.getEntitiesWith(SectorSimulationComponent.class)) {
if (SectorUtil.getWatchedChunks(entity).contains(event.getChunkPos())) {
entity.send(new OnChunkLoaded(event.getChunkPos()));
if (SectorUtil.onlyWatchedChunk(entity, event.getChunkPos(), chunkProvider)) {
entity.send(new SectorEntityLoad());
}
sendLoadedSectorUpdateEvent(entity, simulationDelta(entity));
}
}
}
use of org.terasology.engine.world.chunks.event.OnChunkLoaded in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testLoadSingleChunk.
@Test
void testLoadSingleChunk() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
Chunk chunk = new ChunkImpl(chunkPosition, blockManager, extraDataManager);
generator.createChunk(chunk, null);
storageManager.add(chunk);
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
Assertions.assertTrue(((TestChunkStore) storageManager.loadChunkStore(chunkPosition)).isEntityRestored(), "Entities must be restored by loading");
final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(1)).send(eventArgumentCaptor.capture());
Event mustBeOnLoadedEvent = eventArgumentCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
}
use of org.terasology.engine.world.chunks.event.OnChunkLoaded in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testGenerateSingleChunk.
@Test
void testGenerateSingleChunk() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(2)).send(eventArgumentCaptor.capture());
Assertions.assertAll("WorldEvents not valid", () -> {
Event mustBeOnGeneratedEvent = eventArgumentCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnGeneratedEvent instanceof OnChunkGenerated, "First world event must be OnChunkGenerated");
Assertions.assertEquals(((OnChunkGenerated) mustBeOnGeneratedEvent).getChunkPos(), chunkPosition, "Chunk position at event not expected");
}, () -> {
Event mustBeOnLoadedEvent = eventArgumentCaptor.getAllValues().get(1);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
});
}
use of org.terasology.engine.world.chunks.event.OnChunkLoaded in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testLoadSingleChunkWithBlockLifecycle.
@Test
void testLoadSingleChunkWithBlockLifecycle() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
Chunk chunk = new ChunkImpl(chunkPosition, blockManager, extraDataManager);
generator.createChunk(chunk, null);
storageManager.add(chunk);
blockAtBlockManager.setLifecycleEventsRequired(true);
blockAtBlockManager.setEntity(mock(EntityRef.class));
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
Assertions.assertTrue(((TestChunkStore) storageManager.loadChunkStore(chunkPosition)).isEntityRestored(), "Entities must be restored by loading");
final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(1)).send(eventArgumentCaptor.capture());
Event mustBeOnLoadedEvent = eventArgumentCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
// TODO, it is not clear if the activate/addedBlocks event logic is correct.
// See https://github.com/MovingBlocks/Terasology/issues/3244
final ArgumentCaptor<Event> blockEventCaptor = ArgumentCaptor.forClass(Event.class);
verify(blockAtBlockManager.getEntity(), atLeast(2)).send(blockEventCaptor.capture());
Assertions.assertAll("Block events not valid", () -> {
Event mustBeOnAddedBlocks = blockEventCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnAddedBlocks instanceof OnAddedBlocks, "First block event must be OnAddedBlocks");
Assertions.assertTrue(((OnAddedBlocks) mustBeOnAddedBlocks).blockCount() > 0, "Block count on activate must be non zero");
}, () -> {
Event mustBeOnActivatedBlocks = blockEventCaptor.getAllValues().get(1);
Assertions.assertTrue(mustBeOnActivatedBlocks instanceof OnActivatedBlocks, "First block event must be OnActivatedBlocks");
Assertions.assertTrue(((OnActivatedBlocks) mustBeOnActivatedBlocks).blockCount() > 0, "Block count on activate must be non zero");
});
}
Aggregations