Search in sources :

Example 21 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project GregTech by GregTechCE.

the class AdvancedTextWidget method withHoverTextTranslate.

public static ITextComponent withHoverTextTranslate(ITextComponent textComponent, String hoverTranslation) {
    Style style = textComponent.getStyle();
    ITextComponent translation = new TextComponentTranslation(hoverTranslation);
    translation.getStyle().setColor(TextFormatting.GRAY);
    style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, translation));
    return textComponent;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent)

Example 22 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project GregTech by GregTechCE.

the class MultiblockWithDisplayBase method addDisplayText.

/**
 * Called serverside to obtain text displayed in GUI
 * each element of list is displayed on new line
 * to use translation, use TextComponentTranslation
 */
protected void addDisplayText(List<ITextComponent> textList) {
    if (!isStructureFormed()) {
        ITextComponent tooltip = new TextComponentTranslation("gregtech.multiblock.invalid_structure.tooltip");
        tooltip.setStyle(new Style().setColor(TextFormatting.GRAY));
        textList.add(new TextComponentTranslation("gregtech.multiblock.invalid_structure").setStyle(new Style().setColor(TextFormatting.RED).setHoverEvent(new HoverEvent(Action.SHOW_TEXT, tooltip))));
    }
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style)

Example 23 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project GregTech by GregTechCE.

the class CoverFluidRegulator method getHoverString.

protected void getHoverString(List<ITextComponent> textList) {
    switch(this.transferMode) {
        case KEEP_EXACT:
            ITextComponent keepComponent = new TextComponentString(getTransferSizeString());
            TextComponentTranslation hoverKeep = new TextComponentTranslation("cover.fluid_regulator.keep_exact", this.keepAmount);
            keepComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverKeep));
            textList.add(keepComponent);
            break;
        case TRANSFER_EXACT:
            ITextComponent supplyComponent = new TextComponentString(getTransferSizeString());
            TextComponentTranslation hoverSupply = new TextComponentTranslation("cover.fluid_regulator.supply_exact", this.supplyAmount);
            supplyComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverSupply));
            textList.add(supplyComponent);
            break;
    }
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 24 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project Bookshelf by Darkhax-Minecraft.

the class CommandHand method hand.

private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
    final OutputType type = context.getArgument("type", OutputType.class);
    final ServerPlayerEntity player = context.getSource().getPlayerOrException();
    final String outputText = type.converter.apply(player.getMainHandItem());
    final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
        return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
    }));
    context.getSource().sendSuccess(component, false);
    return 0;
}
Also used : JsonObject(com.google.gson.JsonObject) VanillaIngredientSerializer(net.minecraftforge.common.crafting.VanillaIngredientSerializer) Serializers(net.darkhax.bookshelf.serialization.Serializers) ClickEvent(net.minecraft.util.text.event.ClickEvent) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) StringTextComponent(net.minecraft.util.text.StringTextComponent) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) CommandContext(com.mojang.brigadier.context.CommandContext) TextFormatting(net.minecraft.util.text.TextFormatting) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) TextComponentUtils(net.minecraft.util.text.TextComponentUtils) HoverEvent(net.minecraft.util.text.event.HoverEvent) StringJoiner(java.util.StringJoiner) ResourceLocation(net.minecraft.util.ResourceLocation) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Commands(net.minecraft.command.Commands) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 25 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project RecurrentComplex by Ivorforce.

the class RCTextStyle method copy.

public static ITextComponent copy(String text) {
    ITextComponent comp = new TextComponentString(text);
    comp.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RecurrentComplex.translations.get("commands.rccopy.suggest")));
    comp.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, text));
    return comp;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent)

Aggregations

HoverEvent (net.minecraft.util.text.event.HoverEvent)30 ClickEvent (net.minecraft.util.text.event.ClickEvent)21 ITextComponent (net.minecraft.util.text.ITextComponent)9 TextComponentString (net.minecraft.util.text.TextComponentString)9 Nonnull (javax.annotation.Nonnull)8 IGrowable (net.minecraft.block.IGrowable)2 Minecraft (net.minecraft.client.Minecraft)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 Style (net.minecraft.util.text.Style)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 JsonObject (com.google.gson.JsonObject)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)1 ivorius.mcopts.commands.parameters (ivorius.mcopts.commands.parameters)1