Search in sources :

Example 1 with PatternParameterRotation

use of buildcraft.builders.snapshot.pattern.parameter.PatternParameterRotation in project BuildCraft by BuildCraft.

the class PatternShape2d method fillTemplate.

@Override
public boolean fillTemplate(IFilledTemplate filledTemplate, IStatementParameter[] params) {
    PatternParameterAxis axis = getParam(0, params, PatternParameterAxis.Y);
    PatternParameterRotation dir = getParam(2, params, PatternParameterRotation.NONE);
    PathIterator2d iterator = getIterator(filledTemplate, axis);
    int maxA = axis == PatternParameterAxis.X ? filledTemplate.getMax().getY() : filledTemplate.getMax().getX();
    int maxB = axis == PatternParameterAxis.Z ? filledTemplate.getMax().getY() : filledTemplate.getMax().getZ();
    int normMaxA = maxA;
    int normMaxB = maxB;
    if (dir.rotationCount % 2 == 1) {
        int maxT = maxA;
        maxA = maxB;
        maxB = maxT;
        final int max_b = maxB;
        final PathIterator2d old = iterator;
        iterator = (a, b) -> old.iterate(max_b - b, a);
    }
    if (dir.rotationCount > 1) {
        final PathIterator2d old = iterator;
        final int max_a = maxA;
        final int max_b = maxB;
        // Technically this is wrong... but it doesn't matter for any of
        // the shapes that use this, as they are all symetrical
        iterator = (a, b) -> old.iterate(max_a - a, max_b - b);
    }
    LineList list = new LineList(iterator);
    genShape(maxA, maxB, list);
    PatternParameterHollow filled = getParam(1, params, PatternParameterHollow.HOLLOW);
    if (filled.filled) {
        int fillA = list.fillInA;
        int fillB = list.fillInB;
        if (fillA != -1 && fillB != -1) {
            maxA = normMaxA;
            maxB = normMaxB;
            if (dir.rotationCount % 2 == 1) {
                int fillT = fillA;
                fillA = fillB;
                fillB = fillT;
            }
            if (dir.rotationCount > 1) {
                fillA = maxA - fillA;
                fillB = maxB - fillB;
            }
            iterator = getIterator(filledTemplate, axis);
            PositionGetter getter = getFillGetter(filledTemplate, axis);
            if (filled.outerFilled) {
                iterator = (a, b) -> {
                };
            }
            // Expand outwards from the point
            Set<Point> visited = new HashSet<>();
            List<Point> open = new ArrayList<>();
            open.add(new Point(fillA, fillB));
            while (!open.isEmpty()) {
                List<Point> next = new ArrayList<>();
                for (Point p : open) {
                    if (p.a < 0 || p.a > maxA) {
                        continue;
                    }
                    if (p.b < 0 || p.b > maxB) {
                        continue;
                    }
                    if (!visited.add(p)) {
                        continue;
                    }
                    if (getter.isFilled(p.a, p.b)) {
                        continue;
                    }
                    iterator.iterate(p.a, p.b);
                    next.add(new Point(p.a + 1, p.b));
                    next.add(new Point(p.a - 1, p.b));
                    next.add(new Point(p.a, p.b + 1));
                    next.add(new Point(p.a, p.b - 1));
                }
                open = next;
            }
            if (filled.outerFilled) {
                iterator = getIterator(filledTemplate, axis);
                for (int a = 0; a <= maxA; a++) {
                    for (int b = 0; b <= maxB; b++) {
                        if (visited.contains(new Point(a, b))) {
                            continue;
                        }
                        iterator.iterate(a, b);
                    }
                }
            }
        }
    }
    return true;
}
Also used : PatternParameterAxis(buildcraft.builders.snapshot.pattern.parameter.PatternParameterAxis) ArrayList(java.util.ArrayList) PatternParameterHollow(buildcraft.builders.snapshot.pattern.parameter.PatternParameterHollow) PathIterator2d(buildcraft.lib.misc.PositionUtil.PathIterator2d) PatternParameterRotation(buildcraft.builders.snapshot.pattern.parameter.PatternParameterRotation) HashSet(java.util.HashSet)

Example 2 with PatternParameterRotation

use of buildcraft.builders.snapshot.pattern.parameter.PatternParameterRotation in project BuildCraft by BuildCraft.

the class PatternSpherePart method fillTemplate.

