use of ivorius.ivtoolkit.blocks.IvBlockCollection 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.blocks.IvBlockCollection in project RecurrentComplex by Ivorforce.
the class TransformerAbstractCloud method transform.
@Override
public void transform(S instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
if (generatesInPhase(instanceData, phase)) {
IvBlockCollection blockCollection = worldData.blockCollection;
int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
BlockPos.MutableBlockPos worldCoord = new BlockPos.MutableBlockPos();
instanceData.cloud.forEachEntry((sourcePos, density) -> {
IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldCoord, areaSize), lowerCoord);
transformBlock(instanceData, phase, context, sourcePos, worldCoord, worldData.blockCollection.getBlockState(sourcePos), density);
return true;
});
}
}
use of ivorius.ivtoolkit.blocks.IvBlockCollection in project RecurrentComplex by Ivorforce.
the class TransformerSingleBlock method transform.
@Override
public void transform(S instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
if (!generatesInPhase(instanceData, phase))
return;
IvBlockCollection blockCollection = worldData.blockCollection;
StructureBoundingBox relevantSourceArea = context.intersection(BlockAreas.toBoundingBox(blockCollection.area()));
if (relevantSourceArea == null)
return;
BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
BlockPos.MutableBlockPos worldCoord = new BlockPos.MutableBlockPos();
for (BlockPos sourceCoord : RCStructureBoundingBoxes.mutablePositions(relevantSourceArea)) {
IvMutableBlockPos.add(context.transform.applyOn(sourceCoord, worldCoord, areaSize), lowerCoord);
if (!context.includesComplex(worldCoord))
continue;
IBlockState state = blockCollection.getBlockState(sourceCoord);
if (matches(context.environment, instanceData, state))
transformBlock(instanceData, Phase.BEFORE, context, areaSize, worldCoord, state);
}
}
Aggregations