Search in sources :

Example 51 with Block

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

the class SunlightRegenBatchPropagator method propagateSweep.

private void propagateSweep(LitChunk fromChunk, LitChunk toChunk, int[] depth, int[] startingRegen) {
    Vector3i pos = new Vector3i();
    for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
        for (int x = 0; x < ChunkConstants.SIZE_X; ++x) {
            int depthIndex = x + ChunkConstants.SIZE_X * z;
            startingRegen[depthIndex] = regenRules.getValue(fromChunk, new Vector3i(x, 0, z));
            byte expectedValue = (byte) Math.min(startingRegen[depthIndex] + 1, ChunkConstants.MAX_SUNLIGHT_REGEN);
            Block fromBlock = fromChunk.getBlock(x, 0, z);
            Block toBlock = toChunk.getBlock(x, ChunkConstants.SIZE_Y - 1, z);
            if (!(regenRules.canSpreadOutOf(fromBlock, Side.BOTTOM) && regenRules.canSpreadInto(toBlock, Side.TOP))) {
                continue;
            }
            byte predictedValue = 0;
            pos.set(x, ChunkConstants.SIZE_Y - 1, z);
            int currentValue = regenRules.getValue(toChunk, pos);
            while (currentValue == predictedValue && expectedValue > currentValue) {
                regenRules.setValue(toChunk, pos, expectedValue);
                depth[depthIndex]++;
                byte sunlight = (byte) (expectedValue - ChunkConstants.SUNLIGHT_REGEN_THRESHOLD);
                if (sunlight > 0 && sunlight > toChunk.getSunlight(pos)) {
                    toChunk.setSunlight(pos, sunlight);
                }
                if (expectedValue < ChunkConstants.MAX_SUNLIGHT_REGEN) {
                    expectedValue++;
                }
                predictedValue++;
                pos.y--;
                currentValue = regenRules.getValue(toChunk, pos);
            }
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 52 with Block

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

the class InternalLightProcessor method populateSunlight.

private static void populateSunlight(LitChunk chunk) {
    PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
    BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk));
    for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
        for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
            for (int y = 0; y < ChunkConstants.MAX_SUNLIGHT; ++y) {
                Vector3i pos = new Vector3i(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.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.world.propagation.BatchPropagator) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) PropagationRules(org.terasology.world.propagation.PropagationRules) SingleChunkView(org.terasology.world.propagation.SingleChunkView)

Example 53 with Block

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

the class InternalLightProcessor method populateLight.

private static void populateLight(LitChunk chunk) {
    BatchPropagator lightPropagator = new StandardBatchPropagator(LIGHT_RULES, new SingleChunkView(LIGHT_RULES, chunk));
    for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
        for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
            for (int y = 0; y < ChunkConstants.SIZE_Y; y++) {
                Block block = chunk.getBlock(x, y, z);
                if (block.getLuminance() > 0) {
                    chunk.setLight(x, y, z, block.getLuminance());
                    lightPropagator.propagateFrom(new Vector3i(x, y, z), block.getLuminance());
                }
            }
        }
    }
    lightPropagator.process();
}
Also used : StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.world.propagation.BatchPropagator) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) SingleChunkView(org.terasology.world.propagation.SingleChunkView)

Example 54 with Block

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

the class Zone method generateChunk.

/**
 * Generate the chunk for this zone, based on the rasterizers and nested zones that have been added.
 *
 * This will only change blocks for which {@link #containsBlock(int, int, int, Region)} returns true.
 *
 * @see WorldRasterizer#generateChunk(CoreChunk, Region)
 */
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    Block[][][] savedBlocks = new Block[SIZE_X][SIZE_Y][SIZE_Z];
    boolean changeAllBlocks = true;
    boolean saveAllBlocks = true;
    int offsetX = chunk.getChunkWorldOffsetX();
    int offsetY = chunk.getChunkWorldOffsetY();
    int offsetZ = chunk.getChunkWorldOffsetZ();
    // Save the blocks that aren't in the zone
    for (int x = 0; x < SIZE_X; x++) {
        for (int y = 0; y < SIZE_Y; y++) {
            for (int z = 0; z < SIZE_Z; z++) {
                if (!containsBlock(x + offsetX, y + offsetY, z + offsetZ, chunkRegion)) {
                    savedBlocks[x][y][z] = chunk.getBlock(x, y, z);
                    changeAllBlocks = false;
                } else {
                    saveAllBlocks = false;
                }
            }
        }
    }
    // If none of the blocks are in the zone, it doesn't need to be rasterized
    if (!saveAllBlocks) {
        // Rasterize the zone
        rasterizers.forEach(r -> r.generateChunk(chunk, chunkRegion));
        // Replace any blocks that aren't in the zone
        if (!changeAllBlocks) {
            for (int x = 0; x < SIZE_X; x++) {
                for (int y = 0; y < SIZE_Y; y++) {
                    for (int z = 0; z < SIZE_Z; z++) {
                        Block block = savedBlocks[x][y][z];
                        if (block != null) {
                            chunk.setBlock(x, y, z, block);
                        }
                    }
                }
            }
        }
    }
}
Also used : Block(org.terasology.world.block.Block)

Example 55 with Block

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

the class NetClient method sendRegisteredBlocks.

private void sendRegisteredBlocks(NetData.NetMessage.Builder message) {
    synchronized (newlyRegisteredFamilies) {
        for (BlockFamily family : newlyRegisteredFamilies) {
            NetData.BlockFamilyRegisteredMessage.Builder blockRegMessage = NetData.BlockFamilyRegisteredMessage.newBuilder();
            for (Block block : family.getBlocks()) {
                blockRegMessage.addBlockUri(block.getURI().toString());
                blockRegMessage.addBlockId(block.getId());
            }
            message.addBlockFamilyRegistered(blockRegMessage);
        }
        newlyRegisteredFamilies.clear();
    }
}
Also used : Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily)

Aggregations

Block (org.terasology.world.block.Block)67 Vector3i (org.terasology.math.geom.Vector3i)32 EntityRef (org.terasology.entitySystem.entity.EntityRef)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Side (org.terasology.math.Side)11 Vector3f (org.terasology.math.geom.Vector3f)9 LocationComponent (org.terasology.logic.location.LocationComponent)7 BlockUri (org.terasology.world.block.BlockUri)7 BlockFamily (org.terasology.world.block.family.BlockFamily)7 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)6 OnChangedBlock (org.terasology.world.OnChangedBlock)6 BlockComponent (org.terasology.world.block.BlockComponent)5 BlockManager (org.terasology.world.block.BlockManager)5 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Before (org.junit.Before)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)3