Search in sources :

Example 6 with IStatementParameter

use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.

the class GuiElementStatementDrag method drawForeground.

@Override
public void drawForeground(float partialTicks) {
    if (isDragging) {
        boolean canPlace = false;
        for (IGuiElement element : gui.getElementsAt(gui.mouse.getX(), gui.mouse.getY())) {
            if (element instanceof IReference<?>) {
                if (checkCanSet((IReference<?>) element, dragging)) {
                    canPlace = true;
                    break;
                }
            }
        }
        GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
        if (!canPlace) {
            GlStateManager.color(1.0f, 0.7f, 0.7f);
        }
        double x = gui.mouse.getX() - 9;
        double y = gui.mouse.getY() - 9;
        if (dragging instanceof IStatementParameter) {
            ParameterRenderer.draw((IStatementParameter) dragging, x, y);
        } else {
            GuiIcon background = GuiElementStatement.SLOT_COLOUR;
            if (dragging instanceof StatementWrapper) {
                EnumPipePart part = ((StatementWrapper) dragging).sourcePart;
                if (part != EnumPipePart.CENTER) {
                    background = background.offset(0, (1 + part.getIndex()) * 18);
                }
            }
            background.drawAt(x, y);
            if (dragging != null) {
                ISprite sprite = dragging.getSprite();
                if (sprite != null) {
                    GuiIcon.drawAt(sprite, x + 1, y + 1, 16);
                }
            }
        }
        GlStateManager.color(1, 1, 1);
    }
}
Also used : StatementWrapper(buildcraft.lib.statement.StatementWrapper) ISprite(buildcraft.api.core.render.ISprite) EnumPipePart(buildcraft.api.core.EnumPipePart) IGuiElement(buildcraft.lib.gui.IGuiElement) IStatementParameter(buildcraft.api.statements.IStatementParameter) IReference(buildcraft.lib.misc.data.IReference) GuiIcon(buildcraft.lib.gui.GuiIcon)

Example 7 with IStatementParameter

use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.

the class GuiElementStatementSource method drawGuiSlot.

public static void drawGuiSlot(@Nullable IGuiSlot guiSlot, double x, double y) {
    if (guiSlot instanceof IStatementParameter) {
        ParameterRenderer.draw((IStatementParameter) guiSlot, x, y);
        return;
    }
    GuiIcon background = GuiElementStatement.SLOT_COLOUR;
    if (guiSlot instanceof StatementWrapper) {
        EnumPipePart part = ((StatementWrapper) guiSlot).sourcePart;
        if (part != EnumPipePart.CENTER) {
            background = background.offset(0, (1 + part.getIndex()) * 18);
        }
    }
    background.drawAt(x, y);
    if (guiSlot != null) {
        ISprite sprite = guiSlot.getSprite();
        if (sprite != null) {
            GuiIcon.drawAt(sprite, x + 1, y + 1, 16);
        }
    }
}
Also used : StatementWrapper(buildcraft.lib.statement.StatementWrapper) ISprite(buildcraft.api.core.render.ISprite) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatementParameter(buildcraft.api.statements.IStatementParameter) GuiIcon(buildcraft.lib.gui.GuiIcon)

Example 8 with IStatementParameter

use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.

the class ActionRobotFilterTool method getGateFilterStacks.

public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
    ArrayList<ItemStack> result = new ArrayList<>();
    for (StatementSlot slot : station.getActiveActions()) {
        if (slot.statement instanceof ActionRobotFilterTool) {
            for (IStatementParameter p : slot.parameters) {
                if (p != null && p instanceof StatementParameterItemStack) {
                    StatementParameterItemStack param = (StatementParameterItemStack) p;
                    ItemStack stack = param.getItemStack();
                    if (stack != null) {
                        result.add(stack);
                    }
                }
            }
        }
    }
    return result;
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) ArrayList(java.util.ArrayList) IStatementParameter(buildcraft.api.statements.IStatementParameter) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 9 with IStatementParameter

use of buildcraft.api.statements.IStatementParameter 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 10 with IStatementParameter

use of buildcraft.api.statements.IStatementParameter 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)

Aggregations

IStatementParameter (buildcraft.api.statements.IStatementParameter)21 IStatement (buildcraft.api.statements.IStatement)5 StatementSlot (buildcraft.api.statements.StatementSlot)4 ArrayList (java.util.ArrayList)4 ItemStack (net.minecraft.item.ItemStack)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 StatementParameterItemStack (buildcraft.api.statements.StatementParameterItemStack)3 EnumPipePart (buildcraft.api.core.EnumPipePart)2 ISprite (buildcraft.api.core.render.ISprite)2 IFilledTemplate (buildcraft.api.filler.IFilledTemplate)2 IGate (buildcraft.api.gates.IGate)2 StatementMouseClick (buildcraft.api.statements.StatementMouseClick)2 IWireManager (buildcraft.api.transport.IWireManager)2 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 StatementWrapper (buildcraft.lib.statement.StatementWrapper)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EnumDyeColor (net.minecraft.item.EnumDyeColor)2 EnumFacing (net.minecraft.util.EnumFacing)2 Theory (org.junit.experimental.theories.Theory)2