Search in sources :

Example 1 with IGuiDrone

use of pneumaticCraft.client.gui.IGuiDrone 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)

Aggregations

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