use of org.terasology.core.world.generator.facets.TreeFacet in project Terasology by MovingBlocks.
the class DefaultTreeProvider method process.
@Override
public void process(GeneratingRegion region) {
SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
BiomeFacet biome = region.getRegionFacet(BiomeFacet.class);
List<Predicate<Vector3i>> filters = getFilters(region);
// these value are derived from the maximum tree extents as
// computed by the TreeTests class. Birch is the highest with 32
// and Pine has 13 radius.
// These values must be identical in the class annotations.
int maxRad = 13;
int maxHeight = 32;
Border3D borderForTreeFacet = region.getBorderForFacet(TreeFacet.class);
TreeFacet facet = new TreeFacet(region.getRegion(), borderForTreeFacet.extendBy(0, maxHeight, maxRad));
populateFacet(facet, surface, biome, filters);
region.setRegionFacet(TreeFacet.class, facet);
}
use of org.terasology.core.world.generator.facets.TreeFacet in project Terasology by MovingBlocks.
the class TreeFacetLayer method render.
@Override
public void render(BufferedImage img, Region region) {
TreeFacet treeFacet = region.getFacet(TreeFacet.class);
Graphics2D g = img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
TreeGenerator treeGen = entry.getValue();
int wx = entry.getKey().getX();
int wz = entry.getKey().getZ();
int r = radiusFunc.apply(treeGen);
Color color = colorFunc.apply(treeGen);
// the fill area is offset by +1/+1 pixel
// otherwise it will bleed out at the top left corner
g.setColor(color);
g.fillOval(wx - r + 1, wz - r + 1, r * 2 - 1, r * 2 - 1);
g.setColor(color.darker());
g.drawOval(wx - r, wz - r, r * 2, r * 2);
}
g.dispose();
}
use of org.terasology.core.world.generator.facets.TreeFacet in project Terasology by MovingBlocks.
the class TreeFacetLayer method getWorldText.
@Override
public String getWorldText(Region region, int wx, int wy) {
TreeFacet treeFacet = region.getFacet(TreeFacet.class);
Region3i worldRegion = treeFacet.getWorldRegion();
Region3i relativeRegion = treeFacet.getRelativeRegion();
int rx = wx - worldRegion.minX() + relativeRegion.minX();
int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
Vector2f relCursor = new Vector2f(rx, rz);
CirclePicker<TreeGenerator> picker = new CirclePickerAll<>(relCursor, radiusFunc);
for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
TreeGenerator treeGen = entry.getValue();
BaseVector3i treePos = entry.getKey();
picker.offer(treePos.getX(), treePos.getZ(), treeGen);
}
Set<TreeGenerator> picked = picker.getAll();
// try to exit early first
if (picked.isEmpty()) {
return null;
}
if (picked.size() == 1) {
TreeGenerator first = picked.iterator().next();
return labelFunc.apply(first);
}
// convert to a stream of labels
Stream<String> labels = picked.stream().map(labelFunc);
// collect identical String elements and collect the count in a map
Map<String, Long> counters = labels.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
// define a mapping from a map entry to a String representation
// TODO: treat 1x occurrences like above (e.g. Tree instead of 1x Tree)
Function<Entry<String, Long>, String> toStringFunc = e -> String.format("%dx %s", e.getValue(), e.getKey());
// apply that mapping and join the Strings with a comma
return counters.entrySet().stream().map(toStringFunc).collect(Collectors.joining(", "));
}
use of org.terasology.core.world.generator.facets.TreeFacet in project Terasology by MovingBlocks.
the class TreeRasterizer method generateChunk.
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
TreeFacet facet = chunkRegion.getFacet(TreeFacet.class);
for (Map.Entry<BaseVector3i, TreeGenerator> entry : facet.getRelativeEntries().entrySet()) {
BaseVector3i pos = entry.getKey();
TreeGenerator treeGen = entry.getValue();
int seed = relativeToWorld(facet, pos).hashCode();
Random random = new FastRandom(seed);
treeGen.generate(blockManager, chunk, random, pos.x(), pos.y(), pos.z());
}
}
Aggregations