From af4e41ca71aff08c4f075224c55f1dccab454af7 Mon Sep 17 00:00:00 2001 From: Patbox Date: Thu, 12 Dec 2024 20:51:34 +0100 Subject: [PATCH] Make target command output copyable --- .../java/eu/pb4/polymer/core/impl/Commands.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java index 396ad5b7..008ef3ef 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/Commands.java @@ -53,10 +53,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.stat.StatType; import net.minecraft.state.property.Property; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.MutableText; -import net.minecraft.text.RawFilteredPair; -import net.minecraft.text.Text; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -215,15 +212,21 @@ private static int targetBlock(CommandContext context) { builder.append("]"); } - context.getSource().sendFeedback(() -> Text.literal(builder.toString()), false); + context.getSource().sendFeedback(() -> Text.literal(builder.toString()) + .setStyle(Style.EMPTY + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))) + .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, builder.toString()))), false); return 0; } private static int targetItem(CommandContext context) throws CommandSyntaxException { var itemStack = context.getSource().getPlayerOrThrow().getMainHandStack(); - context.getSource().sendFeedback(() -> Text.of(Registries.ITEM.getId(itemStack.getItem())), false); - return 0; + var id = Registries.ITEM.getId(itemStack.getItem()); + context.getSource().sendFeedback(() -> Text.literal(id.toString()) + .setStyle(Style.EMPTY + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))) + .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, id.toString()))), false); return 0; } private static int dumpRegistries(CommandContext context) {