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);
});
}
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-";
}
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);
}
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();
}
Aggregations