Search in sources :

Example 6 with HoverEvent

use of net.minecraft.text.HoverEvent in project meteor-client by MeteorDevelopment.

the class ModulesCommand method getModuleText.

private BaseText getModuleText(Module module) {
    // Hover tooltip
    BaseText tooltip = new LiteralText("");
    tooltip.append(new LiteralText(module.title).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");
    tooltip.append(new LiteralText(module.name).formatted(Formatting.GRAY)).append("\n\n");
    tooltip.append(new LiteralText(module.description).formatted(Formatting.WHITE));
    BaseText finalModule = new LiteralText(module.title);
    if (!module.equals(Modules.get().getGroup(module.category).get(Modules.get().getGroup(module.category).size() - 1)))
        finalModule.append(new LiteralText(", ").formatted(Formatting.GRAY));
    finalModule.setStyle(finalModule.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)));
    return finalModule;
}
Also used : BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) LiteralText(net.minecraft.text.LiteralText)

Example 7 with HoverEvent

use of net.minecraft.text.HoverEvent in project Client by MatHax.

the class ChatEncryption method onMessageReceive.

@EventHandler
private void onMessageReceive(ReceiveMessageEvent event) {
    ((ChatHudAccessor) mc.inGameHud.getChatHud()).getVisibleMessages().removeIf((message) -> message.getId() == event.id && event.id != 0);
    ((ChatHudAccessor) mc.inGameHud.getChatHud()).getMessages().removeIf((message) -> message.getId() == event.id && event.id != 0);
    Text message = event.getMessage();
    if (message.getString().endsWith(suffix.get()) && !suffix.get().isEmpty()) {
        String[] msg = message.getString().split(encryptedPrefix);
        try {
            String chat = decrypt(msg[1], customKey.get() ? groupKey.get() : password);
            BaseText prefixOpenBorder = new LiteralText("[");
            prefixOpenBorder.setStyle(prefixOpenBorder.getStyle().withFormatting(Formatting.GRAY));
            BaseText prefix = new LiteralText("Encrypted Chat");
            prefix.setStyle(prefix.getStyle().withColor(MatHax.INSTANCE.MATHAX_COLOR.getPacked()));
            BaseText prefixCloseBorder = new LiteralText("] ");
            prefixCloseBorder.setStyle(prefixCloseBorder.getStyle().withFormatting(Formatting.GRAY));
            BaseText chatText = new LiteralText(msg[0] + chat);
            chatText.setStyle(chatText.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(msg[1]))));
            BaseText chatMessage = new LiteralText("");
            if (Modules.get().get(BetterChat.class).displayPlayerHeads())
                chatMessage.append("  ");
            chatMessage.append(prefixOpenBorder);
            chatMessage.append(prefix);
            chatMessage.append(prefixCloseBorder);
            chatMessage.append(chatText);
            message = chatMessage;
        } catch (Exception exception) {
            message = event.getMessage();
        }
    }
    event.setMessage(message);
}
Also used : BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) LiteralText(net.minecraft.text.LiteralText) BaseText(net.minecraft.text.BaseText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText) EventHandler(mathax.client.eventbus.EventHandler)

Example 8 with HoverEvent

use of net.minecraft.text.HoverEvent in project Client by MatHax.

the class CommandsCommand method getCommandText.

private BaseText getCommandText(Command command) {
    // Hover tooltip
    BaseText tooltip = new LiteralText("");
    tooltip.append(new LiteralText(Utils.nameToTitle(command.getName())).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");
    BaseText aliases = new LiteralText(Config.get().prefix + command.getName());
    if (command.getAliases().size() > 0) {
        aliases.append(", ");
        for (String alias : command.getAliases()) {
            if (alias.isEmpty())
                continue;
            aliases.append(Config.get().prefix + alias);
            if (!alias.equals(command.getAliases().get(command.getAliases().size() - 1)))
                aliases.append(", ");
        }
    }
    tooltip.append(aliases.formatted(Formatting.GRAY)).append("\n\n");
    tooltip.append(new LiteralText(command.getDescription()).formatted(Formatting.WHITE));
    // Text
    BaseText text = new LiteralText(Utils.nameToTitle(command.getName()));
    if (command != Commands.get().getAll().get(Commands.get().getAll().size() - 1))
        text.append(new LiteralText(", ").formatted(Formatting.GRAY));
    text.setStyle(text.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, Config.get().prefix + command.getName())));
    return text;
}
Also used : BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 9 with HoverEvent

use of net.minecraft.text.HoverEvent in project KahzerxMod by otakucraft.

the class ExchangeCommand method register.

