Search in sources :

Example 51 with Block

use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.

the class StandardBatchPropagator method purge.

/**
 * Reset a position to only it's fixed values
 *
 * @param pos The position to reset
 * @param oldValue The value present before reset
 */
private void purge(Vector3ic pos, byte oldValue) {
    increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
    /* Clear the value and re-propagate it if it's a positive value */
    Block block = world.getBlockAt(pos);
    byte fixedValue = rules.getFixedValue(block, pos);
    if (fixedValue > 0) {
        increase(pos, fixedValue);
    } else {
        world.setValueAt(pos, NO_VALUE);
    }
    Vector3i adjPos = new Vector3i();
    for (Side side : Side.values()) {
        /* Handle this value being reset to the default by updating sides as needed */
        byte expectedValue = rules.propagateValue(oldValue, side, block, scale);
        if (rules.canSpreadOutOf(block, side)) {
            side.getAdjacentPos(pos, adjPos);
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == expectedValue) {
                Block adjBlock = world.getBlockAt(adjPos);
                if (rules.canSpreadInto(adjBlock, side.reverse())) {
                    reduce(adjPos, expectedValue);
                }
            } else if (adjValue > 0) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 52 with Block

use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBlock.

@Override
public Block setBlock(Vector3ic worldPos, Block type) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Vector3i chunkPos = Chunks.toChunkPos(worldPos, new Vector3i());
    Chunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = Chunks.toRelative(worldPos, new Vector3i());
        Block oldBlockType = chunk.setBlock(blockPos, type);
        if (oldBlockType != type) {
            BlockChange oldChange = blockChanges.get(worldPos);
            if (oldChange == null) {
                blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
            } else {
                oldChange.setTo(type);
            }
            setDirtyChunksNear(worldPos);
            notifyBlockChanged(worldPos, type, oldBlockType);
        }
        return oldBlockType;
    }
    return null;
}
Also used : BlockChange(org.terasology.engine.world.propagation.BlockChange) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 53 with Block

use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.

the class InternalLightProcessor method populateSunlight.

/**
 * Propagate the initial sunlight values out
 *
 * @param chunk The chunk to set in
 */
private static void populateSunlight(Chunk chunk, int scale) {
    PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
    BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk), scale);
    Vector3i pos = new Vector3i();
    for (int x = 0; x < Chunks.SIZE_X; x++) {
        for (int z = 0; z < Chunks.SIZE_Z; z++) {
            /* Start at the bottom of the chunk and then move up until the max sunlight level */
            for (int y = 0; y < Chunks.SIZE_Y; y++) {
                pos.set(x, y, z);
                Block block = chunk.getBlock(x, y, z);
                byte light = sunlightRules.getFixedValue(block, pos);
                if (light > 0) {
                    chunk.setSunlight(x, y, z, light);
                    lightPropagator.propagateFrom(pos, light);
                }
            }
        }
    }
    lightPropagator.process();
}
Also used : StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) SingleChunkView(org.terasology.engine.world.propagation.SingleChunkView)

Example 54 with Block

use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.

the class InternalLightProcessor method populateLight.

/**
 * Propagate out light from the initial luminous blocks
 *
 * @param chunk The chunk to populate through
 */
private static void populateLight(Chunk chunk, int scale) {
    BatchPropagator lightPropagator = new StandardBatchPropagator(LIGHT_RULES, new SingleChunkView(LIGHT_RULES, chunk), scale);
    Vector3i pos = new Vector3i();
    for (int x = 0; x < Chunks.SIZE_X; x++) {
        for (int z = 0; z < Chunks.SIZE_Z; z++) {
            for (int y = 0; y < Chunks.SIZE_Y; y++) {
                Block block = chunk.getBlock(x, y, z);
                if (block.getLuminance() > 0) {
                    chunk.setLight(x, y, z, block.getLuminance());
                    lightPropagator.propagateFrom(pos.set(x, y, z), block.getLuminance());
                }
            }
        }
    }
    lightPropagator.process();
}
Also used : StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) SingleChunkView(org.terasology.engine.world.propagation.SingleChunkView)

Aggregations

Block (org.terasology.engine.world.block.Block)54 Vector3i (org.joml.Vector3i)23 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)13 Vector3ic (org.joml.Vector3ic)12 Vector3f (org.joml.Vector3f)9 OnChangedBlock (org.terasology.engine.world.OnChangedBlock)9 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)7 Side (org.terasology.engine.math.Side)7 Map (java.util.Map)6 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)5 BlockComponent (org.terasology.engine.world.block.BlockComponent)5 Chunk (org.terasology.engine.world.chunks.Chunk)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)4 Maps (com.google.common.collect.Maps)3 Optional (java.util.Optional)3 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)3 BlockEntityRegistry (org.terasology.engine.world.BlockEntityRegistry)3