Search in sources :

Example 21 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, BlockComponent blockComponent) {
    Vector3ic location = blockComponent.getPosition();
    commonDefaultDropsHandling(event, entity, location, blockComponent.getBlock());
}
Also used : Vector3ic(org.joml.Vector3ic) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 22 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
    if (blockComponent.block != null) {
        if (entity.hasComponent(BlockRegionComponent.class)) {
            BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
            if (blockComponent.dropBlocksInRegion) {
                // loop through all the blocks in this region and drop them
                for (Vector3ic location : blockRegion.region) {
                    Block blockInWorld = worldProvider.getBlock(location);
                    commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
                }
            } else {
                // just drop the ActAsBlock block
                Vector3i location = new Vector3i(blockRegion.region.center(new Vector3f()), RoundingMode.HALF_UP);
                commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
            }
        } else if (entity.hasComponent(LocationComponent.class)) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            Vector3i location = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.HALF_UP);
            commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 23 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testLightPropagation.

@Test
public void testLightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    chunk.setBlock(16, 32, 16, fullLight);
    InternalLightProcessor.generateInternalLighting(chunk);
    assertEquals(fullLight.getLuminance(), chunk.getLight(16, 32, 16));
    assertEquals(fullLight.getLuminance() - 1, chunk.getLight(16, 33, 16));
    for (int i = 1; i < fullLight.getLuminance(); ++i) {
        for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(16, 32, 16), i).build()) {
            assertEquals(fullLight.getLuminance() - i, chunk.getLight(pos));
        }
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 24 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testBlockedSunlightRegenPropagationResets.

@Test
public void testBlockedSunlightRegenPropagationResets() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    for (Vector3ic pos : new BlockRegion(0, 60, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        chunk.setBlock(pos, solidBlock);
    }
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 61, 0).setSize(Chunks.SIZE_X, 3, Chunks.SIZE_Z)) {
        byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
        assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
    }
    for (Vector3ic pos : new BlockRegion(0, 60, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        assertEquals(0, chunk.getSunlightRegen(pos));
    }
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 59, Chunks.SIZE_Z)) {
        byte expectedRegen = (byte) Math.min(60 - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
        assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 25 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.

@Test
public void testHorizontalSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    for (Vector3ic pos : new BlockRegion(0, 4, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        chunk.setBlock(pos, solidBlock);
    }
    chunk.setBlock(new Vector3i(16, 4, 16), airBlock);
    InternalLightProcessor.generateInternalLighting(chunk);
    assertEquals(12, chunk.getSunlight(16, 3, 16));
    assertEquals(11, chunk.getSunlight(15, 3, 16));
    assertEquals(11, chunk.getSunlight(17, 3, 16));
    assertEquals(11, chunk.getSunlight(16, 3, 15));
    assertEquals(11, chunk.getSunlight(16, 3, 17));
    assertEquals(12, chunk.getSunlight(15, 2, 16));
    assertEquals(12, chunk.getSunlight(17, 2, 16));
    assertEquals(12, chunk.getSunlight(16, 2, 15));
    assertEquals(12, chunk.getSunlight(16, 2, 17));
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3ic (org.joml.Vector3ic)87 Vector3i (org.joml.Vector3i)52 Test (org.junit.jupiter.api.Test)35 BlockRegion (org.terasology.engine.world.block.BlockRegion)28 Chunk (org.terasology.engine.world.chunks.Chunk)28 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)16 Block (org.terasology.engine.world.block.Block)12 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)11 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Vector3f (org.joml.Vector3f)4