public void register(CommandDispatcher<ServerCommandSource> dispatcher, ShopExtension extension) {
    dispatcher.register(literal("exchange").requires(server -> extension.extensionSettings().isEnabled()).then(literal("confirm").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        String sentItem = StringArgumentType.getString(context, "item");
        int count = player.getMainHandStack().getCount();
        int sentCount = IntegerArgumentType.getInteger(context, "count");
        if (!basicVerify(context, player)) {
            return 1;
        }
        if (count != sentCount || !item.getTranslationKey().equals(sentItem)) {
            context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("El stack de tu mano ha cambiado!"), false);
            return 1;
        }
        extension.updateFounds(player, Exchange.getValue(item) * count);
        extension.logExchange(player, item, count);
        player.setStackInHand(Hand.MAIN_HAND, new ItemStack(Items.AIR));
        context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Añadidos ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(Exchange.getValue(item) * count))), false);
        return 1;
    })))).then(literal("abort").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        String sentItem = StringArgumentType.getString(context, "item");
        int count = player.getMainHandStack().getCount();
        int sentCount = IntegerArgumentType.getInteger(context, "count");
        if (count == sentCount || item.getTranslationKey().equals(sentItem)) {
            context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Exchange cancelado!"), false);
        }
        return 1;
    })))).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        int count = player.getMainHandStack().getCount();
        if (!basicVerify(context, player)) {
            return 1;
        }
        context.getSource().sendFeedback(MarkEnum.INFO.appendMessage(String.format("Vas a cambiar %d %s por ", count, item.getName().getString())).append(MarkEnum.OTAKU_COIN.appendMessage(String.format("%d", Exchange.getValue(item) * count))), false);
        context.getSource().sendFeedback(MarkEnum.QUESTION.appendMessage("Confirmar exchange? ").append(new LiteralText("[Sí]").styled(style -> style.withColor(Formatting.GREEN).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange confirm %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("confirmar exchange"))))).append(new LiteralText(" ").styled(style -> style.withColor(Formatting.WHITE))).append(new LiteralText("[No]").styled(style -> style.withColor(Formatting.DARK_RED).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange abort %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("cancelar exchange"))))), false);
        return 1;
    }).then(literal("info").executes(context -> {
        context.getSource().sendFeedback(MarkEnum.OTAKU_COIN.appendMessage("a"), false);
        return 1;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) ShopExtension(com.kahzerx.kahzerxmod.extensions.shopExtension.ShopExtension) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandContext(com.mojang.brigadier.context.CommandContext) MarkEnum(com.kahzerx.kahzerxmod.utils.MarkEnum) Item(net.minecraft.item.Item) Items(net.minecraft.item.Items) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) ItemStack(net.minecraft.item.ItemStack) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Hand(net.minecraft.util.Hand) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) Item(net.minecraft.item.Item) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 10 with HoverEvent

use of net.minecraft.text.HoverEvent in project meteor-client by MeteorDevelopment.

the class NbtCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("add").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = CompoundNbtTagArgumentType.getTag(s, "nbt_data");
            NbtCompound source = stack.getOrCreateNbt();
            if (tag != null) {
                source.copyFrom(tag);
                setStack(stack);
            } else {
                error("Some of the NBT data could not be found, try using: " + Config.get().prefix.get() + "nbt set {nbt}");
            }
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("set").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = s.getArgument("nbt_data", NbtCompound.class);
            stack.setNbt(tag);
            setStack(stack);
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("remove").then(argument("nbt_path", NbtPathArgumentType.nbtPath()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtPathArgumentType.NbtPath path = s.getArgument("nbt_path", NbtPathArgumentType.NbtPath.class);
            path.remove(stack.getNbt());
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("get").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getNbt();
            String nbt = tag == null ? "{}" : tag.asString();
            BaseText copyButton = new LiteralText("NBT");
            copyButton.setStyle(copyButton.getStyle().withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, this.toString("copy"))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the NBT data to your clipboard."))));
            BaseText text = new LiteralText("");
            text.append(copyButton);
            text.append(new LiteralText(": " + nbt));
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("copy").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getOrCreateNbt();
            mc.keyboard.setClipboard(tag.toString());
            BaseText nbt = new LiteralText("NBT");
            nbt.setStyle(nbt.getStyle().withFormatting(Formatting.UNDERLINE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(tag.toString()))));
            BaseText text = new LiteralText("");
            text.append(nbt);
            text.append(new LiteralText(" data copied!"));
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("count").then(argument("count", IntegerArgumentType.integer(-127, 127)).executes(context -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            int count = IntegerArgumentType.getInteger(context, "count");
            stack.setCount(count);
            setStack(stack);
            info("Set mainhand stack count to %s.", count);
        }
        return SINGLE_SUCCESS;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) CompoundNbtTagArgumentType(meteordevelopment.meteorclient.systems.commands.arguments.CompoundNbtTagArgumentType) CreativeInventoryActionC2SPacket(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket) Config(meteordevelopment.meteorclient.systems.config.Config) HoverEvent(net.minecraft.text.HoverEvent) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) ItemStack(net.minecraft.item.ItemStack) NbtCompound(net.minecraft.nbt.NbtCompound) BaseText(net.minecraft.text.BaseText) Formatting(net.minecraft.util.Formatting) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) Command(meteordevelopment.meteorclient.systems.commands.Command) ClickEvent(net.minecraft.text.ClickEvent) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) NbtCompound(net.minecraft.nbt.NbtCompound) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) ClickEvent(net.minecraft.text.ClickEvent) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Aggregations

HoverEvent (net.minecraft.text.HoverEvent)23 LiteralText (net.minecraft.text.LiteralText)23 ClickEvent (net.minecraft.text.ClickEvent)13 BaseText (net.minecraft.text.BaseText)9 ItemStack (net.minecraft.item.ItemStack)7 MutableText (net.minecraft.text.MutableText)7 Formatting (net.minecraft.util.Formatting)7 CommandSource (net.minecraft.command.CommandSource)6 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)5 Text (net.minecraft.text.Text)5 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)4 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 CommandContext (com.mojang.brigadier.context.CommandContext)3 java.util (java.util)3 NbtPathArgumentType (net.minecraft.command.argument.NbtPathArgumentType)3 CreativeInventoryActionC2SPacket (net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket)3 Command (org.bleachhack.command.Command)3 BleachLogger (org.bleachhack.util.BleachLogger)3 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)2