use of ivorius.ivtoolkit.gui.IntegerRange 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.gui.IntegerRange in project RecurrentComplex by Ivorforce.
the class ItemInventoryGenMultiTag method generateInInventory.
@Override
public void generateInInventory(WorldServer server, IInventory inventory, Random random, ItemStack stack, int fromSlot) {
WeightedItemCollection weightedItemCollection = inventoryGenerator(stack);
inventory.setInventorySlotContents(fromSlot, ItemStack.EMPTY);
if (weightedItemCollection != null) {
IntegerRange range = getGenerationCount(stack);
int amount = range.getMin() < range.getMax() ? random.nextInt(range.getMax() - range.getMin() + 1) + range.getMin() : 0;
TIntList emptySlots = emptySlots(inventory);
for (int i = 0; i < amount; i++) {
int slot = emptySlots.isEmpty() ? random.nextInt(inventory.getSizeInventory()) : emptySlots.removeAt(random.nextInt(emptySlots.size()));
ItemStack generated = weightedItemCollection.getRandomItemStack(server, random);
if (generated != null)
inventory.setInventorySlotContents(slot, generated);
}
}
}
use of ivorius.ivtoolkit.gui.IntegerRange in project RecurrentComplex by Ivorforce.
the class TableDataSourceBlockPos method cellForIndexInSegment.
@Override
public TableCell cellForIndexInSegment(GuiTable table, int index, int segment) {
IntegerRange range;
int val;
String title;
switch(index) {
case 0:
range = rangeX;
val = coord.getX();
title = titleX;
break;
case 1:
range = rangeY;
val = coord.getY();
title = titleY;
break;
default:
range = rangeZ;
val = coord.getZ();
title = titleZ;
break;
}
if (range != null) {
TableCellInteger cell = new TableCellInteger(null, val, range.min, range.max);
cell.addPropertyConsumer(createConsumer(index));
return new TitledCell(title, cell);
} else {
TableCellStringInt cell = new TableCellStringInt(null, val);
cell.addPropertyConsumer(createConsumer(index));
return new TitledCell(title, cell);
}
}
use of ivorius.ivtoolkit.gui.IntegerRange in project RecurrentComplex by Ivorforce.
the class IntegerRanges method crop.
@Nullable
public static IntegerRange crop(IntegerRange range, List<IntegerRange> ranges) {
int[] i = new int[] { range.max, range.min };
ranges.stream().filter(r -> intersects(range, r)).forEach(r -> {
i[0] = Math.min(i[0], r.min);
i[1] = Math.max(i[1], r.max);
});
return i[0] < i[1] ? new IntegerRange(Math.max(range.min, i[0]), Math.min(range.max, i[1])) : null;
}
use of ivorius.ivtoolkit.gui.IntegerRange in project RecurrentComplex by Ivorforce.
the class IntegerRanges method intersection.
@Nullable
public static IntegerRange intersection(IntegerRange range1, IntegerRange range2) {
int min = Math.max(range1.min, range2.min);
int max = Math.min(range1.max, range2.max);
return min < max ? new IntegerRange(min, max) : null;
}
Aggregations