Search in sources :

Example 6 with IvBlockCollection

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;
}
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 7 with IvBlockCollection

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;
        });
    }
}
Also used : IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection)

Example 8 with IvBlockCollection

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);
    }
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection)

Aggregations

IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)8 BlockPos (net.minecraft.util.math.BlockPos)7 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)5 Nullable (javax.annotation.Nullable)4 IBlockState (net.minecraft.block.state.IBlockState)4 com.google.gson (com.google.gson)3 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)3 StructureBoundingBoxes (ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes)3 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)3 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)3 TableDataSource (ivorius.reccomplex.gui.table.datasource.TableDataSource)3 JsonUtils (ivorius.reccomplex.json.JsonUtils)3 Type (java.lang.reflect.Type)3 Collectors (java.util.stream.Collectors)3 WorldServer (net.minecraft.world.WorldServer)3 BlockAreas (ivorius.ivtoolkit.blocks.BlockAreas)2 IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)2 LineSelection (ivorius.ivtoolkit.util.LineSelection)2 WorldCache (ivorius.ivtoolkit.world.WorldCache)2 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)2