Search in sources :

Example 41 with Vector3ic

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

the class VoxelWorldSystem method onChunkUnloaded.

/**
 * free chunk region from bullet
 *
 * @param beforeChunkUnload
 * @param worldEntity
 */
@ReceiveEvent(components = WorldComponent.class)
public void onChunkUnloaded(BeforeChunkUnload beforeChunkUnload, EntityRef worldEntity) {
    Vector3ic chunkPos = beforeChunkUnload.getChunkPos();
    colliders.forEach(k -> k.unloadChunk(chunkPos));
}
Also used : Vector3ic(org.joml.Vector3ic) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 42 with Vector3ic

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

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3fc storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 43 with Vector3ic

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

the class InternalLightGeneratorTest method testBlockedAtTopSunlightRegenPropagationResets.

@Test
public void testBlockedAtTopSunlightRegenPropagationResets() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    for (Vector3ic pos : new BlockRegion(0, 63, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        chunk.setBlock(pos, solidBlock);
    }
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y - 1, Chunks.SIZE_Z)) {
        byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 2, 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 44 with Vector3ic

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

the class InternalLightGeneratorTest method testUnblockedSunlightPropagation.

@Test
public void testUnblockedSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 15, Chunks.SIZE_Z)) {
        assertEquals(15 - pos.y(), chunk.getSunlight(pos), () -> "Incorrect lighting at " + 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 45 with Vector3ic

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

the class InternalLightGeneratorTest method testBlockedSunlightPropagation.

@Test
public void testBlockedSunlightPropagation() {
    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);
    }
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 5, Chunks.SIZE_Z)) {
        assertEquals(0, chunk.getSunlight(pos), () -> "Incorrect lighting at " + 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)

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