@Override
public boolean fillTemplate(IFilledTemplate filledTemplate, IStatementParameter[] params) {
    PatternParameterFacing facing = getParam(1, params, PatternParameterFacing.DOWN);
    PatternParameterRotation rotation = getParam(2, params, PatternParameterRotation.NONE);
    PatternParameterHollow hollow = getParam(0, params, PatternParameterHollow.FILLED_INNER);
    Vec3d center;
    Vec3d radius;
    Set<EnumFacing> innerSides = EnumSet.noneOf(EnumFacing.class);
    Vec3d max = new Vec3d(filledTemplate.getMax().getX(), filledTemplate.getMax().getY(), filledTemplate.getMax().getZ());
    center = VecUtil.scale(max, 0.5);
    radius = center.addVector(0.5, 0.5, 0.5);
    innerSides.add(facing.face);
    Axis axis = facing.face.getAxis();
    Vec3d offset = VecUtil.offset(Vec3d.ZERO, facing.face, VecUtil.getValue(radius, axis));
    center = center.add(offset);
    radius = VecUtil.replaceValue(radius, axis, VecUtil.getValue(radius, axis) * 2);
    if (type.openFaces > 1) {
        Axis secondaryAxis;
        if (rotation.rotationCount % 2 == 1) {
            secondaryAxis = axis == Axis.X ? Axis.Y : axis == Axis.Y ? Axis.Z : Axis.X;
        } else {
            secondaryAxis = axis == Axis.X ? Axis.Z : axis == Axis.Y ? Axis.X : Axis.Y;
        }
        EnumFacing secondaryFace = VecUtil.getFacing(secondaryAxis, rotation.rotationCount >= 2);
        innerSides.add(secondaryFace);
        offset = VecUtil.offset(Vec3d.ZERO, secondaryFace, VecUtil.getValue(radius, secondaryAxis));
        center = center.add(offset);
        radius = VecUtil.replaceValue(radius, secondaryAxis, VecUtil.getValue(radius, secondaryAxis) * 2);
        if (type.openFaces > 2) {
            Axis tertiaryAxis;
            int rotationCount = (rotation.rotationCount + 1) & 3;
            if (rotationCount % 2 == 1) {
                tertiaryAxis = axis == Axis.X ? Axis.Y : axis == Axis.Y ? Axis.Z : Axis.X;
            } else {
                tertiaryAxis = axis == Axis.X ? Axis.Z : axis == Axis.Y ? Axis.X : Axis.Y;
            }
            EnumFacing tertiaryFace = VecUtil.getFacing(tertiaryAxis, rotationCount >= 2);
            innerSides.add(tertiaryFace);
            offset = VecUtil.offset(Vec3d.ZERO, tertiaryFace, VecUtil.getValue(radius, tertiaryAxis));
            center = center.add(offset);
            radius = VecUtil.replaceValue(radius, tertiaryAxis, VecUtil.getValue(radius, tertiaryAxis) * 2);
        }
    }
    double cx = center.x;
    double cy = center.y;
    double cz = center.z;
    double rx = radius.x;
    double ry = radius.y;
    double rz = radius.z;
    BitSet data = null;
    if (hollow != PatternParameterHollow.FILLED_INNER) {
        data = new BitSet(Snapshot.getDataSize(filledTemplate.getSize()));
    }
    for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
        double dx = Math.abs(x - cx) / rx;
        double dxx = dx * dx;
        for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
            double dy = Math.abs(y - cy) / ry;
            double dyy = dy * dy;
            for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
                double dz = Math.abs(z - cz) / rz;
                double dzz = dz * dz;
                if (dxx + dyy + dzz < 1) {
                    if (hollow != PatternParameterHollow.FILLED_INNER) {
                        // noinspection ConstantConditions
                        data.set(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z), true);
                    } else {
                        filledTemplate.set(x, y, z, true);
                    }
                }
            }
        }
    }
    boolean outerFilled = hollow.outerFilled;
    if (hollow != PatternParameterHollow.FILLED_INNER) {
        // Z iteration
        for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
            for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
                if (!innerSides.contains(EnumFacing.NORTH)) {
                    for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
                if (!innerSides.contains(EnumFacing.SOUTH)) {
                    for (int z = filledTemplate.getMax().getZ(); z >= 0; z--) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
            }
        }
        // Y iteration
        for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
            for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
                if (!innerSides.contains(EnumFacing.DOWN)) {
                    for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
                if (!innerSides.contains(EnumFacing.UP)) {
                    for (int y = filledTemplate.getMax().getY(); y >= 0; y--) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
            }
        }
        // X iteration
        for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
            for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
                if (!innerSides.contains(EnumFacing.WEST)) {
                    for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
                if (!innerSides.contains(EnumFacing.EAST)) {
                    for (int x = filledTemplate.getMax().getX(); x >= 0; x--) {
                        if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
                            filledTemplate.set(x, y, z, true);
                            break;
                        }
                        if (outerFilled) {
                            filledTemplate.set(x, y, z, true);
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BitSet(java.util.BitSet) PatternParameterHollow(buildcraft.builders.snapshot.pattern.parameter.PatternParameterHollow) PatternParameterFacing(buildcraft.builders.snapshot.pattern.parameter.PatternParameterFacing) Vec3d(net.minecraft.util.math.Vec3d) Axis(net.minecraft.util.EnumFacing.Axis) PatternParameterRotation(buildcraft.builders.snapshot.pattern.parameter.PatternParameterRotation)

Aggregations

PatternParameterHollow (buildcraft.builders.snapshot.pattern.parameter.PatternParameterHollow)2 PatternParameterRotation (buildcraft.builders.snapshot.pattern.parameter.PatternParameterRotation)2 PatternParameterAxis (buildcraft.builders.snapshot.pattern.parameter.PatternParameterAxis)1 PatternParameterFacing (buildcraft.builders.snapshot.pattern.parameter.PatternParameterFacing)1 PathIterator2d (buildcraft.lib.misc.PositionUtil.PathIterator2d)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 HashSet (java.util.HashSet)1 EnumFacing (net.minecraft.util.EnumFacing)1 Axis (net.minecraft.util.EnumFacing.Axis)1 Vec3d (net.minecraft.util.math.Vec3d)1