|
3 | 3 | import moe.nea.firmament.features.chat.CopyChat; |
4 | 4 | import moe.nea.firmament.mixins.accessor.AccessorChatHud; |
5 | 5 | import moe.nea.firmament.util.ClipboardUtils; |
| 6 | +import moe.nea.firmament.util.MC; |
6 | 7 | import net.minecraft.client.Minecraft; |
| 8 | +import net.minecraft.client.gui.ActiveTextCollector; |
| 9 | +import net.minecraft.client.gui.TextAlignment; |
| 10 | +import net.minecraft.client.gui.render.state.GuiTextRenderState; |
7 | 11 | import net.minecraft.client.input.MouseButtonEvent; |
8 | 12 | import net.minecraft.client.gui.components.ChatComponent; |
9 | 13 | import net.minecraft.client.GuiMessage; |
10 | 14 | import net.minecraft.client.gui.screens.ChatScreen; |
11 | 15 | import net.minecraft.network.chat.Component; |
12 | 16 | import net.minecraft.ChatFormatting; |
| 17 | +import net.minecraft.util.ARGB; |
| 18 | +import net.minecraft.util.FormattedCharSequence; |
13 | 19 | import net.minecraft.util.Mth; |
| 20 | +import org.joml.Matrix3x2f; |
14 | 21 | import org.spongepowered.asm.mixin.Mixin; |
15 | 22 | import org.spongepowered.asm.mixin.Unique; |
16 | 23 | import org.spongepowered.asm.mixin.injection.At; |
17 | 24 | import org.spongepowered.asm.mixin.injection.Inject; |
18 | 25 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
19 | 26 |
|
20 | 27 | import java.util.List; |
| 28 | +import java.util.Objects; |
21 | 29 |
|
22 | 30 | @Mixin(ChatScreen.class) |
23 | 31 | public class CopyChatPatch { |
24 | 32 | @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) |
25 | | - private void onRightClick(MouseButtonEvent click, boolean doubled, CallbackInfoReturnable<Boolean> cir) throws NoSuchFieldException, IllegalAccessException { |
| 33 | + private void onRightClick(MouseButtonEvent click, boolean doubled, CallbackInfoReturnable<Boolean> cir) { |
26 | 34 | if (click.button() != 1 || !CopyChat.TConfig.INSTANCE.getCopyChat()) return; |
27 | 35 | Minecraft client = Minecraft.getInstance(); |
28 | 36 | ChatComponent chatHud = client.gui.getChat(); |
29 | | - int lineIndex = getChatLineIndex(chatHud, click.y()); |
30 | | - if (lineIndex < 0) return; |
31 | | - // TODO!!! use the new visitor for this (cc: image links) |
32 | | - List<GuiMessage.Line> visible = ((AccessorChatHud) chatHud).getVisibleMessages_firmament(); |
33 | | - if (lineIndex >= visible.size()) return; |
34 | | - GuiMessage.Line line = visible.get(lineIndex); |
35 | | - String text = CopyChat.INSTANCE.orderedTextToString(line.content()); |
| 37 | + var collector = new CopyChat.HoveredTextLineCollector((int) click.x(), (int) click.y()); |
| 38 | + chatHud.captureClickableText(collector, |
| 39 | + MC.INSTANCE.getWindow().getGuiScaledHeight(), MC.INSTANCE.getInstance().gui.getGuiTicks(), true); |
| 40 | + if (collector.getResult() == null) return; |
| 41 | + String text = CopyChat.INSTANCE.orderedTextToString(collector.getResult()); |
36 | 42 | ClipboardUtils.INSTANCE.setTextContent(text); |
37 | 43 | chatHud.addMessage(Component.literal("Copied: ").append(text).withStyle(ChatFormatting.GRAY)); |
38 | 44 | cir.setReturnValue(true); |
39 | 45 | cir.cancel(); |
40 | 46 | } |
41 | | - |
42 | | - @Unique |
43 | | - private int getChatLineIndex(ChatComponent chatHud, double mouseY) { |
44 | | - return 0; /// TODO!!!! |
45 | | - } |
46 | 47 | } |
0 commit comments