Search in sources :

Example 1 with IntegerRange

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;
}
Also used : IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) Pair(org.apache.commons.lang3.tuple.Pair) ivorius.reccomplex.utils(ivorius.reccomplex.utils) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) DoubleMath(com.google.common.math.DoubleMath) TableDataSourceFactorMatch(ivorius.reccomplex.gui.editstructure.placer.TableDataSourceFactorMatch) WorldCache(ivorius.ivtoolkit.world.WorldCache) EnumFacing(net.minecraft.util.EnumFacing) LineSelection(ivorius.ivtoolkit.util.LineSelection) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) BlockPos(net.minecraft.util.math.BlockPos) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with IntegerRange

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);
        }
    }
}
Also used : IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WeightedItemCollection(ivorius.reccomplex.world.storage.loot.WeightedItemCollection) TIntList(gnu.trove.list.TIntList) GuiEditItemStack(ivorius.reccomplex.gui.inventorygen.GuiEditItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IntegerRange

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);
    }
}
Also used : TitledCell(ivorius.reccomplex.gui.table.cell.TitledCell) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) TableCellInteger(ivorius.reccomplex.gui.table.cell.TableCellInteger) TableCellStringInt(ivorius.reccomplex.gui.table.cell.TableCellStringInt)

Example 4 with IntegerRange

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;
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Collection(java.util.Collection) Nonnull(javax.annotation.Nonnull) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) Nullable(javax.annotation.Nullable) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) Nullable(javax.annotation.Nullable)

Example 5 with IntegerRange

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;
}
Also used : IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) Nullable(javax.annotation.Nullable)

Aggregations

IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)10 Nullable (javax.annotation.Nullable)4 TableCellInteger (ivorius.reccomplex.gui.table.cell.TableCellInteger)3 TableCellStringInt (ivorius.reccomplex.gui.table.cell.TableCellStringInt)3 TitledCell (ivorius.reccomplex.gui.table.cell.TitledCell)3 Nonnull (javax.annotation.Nonnull)3 com.google.gson (com.google.gson)2 IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)2 IvTranslations (ivorius.ivtoolkit.tools.IvTranslations)2 LineSelection (ivorius.ivtoolkit.util.LineSelection)2 WorldCache (ivorius.ivtoolkit.world.WorldCache)2 StructureBoundingBoxes (ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes)2 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)2 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)2 TableDataSource (ivorius.reccomplex.gui.table.datasource.TableDataSource)2 JsonUtils (ivorius.reccomplex.json.JsonUtils)2 Type (java.lang.reflect.Type)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Pair (org.apache.commons.lang3.tuple.Pair)2