Search in sources :

Example 6 with IChatComponent

use of net.minecraft.util.IChatComponent in project PneumaticCraft by MineMaarten.

the class ItemManometer method onItemUseFirst.

/**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
@Override
public boolean onItemUseFirst(ItemStack iStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
    if (world.isRemote)
        return false;
    if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
        TileEntity te = world.getTileEntity(x, y, z);
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        List<IChatComponent> curInfo = new ArrayList<IChatComponent>();
        List<String> info = new ArrayList<String>();
        if (te instanceof IManoMeasurable) {
            ((IManoMeasurable) te).printManometerMessage(player, info);
        } else if (machine != null) {
            machine.getAirHandler().printManometerMessage(player, info);
        }
        for (String s : info) curInfo.add(new ChatComponentTranslation(s));
        if (te instanceof IHeatExchanger) {
            IHeatExchangerLogic exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(ForgeDirection.getOrientation(side));
            if (exchanger != null) {
                curInfo.add(new ChatComponentTranslation("waila.temperature", (int) exchanger.getTemperature() - 273));
            } else {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                    if (exchanger != null) {
                        curInfo.add(new ChatComponentTranslation("waila.temperature." + d.toString().toLowerCase(), (int) exchanger.getTemperature() - 273));
                    }
                }
            }
        }
        if (curInfo.size() > 0) {
            ((IPressurizable) iStack.getItem()).addAir(iStack, -30);
            for (IChatComponent s : curInfo) {
                player.addChatComponentMessage(s);
            }
            return true;
        }
    } else {
        player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
        return false;
    }
    return false;
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) IManoMeasurable(pneumaticCraft.api.tileentity.IManoMeasurable) ArrayList(java.util.ArrayList) TileEntity(net.minecraft.tileentity.TileEntity) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IChatComponent(net.minecraft.util.IChatComponent) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 7 with IChatComponent

use of net.minecraft.util.IChatComponent in project watson by totemo.

the class WatsonCommand method help.

// handleConfigCommand
// --------------------------------------------------------------------------
/**
   * Show a help message.
   */
