Search in sources :

Example 1 with ICondition

use of pneumaticCraft.common.progwidgets.ICondition in project PneumaticCraft by MineMaarten.

the class GuiProgWidgetCondition method initGui.

@Override
public void initGui() {
    super.initGui();
    if (isSidedWidget()) {
        for (int i = 0; i < 6; i++) {
            String sideName = PneumaticCraftUtils.getOrientationName(ForgeDirection.getOrientation(i));
            GuiCheckBox checkBox = new GuiCheckBox(i, guiLeft + 4, guiTop + 30 + i * 12, 0xFF000000, sideName);
            checkBox.checked = ((ISidedWidget) widget).getSides()[i];
            addWidget(checkBox);
        }
    }
    int baseX = isSidedWidget() ? 90 : 4;
    int baseY = isUsingAndOr() ? 60 : 30;
    List<GuiRadioButton> radioButtons;
    GuiRadioButton radioButton;
    if (isUsingAndOr()) {
        radioButtons = new ArrayList<GuiRadioButton>();
        radioButton = new GuiRadioButton(6, guiLeft + baseX, guiTop + 30, 0xFF000000, "Any block");
        radioButton.checked = !((ICondition) widget).isAndFunction();
        addWidget(radioButton);
        radioButtons.add(radioButton);
        radioButton.otherChoices = radioButtons;
        radioButton = new GuiRadioButton(7, guiLeft + baseX, guiTop + 42, 0xFF000000, "All blocks");
        radioButton.checked = ((ICondition) widget).isAndFunction();
        addWidget(radioButton);
        radioButtons.add(radioButton);
        radioButton.otherChoices = radioButtons;
    }
    if (requiresNumber()) {
        radioButtons = new ArrayList<GuiRadioButton>();
        for (int i = 0; i < ICondition.Operator.values().length; i++) {
            radioButton = new GuiRadioButton(8 + i, guiLeft + baseX, guiTop + baseY + i * 12, 0xFF000000, ICondition.Operator.values()[i].toString());
            radioButton.checked = ((ICondition) widget).getOperator().ordinal() == i;
            addWidget(radioButton);
            radioButtons.add(radioButton);
            radioButton.otherChoices = radioButtons;
        }
        textField = new WidgetTextField(Minecraft.getMinecraft().fontRenderer, guiLeft + baseX, guiTop + baseY + 30, 50, 11);
        textField.setText(((ICondition) widget).getRequiredCount() + "");
        addWidget(textField);
    }
}
Also used : ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) GuiCheckBox(pneumaticCraft.client.gui.widget.GuiCheckBox) GuiRadioButton(pneumaticCraft.client.gui.widget.GuiRadioButton) ICondition(pneumaticCraft.common.progwidgets.ICondition) WidgetTextField(pneumaticCraft.client.gui.widget.WidgetTextField)

Example 2 with ICondition

use of pneumaticCraft.common.progwidgets.ICondition in project PneumaticCraft by MineMaarten.

the class ProgWidgetRFCondition method getEvaluator.

@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(ChunkPosition pos) {
            TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
            int energy = 0;
            if (te instanceof IEnergyReceiver) {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    if (getSides()[d.ordinal()]) {
                        energy = Math.max(((IEnergyReceiver) te).getEnergyStored(d), energy);
                    }
                }
            }
            if (te instanceof IEnergyProvider) {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    if (getSides()[d.ordinal()]) {
                        energy = Math.max(((IEnergyProvider) te).getEnergyStored(d), energy);
                    }
                }
            }
            return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? energy == ((ICondition) widget).getRequiredCount() : energy >= ((ICondition) widget).getRequiredCount();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyProvider(cofh.api.energy.IEnergyProvider) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) ICondition(pneumaticCraft.common.progwidgets.ICondition)

Aggregations

ICondition (pneumaticCraft.common.progwidgets.ICondition)2 IEnergyProvider (cofh.api.energy.IEnergyProvider)1 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 GuiCheckBox (pneumaticCraft.client.gui.widget.GuiCheckBox)1 GuiRadioButton (pneumaticCraft.client.gui.widget.GuiRadioButton)1 WidgetTextField (pneumaticCraft.client.gui.widget.WidgetTextField)1 DroneAIBlockCondition (pneumaticCraft.common.ai.DroneAIBlockCondition)1 ISidedWidget (pneumaticCraft.common.progwidgets.ISidedWidget)1