Search in sources :

Example 81 with Vector3i

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;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk)

Example 82 with Vector3i

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)));
}
Also used : OnActivatedBlocks(org.terasology.world.block.OnActivatedBlocks) TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) Vector3i(org.terasology.math.geom.Vector3i) ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Event(org.terasology.entitySystem.event.Event) Chunk(org.terasology.world.chunks.Chunk) TIntList(gnu.trove.list.TIntList) EntityRef(org.terasology.entitySystem.entity.EntityRef) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 83 with Vector3i

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)));
}
Also used : TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) Vector3i(org.terasology.math.geom.Vector3i) ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Event(org.terasology.entitySystem.event.Event) OnAddedBlocks(org.terasology.world.block.OnAddedBlocks) Chunk(org.terasology.world.chunks.Chunk) TIntList(gnu.trove.list.TIntList) EntityRef(org.terasology.entitySystem.entity.EntityRef) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 84 with Vector3i

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());
}
Also used : WorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary) Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) Test(org.junit.Test)

Example 85 with Vector3i

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());
}
Also used : WorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary) Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) Test(org.junit.Test)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6