Search in sources :

Example 1 with IProgrammable

use of pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.

the class DroneAIExternalProgram method doBlockInteraction.

@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv == null)
        return false;
    if (curProgramTag != null) {
        if (curSlot < inv.getSizeInventory()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack != null && curProgramTag.equals(stack.getTagCompound())) {
                subAI.onUpdateTasks();
                if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
                    curProgramTag = null;
                    curSlot++;
                }
            } else {
                curProgramTag = null;
                subAI.setWidgets(new ArrayList<IProgWidget>());
            }
        }
        return true;
    } else {
        while (curSlot < inv.getSizeInventory()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack != null && 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 : IInventory(net.minecraft.inventory.IInventory) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) IProgrammable(pneumaticCraft.api.item.IProgrammable) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IProgrammable

use of pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammer method getReturnedPuzzleStacks.

public List<ItemStack> getReturnedPuzzleStacks() {
    List<ItemStack> stacks = new ArrayList<ItemStack>();
    if (((IProgrammable) inventory[PROGRAM_SLOT].getItem()).usesPieces(inventory[PROGRAM_SLOT])) {
        Map<Integer, Integer> tePieces = getPuzzleSummary(progWidgets);
        Map<Integer, Integer> dronePieces = getPuzzleSummary(getProgWidgets(inventory[PROGRAM_SLOT]));
        for (Integer availableWidget : dronePieces.keySet()) {
            Integer requiredWidget = tePieces.get(availableWidget);
            if (requiredWidget != null) {
                Integer availableWidgets = dronePieces.get(availableWidget);
                if (availableWidgets > requiredWidget) {
                    ItemStack stack = ItemProgrammingPuzzle.getStackForColor(availableWidget);
                    stack.stackSize = (availableWidgets - requiredWidget) * inventory[PROGRAM_SLOT].stackSize;
                    while (stack.stackSize > stack.getMaxStackSize()) {
                        stacks.add(stack.splitStack(stack.getMaxStackSize()));
                    }
                    stacks.add(stack);
                }
            } else {
                ItemStack stack = ItemProgrammingPuzzle.getStackForColor(availableWidget);
                stack.stackSize = dronePieces.get(availableWidget) * inventory[PROGRAM_SLOT].stackSize;
                while (stack.stackSize > stack.getMaxStackSize()) {
                    stacks.add(stack.splitStack(stack.getMaxStackSize()));
                }
                stacks.add(stack);
            }
        }
    }
    return stacks;
}
Also used : IProgrammable(pneumaticCraft.api.item.IProgrammable) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IProgrammable

use of pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.

the class ClientEventHandler method onItemTooltip.

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    if (event.itemStack.getItem() instanceof IProgrammable) {
        IProgrammable programmable = (IProgrammable) event.itemStack.getItem();
        if (programmable.canProgram(event.itemStack) && programmable.showProgramTooltip()) {
            boolean hasInvalidPrograms = false;
            List<String> addedEntries = new ArrayList<String>();
            Map<String, Integer> widgetMap = getPuzzleSummary(TileEntityProgrammer.getProgWidgets(event.itemStack));
            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 = EnumChatFormatting.RED + "";
                        hasInvalidPrograms = true;
                    }
                }
                addedEntries.add(prefix + "-" + entry.getValue() + "x " + I18n.format("programmingPuzzle." + entry.getKey() + ".name"));
            }
            if (hasInvalidPrograms) {
                event.toolTip.add(EnumChatFormatting.RED + I18n.format("gui.tooltip.programmable.invalidPieces"));
            }
            Collections.sort(addedEntries);
            event.toolTip.addAll(addedEntries);
        }
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) IProgrammable(pneumaticCraft.api.item.IProgrammable) IGuiDrone(pneumaticCraft.client.gui.IGuiDrone) ArrayList(java.util.ArrayList) GuiScreen(net.minecraft.client.gui.GuiScreen) HashMap(java.util.HashMap) Map(java.util.Map) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with IProgrammable

use of pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammer method getRequiredPuzzleStacks.

public List<ItemStack> getRequiredPuzzleStacks() {
    List<ItemStack> stacks = new ArrayList<ItemStack>();
    if (((IProgrammable) inventory[PROGRAM_SLOT].getItem()).usesPieces(inventory[PROGRAM_SLOT])) {
        Map<Integer, Integer> tePieces = getPuzzleSummary(progWidgets);
        Map<Integer, Integer> dronePieces = getPuzzleSummary(getProgWidgets(inventory[PROGRAM_SLOT]));
        for (Integer includedWidget : tePieces.keySet()) {
            Integer existingWidgets = dronePieces.get(includedWidget);
            if (existingWidgets != null) {
                Integer neededWidgets = tePieces.get(includedWidget);
                if (neededWidgets > existingWidgets) {
                    ItemStack stack = ItemProgrammingPuzzle.getStackForColor(includedWidget);
                    stack.stackSize = (neededWidgets - existingWidgets) * inventory[PROGRAM_SLOT].stackSize;
                    stacks.add(stack);
                }
            } else {
                ItemStack stack = ItemProgrammingPuzzle.getStackForColor(includedWidget);
                stack.stackSize = tePieces.get(includedWidget) * inventory[PROGRAM_SLOT].stackSize;
                stacks.add(stack);
            }
        }
    }
    return stacks;
}
Also used : IProgrammable(pneumaticCraft.api.item.IProgrammable) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IProgrammable (pneumaticCraft.api.item.IProgrammable)4 ArrayList (java.util.ArrayList)3 ItemStack (net.minecraft.item.ItemStack)3 IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 IInventory (net.minecraft.inventory.IInventory)1 IGuiDrone (pneumaticCraft.client.gui.IGuiDrone)1