Search in sources :

Example 1 with IFilledTemplate

use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.

the class ShapePatternsTester method testSphereEquality.

/**
 * Ensure that (for the same implicit size sphere) SPHERE, SPHERE_HALF, SPHERE_QUARTER, and SPHERE_EIGHTH all
 * generate the same sphere.
 *
 * @param size an eighth of the size of the entire sphere.
 */
@Theory
public void testSphereEquality(BlockPos size) {
    BlockPos fullSize = new BlockPos(size.getX() * 2, size.getY() * 2, size.getZ() * 2);
    System.out.println("Testing spheres for equality in " + StringUtilBC.blockPosToString(fullSize));
    IStatementParameter[] fullParams = new IStatementParameter[] { // 
    PatternParameterHollow.HOLLOW };
    IFilledTemplate filledTemplateFull = createFilledTemplate(fullSize);
    Assert.assertTrue(BCBuildersStatements.PATTERN_SPHERE.fillTemplate(filledTemplateFull, fullParams));
    System.out.println("Full:\n" + filledTemplateFull);
    // Test halfs
    for (EnumFacing face : EnumFacing.VALUES) {
        BlockPos halfSize = VecUtil.replaceValue(fullSize, face.getAxis(), VecUtil.getValue(size, face.getAxis()));
        IStatementParameter[] params = new IStatementParameter[] { // 
        PatternParameterHollow.HOLLOW, // 
        PatternParameterFacing.get(face) };
        IFilledTemplate filledTemplateHalf = createFilledTemplate(halfSize);
        Assert.assertTrue(BCBuildersStatements.PATTERN_HEMI_SPHERE.fillTemplate(filledTemplateHalf, params));
        System.out.println("Half:\n" + filledTemplateHalf);
        int dx = face == EnumFacing.WEST ? filledTemplateHalf.getSize().getX() : 0;
        int dy = face == EnumFacing.DOWN ? filledTemplateHalf.getSize().getY() : 0;
        int dz = face == EnumFacing.NORTH ? filledTemplateHalf.getSize().getZ() : 0;
        for (int z = 0; z <= filledTemplateHalf.getMax().getZ(); z++) {
            for (int y = 0; y <= filledTemplateHalf.getMax().getY(); y++) {
                for (int x = 0; x <= filledTemplateHalf.getMax().getX(); x++) {
                    if (filledTemplateFull.get(x + dx, y + dy, z + dz) != filledTemplateHalf.get(x, y, z)) {
                        Assert.fail(String.format("Half sphere[%s] didn't match full sphere at (%s, %s, %s)", face, x, y, z));
                    }
                }
            }
        }
    }
// TODO: Test quarters
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IStatementParameter(buildcraft.api.statements.IStatementParameter) IFilledTemplate(buildcraft.api.filler.IFilledTemplate) Theory(org.junit.experimental.theories.Theory)

Example 2 with IFilledTemplate

use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.

the class ShapePatternsTester method testTinyTemplate.

@Theory
public void testTinyTemplate(IFillerPatternShape pattern, BlockPos size) {
    System.out.print("Testing pattern " + pattern.getUniqueTag() + " in " + StringUtilBC.blockPosToString(size));
    try {
        IStatementParameter[] params = new IStatementParameter[pattern.maxParameters()];
        for (int i = 0; i < params.length; i++) {
            params[i] = pattern.createParameter(i);
        }
        IFilledTemplate filledTemplate = createFilledTemplate(size);
        boolean b = pattern.fillTemplate(filledTemplate, params);
        if (pattern == BCBuildersStatements.PATTERN_NONE) {
            Assert.assertFalse(b);
        } else {
            Assert.assertTrue(b);
        }
        System.out.println(" -> success");
    } catch (Throwable t) {
        System.out.println(" -> fail");
        throw t;
    }
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter) IFilledTemplate(buildcraft.api.filler.IFilledTemplate) Theory(org.junit.experimental.theories.Theory)

Example 3 with IFilledTemplate

use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.

the class ShapePatternsTester method createFilledTemplate.

private IFilledTemplate createFilledTemplate(BlockPos size) {
    Template template = new Template();
    template.size = size;
    template.offset = BlockPos.ORIGIN;
    template.data = new BitSet(Snapshot.getDataSize(size));
    return template.getFilledTemplate();
}
Also used : BitSet(java.util.BitSet) Template(buildcraft.builders.snapshot.Template) IFilledTemplate(buildcraft.api.filler.IFilledTemplate)

Aggregations

IFilledTemplate (buildcraft.api.filler.IFilledTemplate)3 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 Theory (org.junit.experimental.theories.Theory)2 Template (buildcraft.builders.snapshot.Template)1 BitSet (java.util.BitSet)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1