Search in sources :

Example 1 with ISidedWidget

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

the class DroneEntityAIInventoryExport method export.

private boolean export(ChunkPosition pos, boolean simulate) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv != null) {
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null) {
                if (widget.isItemValidForFilters(droneStack)) {
                    for (int side = 0; side < 6; side++) {
                        droneStack = drone.getInventory().getStackInSlot(i);
                        if (((ISidedWidget) widget).getSides()[side] && droneStack != null) {
                            droneStack = droneStack.copy();
                            int oldCount = droneStack.stackSize;
                            if (((ICountWidget) widget).useCount())
                                droneStack.stackSize = Math.min(droneStack.stackSize, getRemainingCount());
                            ItemStack remainder = IOHelper.insert(inv, droneStack.copy(), side, simulate);
                            int stackSize = drone.getInventory().getStackInSlot(i).stackSize - (remainder == null ? droneStack.stackSize : droneStack.stackSize - remainder.stackSize);
                            droneStack.stackSize = stackSize;
                            int exportedItems = oldCount - stackSize;
                            if (!simulate) {
                                drone.getInventory().setInventorySlotContents(i, stackSize > 0 ? droneStack : null);
                                decreaseCount(exportedItems);
                            }
                            if (simulate && exportedItems > 0)
                                return true;
                            // doing it for every side for no side sensitive inventories would be a waste.
                            if (!(inv instanceof ISidedInventory))
                                break;
                        }
                    }
                    if (droneStack == null && !simulate)
                        drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
                    else
                        drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
                } else {
                    drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
                }
            }
        }
    } else {
        drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ISidedWidget

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

the class DroneEntityAIInventoryImport method importItems.

private boolean importItems(ChunkPosition pos, boolean simulate) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv != null) {
        Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
        for (Integer i : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(i);
            if (stack != null && IOHelper.canExtractItemFromInventory(inv, stack, i, ((ISidedWidget) widget).getSides())) {
                if (widget.isItemValidForFilters(stack)) {
                    ItemStack importedStack = stack.copy();
                    if (((ICountWidget) widget).useCount())
                        importedStack.stackSize = Math.min(importedStack.stackSize, getRemainingCount());
                    ItemStack remainder = IOHelper.insert(drone.getInventory(), importedStack.copy(), 0, simulate);
                    int removedItems = importedStack.stackSize - (remainder != null ? remainder.stackSize : 0);
                    if (!simulate) {
                        ItemStack newStack = stack.copy();
                        newStack.stackSize = stack.stackSize - removedItems;
                        inv.setInventorySlotContents(i, newStack.stackSize > 0 ? newStack : null);
                        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);
                }
            }
        }
    } else {
        drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISidedWidget

use of pneumaticCraft.common.progwidgets.ISidedWidget 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 4 with ISidedWidget

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

the class DroneAIPlace method doBlockInteraction.

@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
    if (drone.getPathNavigator().hasNoPath()) {
        ForgeDirection side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null && droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).field_150939_a.canPlaceBlockOnSide(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()).ordinal())) {
                if (widget.isItemValidForFilters(droneStack)) {
                    if (drone instanceof EntityDrone) {
                        EntityDrone entity = (EntityDrone) drone;
                        // Teleport the drone to make sure it isn't in the way of placing a block.
                        entity.setPosition(entity.posX, entity.posY + 200, entity.posZ);
                    }
                    if (drone.getWorld().canPlaceEntityOnSide(((ItemBlock) droneStack.getItem()).field_150939_a, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, false, 0, null, droneStack)) {
                        Block block = Block.getBlockFromItem(droneStack.getItem());
                        int meta = droneStack.getItem().getMetadata(droneStack.getItemDamage());
                        int newMeta = block.onBlockPlaced(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), side.offsetX, side.offsetY, side.offsetZ, meta);
                        setFakePlayerAccordingToDir();
                        if (placeBlockAt(droneStack, drone.getFakePlayer(), drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), 0, 0, 0, newMeta)) {
                            drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
                            drone.getWorld().playSoundEffect(pos.chunkPosX + 0.5F, pos.chunkPosY + 0.5F, pos.chunkPosZ + 0.5F, block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
                            if (--droneStack.stackSize <= 0) {
                                drone.getInventory().setInventorySlotContents(i, null);
                            }
                        }
                        if (drone instanceof EntityDrone) {
                            EntityDrone entity = (EntityDrone) drone;
                            entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                        }
                        return false;
                    }
                    if (drone instanceof EntityDrone) {
                        EntityDrone entity = (EntityDrone) drone;
                        entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
                    }
                }
            }
        }
        return false;
    } else {
        return true;
    }
}
Also used : ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

ISidedWidget (pneumaticCraft.common.progwidgets.ISidedWidget)4 ItemStack (net.minecraft.item.ItemStack)3 IInventory (net.minecraft.inventory.IInventory)2 ICountWidget (pneumaticCraft.common.progwidgets.ICountWidget)2 Block (net.minecraft.block.Block)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 ItemBlock (net.minecraft.item.ItemBlock)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 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)1 ICondition (pneumaticCraft.common.progwidgets.ICondition)1