public void help(ICommandSender sender) {
    String w = Configuration.instance.getWatsonPrefix();
    localOutput(sender, "Usage:");
    localOutput(sender, "  /" + w + " help");
    localOutput(sender, "  /" + w + " display [on|off]");
    localOutput(sender, "  /" + w + " outline [on|off]");
    localOutput(sender, "  /" + w + " anno [on|off]");
    localOutput(sender, "  /" + w + " vector [on|off]");
    localOutput(sender, "  /" + w + " vector (creations|destructions) [on|off]");
    localOutput(sender, "  /" + w + " vector length <decimal>");
    localOutput(sender, "  /" + w + " label [on|off]");
    localOutput(sender, "  /" + w + " clear");
    localOutput(sender, "  /" + w + " pre [<count>]");
    localOutput(sender, "  /" + w + " post [<count>]");
    localOutput(sender, "  /" + w + " ore [<page>]");
    localOutput(sender, "  /" + w + " ratio");
    localOutput(sender, "  /" + w + " tp [next|prev|<number>]");
    localOutput(sender, "  /" + w + " edits [list]");
    localOutput(sender, "  /" + w + " edits (hide|show|remove) <player> ...");
    localOutput(sender, "  /" + w + " filter [list|clear]");
    localOutput(sender, "  /" + w + " filter (add|remove) <player> ...");
    localOutput(sender, "  /" + w + " servertime");
    localOutput(sender, "  /" + w + " file list [*|<playername>] [<page>]");
    localOutput(sender, "  /" + w + " file delete *|<filename>|<playername>");
    localOutput(sender, "  /" + w + " file expire <YYYY-MM-DD>");
    localOutput(sender, "  /" + w + " file load <filename>|<playername>");
    localOutput(sender, "  /" + w + " file save [<filename>]");
    localOutput(sender, "  /" + w + " config <name> [<value>]");
    localOutput(sender, "  /hl help");
    localOutput(sender, "  /anno help");
    // Make the documentation link clickable.
    IChatComponent docs = new ChatComponentText("Documentation: ");
    ChatStyle style = new ChatStyle().setColor(EnumChatFormatting.AQUA);
    docs.setChatStyle(style);
    String url = "http://github.com/totemo/watson";
    IChatComponent link = new ChatComponentText(url);
    ChatStyle linkStyle = new ChatStyle();
    linkStyle.setUnderlined(true);
    link.setChatStyle(linkStyle);
    linkStyle.setChatClickEvent(new ClickEvent(Action.OPEN_URL, url));
    docs.appendSibling(link);
    sender.addChatMessage(docs);
    if (!Configuration.instance.isEnabled()) {
        localOutput(sender, "Watson is currently disabled.");
        localOutput(sender, "To re-enable, use: /" + w + " config watson on");
    }
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 8 with IChatComponent

use of net.minecraft.util.IChatComponent in project watson by totemo.

the class ChatHighlighter method highlight.

// --------------------------------------------------------------------------
/**
   * Highlight the text in a chat component.
   * 
   * @param chat the text to highlight.
   * @return highlighted text.
   */
public IChatComponent highlight(IChatComponent chat) {
    if (isReisLikeCode(chat.getFormattedText())) {
        return chat;
    } else {
        ArrayList<IChatComponent> resultComponents = new ArrayList<IChatComponent>();
        ArrayList<IChatComponent> components = ChatComponents.getComponents(chat);
        while (!components.isEmpty()) {
            IChatComponent head = components.remove(0);
            if (ChatComponents.hasEvents(head)) {
                // Can't currently highlight links etc.
                resultComponents.add(head);
            } else {
                // Collect all consecutive components that don't have events
                // and therefore can be highlighted.
                ArrayList<IChatComponent> highlightableComps = new ArrayList<IChatComponent>();
                highlightableComps.add(head);
                while (!components.isEmpty()) {
                    IChatComponent next = components.get(0);
                    if (ChatComponents.hasEvents(next)) {
                        break;
                    } else {
                        highlightableComps.add(next);
                        components.remove(0);
                    }
                }
                // while
                IChatComponent highlightable = ChatComponents.toChatComponent(highlightableComps);
                String highlightableText = highlightable.getFormattedText();
                Text highlighted = highlight(highlightableText);
                resultComponents.add(highlighted.toChatComponent());
            }
        }
        // while there are components to consider
        return ChatComponents.toChatComponent(resultComponents);
    }
}
Also used : ArrayList(java.util.ArrayList) IChatComponent(net.minecraft.util.IChatComponent)

Example 9 with IChatComponent

use of net.minecraft.util.IChatComponent in project watson by totemo.

the class ChatComponents method dump.

// --------------------------------------------------------------------------
/**
   * Dump information about the IChatComponent to standard output.
   * 
   * @patam component the component.
   */
public static void dump(ArrayList<IChatComponent> components) {
    System.out.println("Dump: " + toChatComponent(components).getFormattedText());
    for (int i = 0; i < components.size(); ++i) {
        IChatComponent c = components.get(i);
        System.out.println(i + ": " + hasEvents(c) + ": \"" + c.getFormattedText() + "\" " + c.getUnformattedTextForChat().length() + " " + c.getChatStyle().isEmpty() + " " + c.getChatStyle().toString());
    }
}
Also used : IChatComponent(net.minecraft.util.IChatComponent)

Aggregations

IChatComponent (net.minecraft.util.IChatComponent)9 ArrayList (java.util.ArrayList)4 ChatComponentText (net.minecraft.util.ChatComponentText)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)2 ChatStyle (net.minecraft.util.ChatStyle)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ClickEvent (net.minecraft.event.ClickEvent)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumChatFormatting (net.minecraft.util.EnumChatFormatting)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)1 IPressurizable (pneumaticCraft.api.item.IPressurizable)1 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)1 IManoMeasurable (pneumaticCraft.api.tileentity.IManoMeasurable)1 IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)1