use of ivorius.ivtoolkit.util.LineSelection in project RecurrentComplex by Ivorforce.
the class FactorMatch method consider.
@Override
public List<Pair<LineSelection, Float>> consider(WorldCache cache, LineSelection considerable, @Nullable IvBlockCollection blockCollection, StructurePlaceContext context) {
if (blockCollection == null)
throw new IllegalArgumentException("Missing a block collection!");
List<Pair<LineSelection, Float>> consideration = new ArrayList<>();
int[] size = StructureBoundingBoxes.size(context.boundingBox);
BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
Set<BlockPos.MutableBlockPos> sources = BlockAreas.streamMutablePositions(blockCollection.area()).filter(p -> sourceMatcher.evaluate(() -> blockCollection.getBlockState(p))).map(p -> new BlockPos.MutableBlockPos(context.transform.apply(p, size).add(lowerCoord.getX(), 0, lowerCoord.getZ()))).collect(Collectors.toSet());
for (IntegerRange range : (Iterable<IntegerRange>) considerable.streamSections(null, true)::iterator) {
Float curConformity = null;
int lastY = range.getMax();
int end = range.getMin();
for (int y = lastY; y >= end; y--) {
int finalY = y;
sources.forEach(p -> p.move(EnumFacing.UP, finalY));
float conformity = weight(cache, sources, requiredConformity);
sources.forEach(p -> p.move(EnumFacing.DOWN, finalY));
if (curConformity == null) {
curConformity = conformity;
lastY = y;
} else if (!DoubleMath.fuzzyEquals(conformity, curConformity, 0.01)) {
consideration.add(Pair.of(LineSelection.fromRange(IntegerRanges.from(lastY, y + 1), true), weight(curConformity)));
curConformity = conformity;
lastY = y;
}
}
if (curConformity != null)
consideration.add(Pair.of(LineSelection.fromRange(IntegerRanges.from(lastY, end), true), weight(curConformity)));
}
return consideration;
}
use of ivorius.ivtoolkit.util.LineSelection in project RecurrentComplex by Ivorforce.
the class GenericPlacer method place.
@Override
public int place(StructurePlaceContext context, @Nullable IvBlockCollection blockCollection) {
if (factors.isEmpty())
return DONT_GENERATE;
WorldServer world = context.environment.world;
WorldCache cache = new WorldCache(world, StructureBoundingBoxes.wholeHeightBoundingBox(world, context.boundingBox));
LineSelection considerable = LineSelection.fromRange(new IntegerRange(0, world.getHeight() - context.boundingBox.getYSize()), true);
List<Pair<LineSelection, Float>> considerations = new ArrayList<>();
factors.forEach(factor -> {
List<Pair<LineSelection, Float>> consideration = factor.consider(cache, considerable, blockCollection, context);
consideration.stream().filter(p -> p.getRight() <= 0).forEach(p -> considerable.set(p.getLeft(), true, false));
consideration = consideration.stream().filter(p -> p.getRight() > 0).collect(Collectors.toList());
considerable.set(LineSelections.combine(consideration.stream().map(Pair::getLeft), true), false, false);
considerations.addAll(consideration);
});
Set<Pair<Integer, Double>> applicable = considerable.streamElements(null, true).mapToObj(y -> Pair.of(y, considerations.stream().mapToDouble(pair -> pair.getLeft().isSectionAdditive(pair.getLeft().sectionForIndex(y)) ? pair.getRight() : 1).reduce(1f, (left, right) -> left * right))).filter(p -> p.getRight() > 0).collect(Collectors.toSet());
return applicable.size() > 0 ? WeightedSelector.select(context.random, applicable, Pair::getRight).getLeft() : DONT_GENERATE;
}
use of ivorius.ivtoolkit.util.LineSelection in project RecurrentComplex by Ivorforce.
the class FactorLimit method consider.
@Override
public List<Pair<LineSelection, Float>> consider(WorldCache cache, LineSelection considerable, @Nullable IvBlockCollection blockCollection, StructurePlaceContext context) {
List<Pair<LineSelection, Float>> consideration = new ArrayList<>();
int height = cache.world.getHeight();
int pos = height - 1;
for (Ray ray : rays) {
int before = pos;
OptionalInt cast = ray.cast(cache, context, pos);
if (cast.isPresent()) {
pos = cast.getAsInt();
LineSelection selection = LineSelection.fromRange(IntegerRanges.from(pos, before), true);
selection.set(considerable, false, false);
if (ray.weight != null && !selection.isUniform())
consideration.add(Pair.of(selection, weight(ray.weight)));
} else
break;
}
return consideration;
}
Aggregations