下面列出了net.minecraft.util.ChatStyle#net.minecraft.event.HoverEvent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
return;
final ChatStyle chatStyle = component.getChatStyle();
final ClickEvent clickEvent = chatStyle.getChatClickEvent();
final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();
drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
return;
final ChatStyle chatStyle = component.getChatStyle();
final ClickEvent clickEvent = chatStyle.getChatClickEvent();
final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();
drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
public void sendMessage(String message, String hover, String click) {
ChatComponentText chatComponent = new ChatComponentText(ChatColor.YELLOW + message);
if (hover != null && !hover.isEmpty()) {
chatComponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ChatComponentText(ChatColor.AQUA + hover + (!click.isEmpty() ? "\n" + click : ""))));
}
if (click != null && !click.isEmpty()) {
chatComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, click));
}
Minecraft.getMinecraft().thePlayer.addChatComponentMessage(chatComponent);
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if(args.length <= 0) {
TickScheduler.INSTANCE.schedule(1, () -> FMLClientHandler.instance().getClient().displayGuiScreen(new GuiMediaModSettings()));
} else {
String subcommand = args[0];
if(subcommand.equalsIgnoreCase("party")) {
if(args.length >= 2) {
String function = args[1];
if(function.equalsIgnoreCase("start")) {
if(!MediaMod.INSTANCE.partyManager.canStartParty()) {
PlayerMessager.sendMessage(ChatColor.RED + "You are already in a party!", true);
return;
}
PlayerMessager.sendMessage(ChatColor.GRAY + "Creating MediaMod Party... " + "(note: this only works with spotify at the moment)", true);
String code = MediaMod.INSTANCE.partyManager.startParty();
if(code.equals("")) {
PlayerMessager.sendMessage(ChatColor.RED + "An error occurred whilst creating your MediaMod party!", true);
} else {
IChatComponent urlComponent = new ChatComponentText(ChatColor.WHITE + "" + ChatColor.BOLD + code);
urlComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, code));
urlComponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText("Copy Code")));
PlayerMessager.sendMessage(new ChatComponentText(ChatColor.GRAY + "Share this code with your friends to invite them to your party: ").appendSibling(urlComponent), true);
}
} else if (function.equalsIgnoreCase("leave")) {
if(!MediaMod.INSTANCE.partyManager.canStartParty()) {
boolean success = MediaMod.INSTANCE.partyManager.leaveParty();
if(success) {
PlayerMessager.sendMessage((ChatColor.GRAY + "You have left the party"), true);
} else {
PlayerMessager.sendMessage(ChatColor.RED + "An error occurred whilst trying to leave the party!", true);
}
} else {
PlayerMessager.sendMessage(ChatColor.RED + "You are not in a party!");
}
}
} else {
PlayerMessager.sendMessage(ChatColor.RED + "Incorrect syntax! Usage: /mm party <start/invite/info/join/leave>");
}
}
}
}
/**
* @author Sk1er
*/
@Inject(method = "setChatHoverEvent", at = @At("HEAD"))
private void setChatHoverEvent(HoverEvent boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
hyperiumChatStyle.resetCache();
}
/**
* Draws the screen and all the components in it.
*/
@SuppressWarnings("unchecked")
@Override
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
drawRect(2, this.height - 14, this.width - 2, this.height - 2, Integer.MIN_VALUE);
if (this.inputField.getText().length() == 0) {
this.inputField.setText("/");
}
if (this.inputField.getText().charAt(0) != '/') {
this.inputField.setText("/" + this.inputField.getText());
}
this.inputField.drawTextBox();
IChatComponent ichatcomponent = EHacksGui.clickGui.consoleGui.getChatComponent(Mouse.getX(), Mouse.getY());
if (ichatcomponent != null && ichatcomponent.getChatStyle().getChatHoverEvent() != null) {
HoverEvent hoverevent = ichatcomponent.getChatStyle().getChatHoverEvent();
if (null != hoverevent.getAction()) {
switch (hoverevent.getAction()) {
case SHOW_ITEM:
ItemStack itemstack = null;
try {
NBTBase nbtbase = JsonToNBT.func_150315_a(hoverevent.getValue().getUnformattedText());
if (nbtbase instanceof NBTTagCompound) {
itemstack = ItemStack.loadItemStackFromNBT((NBTTagCompound) nbtbase);
}
} catch (NBTException ignored) {
}
if (itemstack != null) {
this.renderToolTip(itemstack, p_73863_1_, p_73863_2_);
} else {
this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid Item!", p_73863_1_, p_73863_2_);
}
break;
case SHOW_TEXT:
this.func_146283_a(Splitter.on("\n").splitToList(hoverevent.getValue().getFormattedText()), p_73863_1_, p_73863_2_);
break;
case SHOW_ACHIEVEMENT:
StatBase statbase = StatList.func_151177_a(hoverevent.getValue().getUnformattedText());
if (statbase != null) {
IChatComponent ichatcomponent1 = statbase.func_150951_e();
ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("stats.tooltip.type." + (statbase.isAchievement() ? "achievement" : "statistic"));
chatcomponenttranslation.getChatStyle().setItalic(Boolean.TRUE);
String s = statbase instanceof Achievement ? ((Achievement) statbase).getDescription() : null;
ArrayList<String> arraylist = Lists.newArrayList(ichatcomponent1.getFormattedText(), chatcomponenttranslation.getFormattedText());
if (s != null) {
arraylist.addAll(this.fontRendererObj.listFormattedStringToWidth(s, 150));
}
this.func_146283_a(arraylist, p_73863_1_, p_73863_2_);
} else {
this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid statistic/achievement!", p_73863_1_, p_73863_2_);
}
break;
default:
break;
}
}
GL11.glDisable(GL11.GL_LIGHTING);
}
super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
}
@Invoker HoverEvent callGetHoverEvent();