/** * Get a ChatComponent for this Item's display name that shows this Item on hover */ public ITextComponent getTextComponent() { TextComponentString textcomponentstring = new TextComponentString(this.getDisplayName()); if (this.hasDisplayName()) { textcomponentstring.getStyle().setItalic(Boolean.valueOf(true)); } ITextComponent itextcomponent = (new TextComponentString("[")).appendSibling(textcomponentstring).appendText("]"); if (!this.field_190928_g) { NBTTagCompound nbttagcompound = this.writeToNBT(new NBTTagCompound()); itextcomponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new TextComponentString(nbttagcompound.toString()))); itextcomponent.getStyle().setColor(this.getRarity().rarityColor); } return itextcomponent; }
/** * Get a ChatComponent for this Item's display name that shows this Item on hover */ public ITextComponent getTextComponent() { TextComponentString textcomponentstring = new TextComponentString(this.getDisplayName()); if (this.hasDisplayName()) { textcomponentstring.getStyle().setItalic(Boolean.valueOf(true)); } ITextComponent itextcomponent = (new TextComponentString("[")).appendSibling(textcomponentstring).appendText("]"); if (this.item != null) { NBTTagCompound nbttagcompound = this.writeToNBT(new NBTTagCompound()); itextcomponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new TextComponentString(nbttagcompound.toString()))); itextcomponent.getStyle().setColor(this.getRarity().rarityColor); } return itextcomponent; }
private boolean tryParsePlaceMessage(ITextComponent msg) { List<ITextComponent> siblings = msg.getSiblings(); if (siblings.size() <= 0) return false; ITextComponent hoverComponent = siblings.get(0); HoverEvent hover = hoverComponent.getStyle().getHoverEvent(); if (hover != null) { String text = hover.getValue().getUnformattedComponentText(); Snitch snitch = parseSnitchFromChat(text); if (snitch != null) { manager.submitSnitch(snitch); return true; } } return false; }
/** * Appends a string with the specified color(s) and an event * triggered on text click and on text hover. Only one actual * color should be specified, any other {@code TextFormatting} * type should be styling. (Bold, Italic, Underline, Strikethrough, * and Obfuscated) * * @param text The string being appended * @param clickEvent Click event to be used * @param hoverEvent Hover event to be used * @param colors Color formatting * @return This builder */ public final ChatBuilder append(String text, @Nullable ClickEvent clickEvent, @Nullable HoverEvent hoverEvent, TextFormatting... colors) { TextComponentString component = new TextComponentString(text); Style style = component.getStyle(); Arrays.stream(colors).forEach(color -> { switch (color) { case BOLD: { style.setBold(true); break; } case ITALIC: { style.setItalic(true); break; } case UNDERLINE: { style.setUnderlined(true); break; } case STRIKETHROUGH: { style.setStrikethrough(true); break; } case OBFUSCATED: { style.setObfuscated(true); break; } default: { style.setColor(color); break; } } }); // noinspection ConstantConditions style.setClickEvent(clickEvent).setHoverEvent(hoverEvent); this.component.appendSibling(component); return this; }
public static ITextComponent addHoverText(ITextComponent component, ITextComponent hoverComponent) { Style s = component.getStyle(); s.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); component.setStyle(s); return component; }
protected HoverEvent getHoverEvent() { NBTTagCompound nbttagcompound = new NBTTagCompound(); ResourceLocation resourcelocation = EntityList.func_191301_a(this); nbttagcompound.setString("id", this.getCachedUniqueIdString()); if (resourcelocation != null) { nbttagcompound.setString("type", resourcelocation.toString()); } nbttagcompound.setString("name", this.getName()); return new HoverEvent(HoverEvent.Action.SHOW_ENTITY, new TextComponentString(nbttagcompound.toString())); }
public ITextComponent getStatName() { ITextComponent itextcomponent = this.statName.createCopy(); itextcomponent.getStyle().setColor(TextFormatting.GRAY); itextcomponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ACHIEVEMENT, new TextComponentString(this.statId))); return itextcomponent; }
@Nullable /** * The effective chat hover event. */ public HoverEvent getHoverEvent() { return this.hoverEvent == null ? this.getParent().getHoverEvent() : this.hoverEvent; }
protected HoverEvent getHoverEvent() { NBTTagCompound nbttagcompound = new NBTTagCompound(); String s = EntityList.getEntityString(this); nbttagcompound.setString("id", this.getCachedUniqueIdString()); if (s != null) { nbttagcompound.setString("type", s); } nbttagcompound.setString("name", this.getName()); return new HoverEvent(HoverEvent.Action.SHOW_ENTITY, new TextComponentString(nbttagcompound.toString())); }
private ITextComponent parseHover(SnitchAlert alert) { try { //If we are parsing a hover then the current index is for the hover instruction //That means that we have 2 parts: 1-TEXT YOU SEE IN CHAT, 2-TEXT THAT YOU SEE WHEN YOU HOVER //Either of those 2 could be a string substitution or a variable instruction String text; //Move index to the first instruction part (text to show in chat) index++; String showText = getTextForCurrentInstruction(alert); //Move index to second instruction part (text shown on hover) index++; String hoverText = getTextForCurrentInstruction(alert); index++; HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(hoverText)); ITextComponent hoverComponent = new TextComponentString(showText).setStyle(new Style().setColor(TextFormatting.AQUA).setHoverEvent(hoverEvent)); index--;//???? return hoverComponent; } catch (Exception e) { return null; } }
/** * Send record message to the player */ private void sendRecordMessage() { EntityPlayer player = this.mc.thePlayer; if (this.filename.getText().isEmpty()) { L10n.error(player, "recording.fill_filename"); return; } String command = "/action record " + this.filename.getText() + " " + this.pos.getX() + " " + this.pos.getY() + " " + this.pos.getZ(); ITextComponent component = new TextComponentString(stringClickhere); component.getStyle().setClickEvent(new ClickEvent(Action.RUN_COMMAND, command)); component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(command))); component.getStyle().setColor(TextFormatting.GRAY).setUnderlined(true); L10n.info(player, "recording.message", this.filename.getText(), component); /* Add the command to the history */ List<String> messages = this.mc.ingameGUI.getChatGUI().getSentMessages(); boolean empty = messages.isEmpty(); boolean lastMessageIsntCommand = !empty && !messages.get(messages.size() - 1).equals(command); if (lastMessageIsntCommand || empty) { messages.add(command); } }
@SubscribeEvent public static void playerDeath(LivingDeathEvent event) { if (event.getEntityLiving() instanceof EntityPlayer && printDeathCoords) { TextComponentString posText = new TextComponentString("X: " + MathHelper.floor(event.getEntityLiving().posX) + " Y: " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " Z: " + MathHelper.floor(event.getEntityLiving().posZ)); try { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); if (server.getCommandManager().getPossibleCommands(event.getEntityLiving()).contains(server.getCommandManager().getCommands().get("tp"))) { posText.setStyle(new Style().setItalic(true) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to teleport!"))) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tp " + MathHelper.floor(event.getEntityLiving().posX) + " " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " " + MathHelper.floor(event.getEntityLiving().posZ)))); } if (server.getCommandManager().getPossibleCommands(event.getEntityLiving()).contains(server.getCommandManager().getCommands().get("tpx"))) { posText.setStyle(new Style().setItalic(true) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to teleport!"))) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpx " + ((EntityPlayer) event.getEntityLiving()).dimension + " " + MathHelper.floor(event.getEntityLiving().posX) + " " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " " + MathHelper.floor(event.getEntityLiving().posZ)))); } } catch (Exception ignored) { } event.getEntityLiving().sendMessage(new TextComponentString("You died at ").setStyle(new Style().setColor(TextFormatting.AQUA)).appendSibling(posText)); } }
@Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); if (!orderPressed || isSure) { for (TextFieldDetails field : this.fields) { if (loginMode) { if (field.getId() < 2) { field.drawTextBox(); } } else { field.drawTextBox(); } } if (loginMode) { if (loggingIn) { this.drawCenteredString(fontRendererObj, Util.localize("details.login"), this.width / 2, (this.height / 2) - 20, 0xFFFFFF); } else if (!loggingInError.isEmpty()) { this.drawCenteredString(fontRendererObj, Util.localize("details.loginerror") + loggingInError, this.width / 2, (this.height / 2) - 20, 0xFFFFFF); } else if (loggedIn) { this.drawCenteredString(fontRendererObj, Util.localize("details.loginsuccess"), this.width / 2, (this.height / 2) - 20, 0xFFFFFF); } else { this.drawCenteredString(fontRendererObj, Util.localize("details.accountexists"), this.width / 2, (this.height / 2) - 20, 0xFFFFFF); } } } else { int info2Start = (this.height / 2) - 50; this.drawCenteredString(fontRendererObj, Util.localize("order.info1"), this.width / 2, (this.height / 2) - 60, 0xFFFFFF); this.drawCenteredString(fontRendererObj, info2.getFormattedText(), this.width / 2, (this.height / 2) - 50, 0xFFFFFF); this.drawCenteredString(fontRendererObj, Util.localize("order.info3"), this.width / 2, (this.height / 2) - 30, 0xFFFFFF); this.drawCenteredString(fontRendererObj, Util.localize("order.info4"), this.width / 2, (this.height / 2) - 20, 0xFFFFFF); if (mouseY >= info2Start && mouseY <= info2Start + fontRendererObj.FONT_HEIGHT) { ITextComponent component = getComponent(mouseX, mouseY); if (component != null) { HoverEvent event = component.getStyle().getHoverEvent(); if (event != null) if (event.getAction() == HoverEvent.Action.SHOW_TEXT) this.drawHoveringText(Splitter.on("\n").splitToList(event.getValue().getFormattedText()), mouseX, mouseY); } } } }
@Nullable public HoverEvent getHoverEvent() { return null; }
public Style setHoverEvent(HoverEvent event) { throw new UnsupportedOperationException(); }
/** * Sets the event that should be run when text of this ChatStyle is hovered over. */ public Style setHoverEvent(HoverEvent event) { this.hoverEvent = event; return this; }
/** * The effective chat hover event. */ @Nullable public HoverEvent getHoverEvent() { return null; }
/** * Sets the event that should be run when text of this ChatStyle is hovered over. */ public Style setHoverEvent(HoverEvent event) { throw new UnsupportedOperationException(); }
/** * The effective chat hover event. */ @Nullable public HoverEvent getHoverEvent() { return this.hoverEvent == null ? this.getParent().getHoverEvent() : this.hoverEvent; }
private boolean tryParseNameChangeMessage(ITextComponent msg) { List<ITextComponent> siblings = msg.getSiblings(); if (siblings.size() <= 0) return false; ITextComponent hoverComponent = siblings.get(0); HoverEvent hover = hoverComponent.getStyle().getHoverEvent(); if (hover != null) { String text = hover.getValue().getUnformattedComponentText(); try { String[] args = text.split("\n"); String[] worldArgs = args[0].split(" "); String[] locationArgs = args[1].split(":")[1].split(" "); String newName = args[6].trim(); int x, y, z; x = Integer.parseInt(locationArgs[1].substring(1)); y = Integer.parseInt(locationArgs[2]); z = Integer.parseInt(locationArgs[3].substring(0, locationArgs[3].length() - 1)); String world = worldArgs.length > 1 ? worldArgs[1] : snitchMaster.getCurrentWorld(); Location loc = new Location(x, y, z, world); Snitch snitch = manager.getSnitches().get(loc); if(snitch != null) { snitch.setSnitchName(newName); snitchMaster.individualJourneyMapUpdate(snitch); return true; } } catch (Exception e) { return false; } } return false; }
@SubscribeEvent @SideOnly(Side.CLIENT) public void onTick(TickEvent.ClientTickEvent event) { EntityPlayer player = Minecraft.getMinecraft().player; if (!ConfigValues.versionCheckerEnabled) return; if (doneChecking && event.phase == TickEvent.Phase.END && player != null && !triedToWarnPlayer) { ITextComponent component = new TextComponentString("[").setStyle(new Style().setColor(TextFormatting.GREEN)) .appendSibling(new TextComponentTranslation("wizardry.misc.update_link").setStyle(new Style().setColor(TextFormatting.GRAY))) .appendSibling(new TextComponentString("]").setStyle(new Style().setColor(TextFormatting.GREEN))); component.getStyle() .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(updateMessage))) .setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://minecraft.curseforge.com/projects/wizardry-mod/files")); if (onlineVersion != null && !onlineVersion.isEmpty()) { String clientBuild = Wizardry.VERSION; if (Utils.compareVersions(onlineVersion, clientBuild) == 1) { ArrayList<String> messages = new ArrayList<>(); String base = "wizardry.update"; int n = 0; while (LibrarianLib.PROXY.canTranslate(base + n)) messages.add(base + n++); if (messages.isEmpty()) messages.add("wizardry.misc.update_link"); player.sendMessage(new TextComponentTranslation(messages.get(RandUtil.nextInt(messages.size() - 1))).setStyle(new Style().setColor(TextFormatting.YELLOW))); player.sendMessage(new TextComponentTranslation("wizardry.misc.update_checker0") .setStyle(new Style().setColor(TextFormatting.GREEN))); player.sendMessage(new TextComponentTranslation("wizardry.misc.update_checker1") .setStyle(new Style().setColor(TextFormatting.GREEN)) .appendSibling(new TextComponentString(clientBuild).setStyle(new Style().setColor(TextFormatting.RED)))); player.sendMessage(new TextComponentTranslation("wizardry.misc.update_checker2") .setStyle(new Style().setColor(TextFormatting.GREEN)) .appendSibling(new TextComponentString(onlineVersion).setStyle(new Style().setColor(TextFormatting.YELLOW)))); if (updateMessage != null && !updateMessage.isEmpty()) player.sendMessage(component); } else if (updateMessage != null && !updateMessage.isEmpty()) player.sendMessage(component); } triedToWarnPlayer = true; } }
@Override protected HoverEvent getHoverEvent() { return getSettler().getHoverEvent(); }
@Override public HoverEvent getHoverEvent() { return super.getHoverEvent(); }
public ComponentImage(String location, int u, int v, int width, int height, int viewportWidth, int viewportHeight, HoverEvent hoverEvent, ClickEvent clickEvent) { this.fontRenderer = Minecraft.getMinecraft().fontRendererObj; this.textureManager = Minecraft.getMinecraft().getTextureManager(); this.location = new ResourceLocation(location); BufferedImage theImage; try { theImage = ImageIO.read( Minecraft.getMinecraft().getResourceManager().getResource(this.location).getInputStream()); if (width <= 0) width = theImage.getWidth(); if (height <= 0) height = theImage.getHeight(); } catch (IOException e) { theImage = null; } this.theImage = theImage; if (u + width >= theImage.getWidth()) { u = 0; width = theImage.getWidth(); } if (v + height >= theImage.getHeight()) { v = 0; height = theImage.getHeight(); } if (viewportWidth == 0) viewportWidth = width; if (viewportHeight == 0) viewportHeight = height; this.u = u; this.v = v; this.width = width; this.height = height; this.viewportWidth = viewportWidth; this.viewportHeight = viewportHeight; this.hoverEvent = hoverEvent; this.clickEvent = clickEvent; }
@Override public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return; } // Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :( StringBuilder outputRaw = new StringBuilder(String.format("\u00A77%1$4d,%2$4d,%3$4d\u00A7r ", pos.getX(), pos.getY(), pos.getZ())); // Check if the clicked on block has the IGrowable interface. final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null); if (crop == null) { // If it does not, add a nicely formatted report, then skip onward. outputRaw.append(chatNotIG); } else { // Otherwise run the tests and record the results. IBlockState state = world.getBlockState(pos); outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse); // canGrow outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse); // canUseBonemeal crop.grow(world, world.rand, pos, state); // grow // It's also helpful to also make clear what block was being tested. outputRaw.append("\u00A73"); // '3' is dark aqua. outputRaw.append(crop.toString().replaceFirst("Block","")); outputRaw.append("\u00A7r"); } // Ellipsis are added as a clue that there's more text. outputRaw.append(" \u00A78[...]\u00A7r"); // '8' is dark gray. // Create a hover box with explanatory information. TextComponentString hoverComponent = new TextComponentString(chatInfo); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent); // Turn the output String into a chat message. TextComponentString outputComponent = new TextComponentString(outputRaw.toString()); // Add the hover box to the chat message. outputComponent.getStyle().setHoverEvent(hoverEvent); // Now send the completed chat message. player.sendMessage(outputComponent); }
@Override public ITextBuilder hover(HoverEvent event) { checkCreated(); current.getStyle().setHoverEvent(event); return this; }
/** * Appends a string with the specified color(s) * and an event triggered on text hover. * * @param text The string being appended * @param hoverEvent Hover event to be used * @param colors Color formatting * @return This builder */ public final ChatBuilder append(String text, HoverEvent hoverEvent, TextFormatting... colors) { this.append(text, null, hoverEvent, colors); return this; }
ITextBuilder hover(HoverEvent event);