Search in sources :

Example 1 with CoreChunk

use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.

the class FloraRasterizer method generateChunk.

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    FloraFacet facet = chunkRegion.getFacet(FloraFacet.class);
    WhiteNoise noise = new WhiteNoise(chunk.getPosition().hashCode());
    Map<BaseVector3i, FloraType> entries = facet.getRelativeEntries();
    // check if some other rasterizer has already placed something here
    entries.keySet().stream().filter(pos -> chunk.getBlock(pos).equals(air)).forEach(pos -> {
        FloraType type = entries.get(pos);
        List<Block> list = flora.get(type);
        int blockIdx = Math.abs(noise.intNoise(pos.x(), pos.y(), pos.z())) % list.size();
        Block block = list.get(blockIdx);
        chunk.setBlock(pos, block);
    });
}
Also used : BlockManager(org.terasology.world.block.BlockManager) Region(org.terasology.world.generation.Region) WorldRasterizer(org.terasology.world.generation.WorldRasterizer) Maps(com.google.common.collect.Maps) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) BaseVector3i(org.terasology.math.geom.BaseVector3i) Block(org.terasology.world.block.Block) CoreChunk(org.terasology.world.chunks.CoreChunk) Map(java.util.Map) CoreRegistry(org.terasology.registry.CoreRegistry) WhiteNoise(org.terasology.utilities.procedural.WhiteNoise) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) WhiteNoise(org.terasology.utilities.procedural.WhiteNoise) BaseVector3i(org.terasology.math.geom.BaseVector3i) Block(org.terasology.world.block.Block)

Example 2 with CoreChunk

use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method getLiquid.

@Override
public LiquidData getLiquid(int x, int y, int z) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        return chunk.getLiquid(blockPos);
    }
    return new LiquidData();
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Example 3 with CoreChunk

use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setLiquid.

@Override
public boolean setLiquid(int x, int y, int z, LiquidData newState, LiquidData oldState) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        LiquidData liquidState = chunk.getLiquid(blockPos);
        if (liquidState.equals(oldState)) {
            chunk.setLiquid(blockPos, newState);
            return true;
        }
    }
    return false;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Example 4 with CoreChunk

use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBlock.

@Override
public Block setBlock(Vector3i 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 = ChunkMath.calcChunkPos(worldPos);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
        Block oldBlockType = chunk.setBlock(blockPos, type);
        if (oldBlockType != type) {
            BlockChange oldChange = blockChanges.get(worldPos);
            if (oldChange == null) {
                blockChanges.put(worldPos, new BlockChange(worldPos, oldBlockType, type));
            } else {
                oldChange.setTo(type);
            }
            for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
                RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
                if (dirtiedChunk != null) {
                    dirtiedChunk.setDirty(true);
                }
            }
            notifyBlockChanged(worldPos, type, oldBlockType);
        }
        return oldBlockType;
    }
    return null;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) BlockChange(org.terasology.world.propagation.BlockChange) Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Block(org.terasology.world.block.Block)

Example 5 with CoreChunk

use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBiome.

@Override
public Biome setBiome(Vector3i worldPos, Biome biome) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
        Biome oldBiomeType = chunk.setBiome(blockPos.x, blockPos.y, blockPos.z, biome);
        if (oldBiomeType != biome) {
            BiomeChange oldChange = biomeChanges.get(worldPos);
            if (oldChange == null) {
                biomeChanges.put(worldPos, new BiomeChange(worldPos, oldBiomeType, biome));
            } else {
                oldChange.setTo(biome);
            }
            for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
                RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
                if (dirtiedChunk != null) {
                    dirtiedChunk.setDirty(true);
                }
            }
            notifyBiomeChanged(worldPos, biome, oldBiomeType);
        }
        return oldBiomeType;
    }
    return null;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Biome(org.terasology.world.biomes.Biome) BiomeChange(org.terasology.world.propagation.BiomeChange) Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Aggregations

CoreChunk (org.terasology.world.chunks.CoreChunk)7 Vector3i (org.terasology.math.geom.Vector3i)6 Block (org.terasology.world.block.Block)3 RenderableChunk (org.terasology.world.chunks.RenderableChunk)3 Map (java.util.Map)2 LiquidData (org.terasology.world.liquid.LiquidData)2 BlockChange (org.terasology.world.propagation.BlockChange)2 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)1 BaseVector3i (org.terasology.math.geom.BaseVector3i)1 CoreRegistry (org.terasology.registry.CoreRegistry)1 WhiteNoise (org.terasology.utilities.procedural.WhiteNoise)1 Biome (org.terasology.world.biomes.Biome)1 BlockManager (org.terasology.world.block.BlockManager)1 Region (org.terasology.world.generation.Region)1 WorldRasterizer (org.terasology.world.generation.WorldRasterizer)1