Search in sources :

Example 1 with ISidedWidget

use of me.desht.pneumaticcraft.common.progwidgets.ISidedWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgWidgetCondition method initGui.

@Override
public void initGui() {
    super.initGui();
    if (isSidedWidget()) {
        for (int i = 0; i < 6; i++) {
            String sideName = PneumaticCraftUtils.getOrientationName(EnumFacing.getFront(i));
            GuiCheckBox checkBox = new GuiCheckBox(i, guiLeft + 4, guiTop + 30 + i * 12, 0xFF404040, 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<>();
        radioButton = new GuiRadioButton(6, guiLeft + baseX, guiTop + 30, 0xFF404040, "Any block");
        radioButton.checked = !((ICondition) widget).isAndFunction();
        addWidget(radioButton);
        radioButtons.add(radioButton);
        radioButton.otherChoices = radioButtons;
        radioButton = new GuiRadioButton(7, guiLeft + baseX, guiTop + 42, 0xFF404040, "All blocks");
        radioButton.checked = ((ICondition) widget).isAndFunction();
        addWidget(radioButton);
        radioButtons.add(radioButton);
        radioButton.otherChoices = radioButtons;
    }
    if (requiresNumber()) {
        radioButtons = new ArrayList<>();
        for (int i = 0; i < ICondition.Operator.values().length; i++) {
            radioButton = new GuiRadioButton(8 + i, guiLeft + baseX, guiTop + baseY + i * 12, 0xFF404040, 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(me.desht.pneumaticcraft.common.progwidgets.ISidedWidget) GuiCheckBox(me.desht.pneumaticcraft.client.gui.widget.GuiCheckBox) GuiRadioButton(me.desht.pneumaticcraft.client.gui.widget.GuiRadioButton) ICondition(me.desht.pneumaticcraft.common.progwidgets.ICondition) WidgetTextField(me.desht.pneumaticcraft.client.gui.widget.WidgetTextField)

Example 2 with ISidedWidget

use of me.desht.pneumaticcraft.common.progwidgets.ISidedWidget in project pnc-repressurized by TeamPneumatic.

the class DroneEntityAIInventoryImport method importItems.

private boolean importItems(BlockPos pos, boolean simulate) {
    TileEntity te = drone.world().getTileEntity(pos);
    boolean[] sides = ((ISidedWidget) widget).getSides();
    for (int d = 0; d < sides.length; d++) {
        if (!sides[d]) {
            continue;
        }
        IItemHandler inv = IOHelper.getInventoryForTE(te, EnumFacing.getFront(d));
        if (inv == null) {
            continue;
        }
        for (int i = 0; i < inv.getSlots(); i++) {
            ItemStack stack = inv.getStackInSlot(i);
            if (!stack.isEmpty()) {
                if (widget.isItemValidForFilters(stack)) {
                    ItemStack importedStack = IOHelper.extract(inv, i, true);
                    if (importedStack.isEmpty()) {
                        continue;
                    }
                    if (((ICountWidget) widget).useCount())
                        importedStack.setCount(Math.min(importedStack.getCount(), getRemainingCount()));
                    ItemStack remainder = IOHelper.insert(drone, importedStack.copy(), EnumFacing.UP, simulate);
                    int removedItems = importedStack.getCount() - remainder.getCount();
                    if (!simulate) {
                        inv.extractItem(i, removedItems, false);
                        decreaseCount(removedItems);
                        drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
                        if (((ICountWidget) widget).useCount() && getRemainingCount() <= 0) {
                            return false;
                        }
                    } else if (removedItems > 0) {
                        return true;
                    } else {
                        drone.addDebugEntry("gui.progWidget.inventoryImport.debug.filledToMax", pos);
                    }
                } else {
                    drone.addDebugEntry("gui.progWidget.inventoryImport.debug.stackdoesntPassFilter", pos);
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedWidget(me.desht.pneumaticcraft.common.progwidgets.ISidedWidget) IItemHandler(net.minecraftforge.items.IItemHandler) ICountWidget(me.desht.pneumaticcraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISidedWidget

use of me.desht.pneumaticcraft.common.progwidgets.ISidedWidget in project pnc-repressurized by TeamPneumatic.

the class DroneAILiquidImport method emptyTank.

private boolean emptyTank(BlockPos pos, boolean simulate) {
    if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.world().getTileEntity(pos);
        if (te != null) {
            for (int i = 0; i < 6; i++) {
                if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i))) {
                    IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i));
                    FluidStack importedFluid = handler.drain(Integer.MAX_VALUE, false);
                    if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) {
                        int filledAmount = drone.getTank().fill(importedFluid, false);
                        if (filledAmount > 0) {
                            if (((ICountWidget) widget).useCount())
                                filledAmount = Math.min(filledAmount, getRemainingCount());
                            if (!simulate) {
                                decreaseCount(drone.getTank().fill(handler.drain(filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
            }
            drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
        } else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock());
            if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.world(), pos)) {
                if (!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.world().setBlockToAir(pos);
                }
                return true;
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedWidget(me.desht.pneumaticcraft.common.progwidgets.ISidedWidget) ILiquidFiltered(me.desht.pneumaticcraft.common.progwidgets.ILiquidFiltered) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ICountWidget(me.desht.pneumaticcraft.common.progwidgets.ICountWidget) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

ISidedWidget (me.desht.pneumaticcraft.common.progwidgets.ISidedWidget)3 ICountWidget (me.desht.pneumaticcraft.common.progwidgets.ICountWidget)2 TileEntity (net.minecraft.tileentity.TileEntity)2 GuiCheckBox (me.desht.pneumaticcraft.client.gui.widget.GuiCheckBox)1 GuiRadioButton (me.desht.pneumaticcraft.client.gui.widget.GuiRadioButton)1 WidgetTextField (me.desht.pneumaticcraft.client.gui.widget.WidgetTextField)1 ICondition (me.desht.pneumaticcraft.common.progwidgets.ICondition)1 ILiquidFiltered (me.desht.pneumaticcraft.common.progwidgets.ILiquidFiltered)1 ItemStack (net.minecraft.item.ItemStack)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 IItemHandler (net.minecraftforge.items.IItemHandler)1