Search in sources :

Example 1 with IProgrammable

use of me.desht.pneumaticcraft.api.item.IProgrammable in project pnc-repressurized by TeamPneumatic.

the class DroneAIExternalProgram method doBlockInteraction.

@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
    IItemHandler inv = IOHelper.getInventoryForTE(drone.world().getTileEntity(pos));
    if (inv == null)
        return false;
    if (curProgramTag != null) {
        if (curSlot < inv.getSlots()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (curProgramTag.equals(stack.getTagCompound())) {
                subAI.onUpdateTasks();
                if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
                    curProgramTag = null;
                    curSlot++;
                }
            } else {
                curProgramTag = null;
                subAI.setWidgets(new ArrayList<>());
            }
        }
        return true;
    } else {
        while (curSlot < inv.getSlots()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack.getItem() instanceof IProgrammable) {
                IProgrammable programmable = (IProgrammable) stack.getItem();
                if (programmable.canProgram(stack) && programmable.usesPieces(stack)) {
                    List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(stack);
                    boolean areWidgetsValid = true;
                    for (IProgWidget widget : widgets) {
                        if (!drone.isProgramApplicable(widget)) {
                            areWidgetsValid = false;
                            break;
                        }
                    }
                    if (areWidgetsValid) {
                        if (widget.shareVariables)
                            mainAI.connectVariables(subAI);
                        subAI.getDrone().getAIManager().setLabel("Main");
                        subAI.setWidgets(widgets);
                        curProgramTag = stack.getTagCompound();
                        if (!subAI.isIdling()) {
                            return true;
                        }
                    }
                }
            }
            curSlot++;
        }
        return false;
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) IItemHandler(net.minecraftforge.items.IItemHandler) IProgrammable(me.desht.pneumaticcraft.api.item.IProgrammable) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IProgrammable

use of me.desht.pneumaticcraft.api.item.IProgrammable in project pnc-repressurized by TeamPneumatic.

the class ClientEventHandler method handleProgrammableTooltip.

private void handleProgrammableTooltip(ItemTooltipEvent event) {
    IProgrammable programmable = (IProgrammable) event.getItemStack().getItem();
    if (programmable.canProgram(event.getItemStack()) && programmable.showProgramTooltip()) {
        boolean hasInvalidPrograms = false;
        List<String> addedEntries = new ArrayList<>();
        List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(event.getItemStack());
        Map<String, Integer> widgetMap = getPuzzleSummary(widgets);
        for (Map.Entry<String, Integer> entry : widgetMap.entrySet()) {
            IProgWidget widget = ItemProgrammingPuzzle.getWidgetForName(entry.getKey());
            String prefix = "";
            GuiScreen curScreen = Minecraft.getMinecraft().currentScreen;
            if (curScreen instanceof IGuiDrone) {
                if (!((IGuiDrone) curScreen).getDrone().isProgramApplicable(widget)) {
                    prefix = TextFormatting.RED + "";
                    hasInvalidPrograms = true;
                }
            }
            addedEntries.add(prefix + "- " + entry.getValue() + "x " + I18n.format("programmingPuzzle." + entry.getKey() + ".name"));
        }
        if (hasInvalidPrograms) {
            event.getToolTip().add(TextFormatting.RED + I18n.format("gui.tooltip.programmable.invalidPieces"));
        }
        Collections.sort(addedEntries);
        event.getToolTip().addAll(addedEntries);
        if (PneumaticCraftRepressurized.proxy.isSneakingInGui() && !widgets.isEmpty()) {
            Map<Integer, Integer> widgetColorMap = TileEntityProgrammer.getPuzzleSummary(widgets);
            event.getToolTip().add(TextFormatting.WHITE + I18n.format("gui.tooltip.programmable.requiredPieces"));
            for (int color : widgetColorMap.keySet()) {
                ItemStack stack = ItemProgrammingPuzzle.getStackForColor(color);
                stack.setCount(widgetColorMap.get(color));
                event.getToolTip().add("- " + widgetColorMap.get(color) + " x " + stack.getDisplayName());
            }
        }
    }
}
Also used : IProgrammable(me.desht.pneumaticcraft.api.item.IProgrammable) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) IGuiDrone(me.desht.pneumaticcraft.client.gui.IGuiDrone) GuiScreen(net.minecraft.client.gui.GuiScreen) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IProgrammable (me.desht.pneumaticcraft.api.item.IProgrammable)2 IProgWidget (me.desht.pneumaticcraft.common.progwidgets.IProgWidget)2 ItemStack (net.minecraft.item.ItemStack)2 IGuiDrone (me.desht.pneumaticcraft.client.gui.IGuiDrone)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 IItemHandler (net.minecraftforge.items.IItemHandler)1