use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method mockChunkAt.
private static Chunk mockChunkAt(final int x, final int y, final int z) {
final Chunk chunk = mock(Chunk.class);
when(chunk.getPosition()).thenReturn(new Vector3i(x, y, z));
return chunk;
}
use of org.terasology.math.geom.Vector3i 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.math.geom.Vector3i 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 org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldBuilderTest method testBorderCalculation.
@Test
public void testBorderCalculation() {
WorldBuilder worldBuilder = new WorldBuilder(context.get(WorldGeneratorPluginLibrary.class));
worldBuilder.setSeed(12);
worldBuilder.addProvider(new Facet1Provider());
worldBuilder.addProvider(new Facet2Provider());
World world = worldBuilder.build();
Region3i regionToGenerate = Region3i.createFromCenterExtents(new Vector3i(), 1);
Region regionData = world.getWorldData(regionToGenerate);
Facet1 facet1 = regionData.getFacet(Facet1.class);
assertEquals(regionToGenerate, facet1.getWorldRegion());
Facet2 facet2 = regionData.getFacet(Facet2.class);
assertEquals(Region3i.createFromMinAndSize(new Vector3i(-3, -1, -3), new Vector3i(7, 3, 7)), facet2.getWorldRegion());
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldBuilderTest method testMultiplePathsBorderCalculation.
@Test
public void testMultiplePathsBorderCalculation() {
WorldBuilder worldBuilder = new WorldBuilder(context.get(WorldGeneratorPluginLibrary.class));
worldBuilder.setSeed(12);
worldBuilder.addProvider(new Facet1Provider());
worldBuilder.addProvider(new Facet2Provider());
worldBuilder.addProvider(new Facet4Provider());
World world = worldBuilder.build();
Region3i regionToGenerate = Region3i.createFromCenterExtents(new Vector3i(), 1);
Region regionData = world.getWorldData(regionToGenerate);
Facet1 facet1 = regionData.getFacet(Facet1.class);
assertEquals(regionToGenerate, facet1.getWorldRegion());
Facet4 facet4 = regionData.getFacet(Facet4.class);
assertEquals(regionToGenerate, facet4.getWorldRegion());
Facet2 facet2 = regionData.getFacet(Facet2.class);
assertEquals(Region3i.createFromMinAndSize(new Vector3i(-4, -1, -4), new Vector3i(9, 3, 9)), facet2.getWorldRegion());
}
Aggregations