Search in sources :

Example 1 with TObjectDoubleHashMap

use of gnu.trove.map.hash.TObjectDoubleHashMap in project RecurrentComplex by Ivorforce.

the class TransformerAbstractCloud method buildCloud.

public TObjectDoubleMap<BlockPos> buildCloud(S instanceData, IvWorldData worldData, StructurePrepareContext context, TransformerMulti transformer, TransformerMulti.InstanceData transformerInstanceData) {
    Random random = context.random;
    Environment environment = context.environment;
    BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
    int[] strucSize = new int[] { worldData.blockCollection.width, worldData.blockCollection.height, worldData.blockCollection.length };
    TObjectDoubleMap<BlockPos> cloud = new TObjectDoubleHashMap<>();
    BlurredValueField blurredValueField = new BlurredValueField(strucSize);
    int gridCoords = 1;
    for (int d : strucSize) gridCoords *= d;
    int values = MathHelper.floor(gridCoords * (1f / 25f) + 0.5f);
    for (int i = 0; i < values; i++) blurredValueField.addValue(1 + (random.nextFloat() - random.nextFloat()) * (float) cloudExpansionRandomization() / 100f, random);
    BlockAreas.mutablePositions(worldData.blockCollection.area()).forEach(pos -> {
        IBlockState state = worldData.blockCollection.getBlockState(pos);
        BlockPos worldCoord = context.transform.apply(pos, strucSize).add(lowerCoord);
        if (matches(instanceData, state) && canPenetrate(environment, worldData, worldCoord, 1, transformer, transformerInstanceData))
            cloud.put(pos.toImmutable(), 1);
    });
    double expansionDistance = cloudExpansionDistance();
    BlockPos.MutableBlockPos sidePos = new BlockPos.MutableBlockPos();
    BlockPos.MutableBlockPos sideWorldCoord = new BlockPos.MutableBlockPos();
    if (expansionDistance > 0.000001) {
        // The code below will be called _often_, so let's cache the divisions
        double[] sideFalloffs = new double[6];
        List<EnumFacing> checkSides = new ArrayList<>();
        for (EnumFacing side : EnumFacing.values()) {
            double sideExpansionDistance = cloudExpansionDistance(side);
            double sideFalloff = sideExpansionDistance > 0.000001 ? 1.0f / sideExpansionDistance / expansionDistance : 0;
            if (sideFalloff > 0) {
                checkSides.add(side);
                sideFalloffs[side.getIndex()] = sideFalloff;
            }
        }
        visitRecursively(Sets.newHashSet(cloud.keySet()), (changed, pos) -> {
            double density = cloud.get(pos);
            for (EnumFacing side : checkSides) {
                double sideFalloff = sideFalloffs[side.getIndex()];
                IvMutableBlockPos.offset(pos, sidePos, side);
                double sideDensity = density - sideFalloff * blurredValueField.getValue(sidePos.getX(), sidePos.getY(), sidePos.getZ());
                if (sideDensity <= 0 || cloud.get(sidePos) >= sideDensity - 0.00001)
                    continue;
                IvMutableBlockPos.add(context.transform.applyOn(sidePos, sideWorldCoord, strucSize), lowerCoord);
                if (!canPenetrate(environment, worldData, sideWorldCoord, sideDensity, transformer, transformerInstanceData))
                    continue;
                BlockPos immutableSidePos = sidePos.toImmutable();
                cloud.put(immutableSidePos, sideDensity);
                changed.add(immutableSidePos);
            }
            return true;
        });
    }
    return cloud;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlurredValueField(ivorius.ivtoolkit.random.BlurredValueField) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos)

Aggregations

TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)1 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)1 BlurredValueField (ivorius.ivtoolkit.random.BlurredValueField)1 Environment (ivorius.reccomplex.world.gen.feature.structure.Environment)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1