Search in sources :

Example 1 with FloraFacet

use of org.terasology.core.world.generator.facets.FloraFacet 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 FloraFacet

use of org.terasology.core.world.generator.facets.FloraFacet in project Terasology by MovingBlocks.

the class FloraFacetLayer method getWorldText.

@Override
public String getWorldText(Region region, int wx, int wy) {
    FloraFacet floraFacet = region.getFacet(FloraFacet.class);
    Region3i worldRegion = floraFacet.getWorldRegion();
    Region3i relativeRegion = floraFacet.getRelativeRegion();
    int rx = wx - worldRegion.minX() + relativeRegion.minX();
    int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
    for (Entry<BaseVector3i, FloraType> entry : floraFacet.getRelativeEntries().entrySet()) {
        BaseVector3i treePos = entry.getKey();
        if (treePos.getX() == rx && treePos.getZ() == rz) {
            FloraType flora = entry.getValue();
            return labelFunc.apply(flora);
        }
    }
    return "-no vegetation-";
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 3 with FloraFacet

use of org.terasology.core.world.generator.facets.FloraFacet in project Terasology by MovingBlocks.

the class DefaultFloraProvider method process.

@Override
public void process(GeneratingRegion region) {
    SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
    BiomeFacet biomeFacet = region.getRegionFacet(BiomeFacet.class);
    FloraFacet facet = new FloraFacet(region.getRegion(), region.getBorderForFacet(FloraFacet.class));
    List<Predicate<Vector3i>> filters = getFilters(region);
    populateFacet(facet, surface, biomeFacet, filters);
    region.setRegionFacet(FloraFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) Predicate(com.google.common.base.Predicate)

Example 4 with FloraFacet

use of org.terasology.core.world.generator.facets.FloraFacet in project Terasology by MovingBlocks.

the class FloraFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    FloraFacet treeFacet = region.getFacet(FloraFacet.class);
    Graphics2D g = img.createGraphics();
    int width = img.getWidth();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
        FloraType treeGen = entry.getValue();
        int wx = entry.getKey().getX();
        int wz = entry.getKey().getZ();
        Color color = colorFunc.apply(treeGen);
        int src = color.rgba();
        int dst = dataBuffer.getElem(wz * width + wx);
        int mix = blender.blend(src, dst);
        dataBuffer.setElem(wz * width + wx, mix);
    }
    g.dispose();
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) ColorBlender(org.terasology.world.viewer.color.ColorBlender) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) BaseVector3i(org.terasology.math.geom.BaseVector3i) DataBufferInt(java.awt.image.DataBufferInt) Graphics2D(java.awt.Graphics2D)

Aggregations

FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)4 BaseVector3i (org.terasology.math.geom.BaseVector3i)3 FloraType (org.terasology.core.world.generator.rasterizers.FloraType)2 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Graphics2D (java.awt.Graphics2D)1 ColorModel (java.awt.image.ColorModel)1 DataBufferInt (java.awt.image.DataBufferInt)1 List (java.util.List)1 Map (java.util.Map)1 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)1 Region3i (org.terasology.math.Region3i)1 CoreRegistry (org.terasology.registry.CoreRegistry)1 Color (org.terasology.rendering.nui.Color)1 WhiteNoise (org.terasology.utilities.procedural.WhiteNoise)1 Block (org.terasology.world.block.Block)1 BlockManager (org.terasology.world.block.BlockManager)1 CoreChunk (org.terasology.world.chunks.CoreChunk)1 Region (org.terasology.world.generation.Region)1