Search in sources :

Example 1 with WorldCache

use of ivorius.ivtoolkit.world.WorldCache 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 WorldCache

use of ivorius.ivtoolkit.world.WorldCache in project RecurrentComplex by Ivorforce.

the class FactorMatch method consider.

@Override
public List<Pair<LineSelection, Float>> consider(WorldCache cache, LineSelection considerable, @Nullable IvBlockCollection blockCollection, Set<BlockPos> surface, 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) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) 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) Set(java.util.Set) LineSelection(ivorius.ivtoolkit.util.LineSelection) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) List(java.util.List) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) IntegerRanges(ivorius.reccomplex.utils.IntegerRanges) com.google.gson(com.google.gson) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with WorldCache

use of ivorius.ivtoolkit.world.WorldCache 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;
}
Also used : IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) java.util(java.util) RayMove(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayMove) RayMatcher(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayMatcher) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) TypeToken(com.google.common.reflect.TypeToken) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RayDynamicPosition(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayDynamicPosition) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) Pair(org.apache.commons.lang3.tuple.Pair) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) LineSelections(ivorius.ivtoolkit.util.LineSelections) WorldServer(net.minecraft.world.WorldServer) Nonnull(javax.annotation.Nonnull) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) WorldCache(ivorius.ivtoolkit.world.WorldCache) RayAverageMatcher(ivorius.reccomplex.world.gen.feature.structure.generic.placement.rays.RayAverageMatcher) LineSelection(ivorius.ivtoolkit.util.LineSelection) SerializedName(com.google.gson.annotations.SerializedName) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) GenericPlacerPresets(ivorius.reccomplex.world.gen.feature.structure.generic.presets.GenericPlacerPresets) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) PresettedObject(ivorius.reccomplex.utils.presets.PresettedObject) LineSelection(ivorius.ivtoolkit.util.LineSelection) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WorldServer(net.minecraft.world.WorldServer) WorldCache(ivorius.ivtoolkit.world.WorldCache) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with WorldCache

use of ivorius.ivtoolkit.world.WorldCache in project RecurrentComplex by Ivorforce.

the class GenericPlacer method place.

public int place(StructurePlaceContext context, @Nullable IvBlockCollection blockCollection, Set<BlockPos> surface) {
    if (factors.isEmpty())
        return Placer.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, surface, context);
        // Quick remove null considerations
        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());
        // Remove everything not even considered
        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() : Placer.DONT_GENERATE;
}
Also used : IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) java.util(java.util) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) TypeToken(com.google.common.reflect.TypeToken) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) LineSelections(ivorius.ivtoolkit.util.LineSelections) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) WorldServer(net.minecraft.world.WorldServer) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) WorldCache(ivorius.ivtoolkit.world.WorldCache) LineSelection(ivorius.ivtoolkit.util.LineSelection) BlockPos(net.minecraft.util.math.BlockPos) SerializedName(com.google.gson.annotations.SerializedName) 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) LineSelection(ivorius.ivtoolkit.util.LineSelection) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WorldServer(net.minecraft.world.WorldServer) WorldCache(ivorius.ivtoolkit.world.WorldCache) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

com.google.gson (com.google.gson)4 IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)4 IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)4 LineSelection (ivorius.ivtoolkit.util.LineSelection)4 WorldCache (ivorius.ivtoolkit.world.WorldCache)4 StructureBoundingBoxes (ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes)4 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)4 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)4 TableDataSource (ivorius.reccomplex.gui.table.datasource.TableDataSource)4 JsonUtils (ivorius.reccomplex.json.JsonUtils)4 Type (java.lang.reflect.Type)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 Pair (org.apache.commons.lang3.tuple.Pair)4 java.util (java.util)3 BlockPos (net.minecraft.util.math.BlockPos)3 DoubleMath (com.google.common.math.DoubleMath)2 TypeToken (com.google.common.reflect.TypeToken)2 SerializedName (com.google.gson.annotations.SerializedName)2 BlockAreas (ivorius.ivtoolkit.blocks.BlockAreas)2