aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java6
-rw-r--r--src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java8
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java30
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java80
-rw-r--r--src/main/kotlin/com/raeids/stratus/Stratus.kt16
-rw-r--r--src/main/resources/assets/stratus/copy.pngbin0 -> 641 bytes
-rw-r--r--src/main/resources/mixins.stratus.json1
7 files changed, 135 insertions, 6 deletions
diff --git a/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java b/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java
new file mode 100644
index 0000000..542b4a5
--- /dev/null
+++ b/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java
@@ -0,0 +1,6 @@
+package com.raeids.stratus.hook;
+
+public interface GuiIngameForgeHook {
+ int getX();
+ int getY();
+}
diff --git a/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java
new file mode 100644
index 0000000..4c50e5c
--- /dev/null
+++ b/src/main/java/com/raeids/stratus/hook/GuiNewChatHook.java
@@ -0,0 +1,8 @@
+package com.raeids.stratus.hook;
+
+public interface GuiNewChatHook {
+ int getX();
+ int getY();
+ boolean shouldCopy();
+ String copyString();
+}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java
new file mode 100644
index 0000000..3c500f5
--- /dev/null
+++ b/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java
@@ -0,0 +1,30 @@
+package com.raeids.stratus.mixin;
+
+import com.raeids.stratus.hook.GuiIngameForgeHook;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraftforge.client.GuiIngameForge;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Redirect;
+
+@Mixin(value = GuiIngameForge.class, remap = false)
+public class GuiIngameForgeMixin implements GuiIngameForgeHook {
+ private int stratus$x = 0;
+ private int stratus$y = 0;
+ @Redirect(method = "renderChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V", remap = true))
+ private void captureTranslate(float x, float y, float z) {
+ stratus$x = Math.round(x);
+ stratus$y = Math.round(y);
+ GlStateManager.translate(x, y, z);
+ }
+
+ @Override
+ public int getX() {
+ return stratus$x;
+ }
+
+ @Override
+ public int getY() {
+ return stratus$y;
+ }
+}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
index bbe1e9b..5732778 100644
--- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
+++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
@@ -3,25 +3,36 @@ package com.raeids.stratus.mixin;
import com.raeids.stratus.Stratus;
import com.raeids.stratus.hook.ChatSearchingKt;
import com.raeids.stratus.hook.ChatTabs;
+import com.raeids.stratus.hook.GuiIngameForgeHook;
+import com.raeids.stratus.hook.GuiNewChatHook;
+import gg.essential.universal.UResolution;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
+import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiNewChat;
+import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.IChatComponent;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.input.Mouse;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
-import org.spongepowered.asm.mixin.injection.Redirect;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
@Mixin(GuiNewChat.class)
-public class GuiNewChatMixin {
+public class GuiNewChatMixin extends Gui implements GuiNewChatHook {
+ @Unique private int stratus$x = 0;
+ @Unique private int stratus$y = 0;
+ @Unique private boolean stratus$shouldCopy;
+ @Unique private ChatLine stratus$chatLine;
@Shadow @Final private Minecraft mc;
+ @Shadow @Final private List<ChatLine> drawnChatLines;
+ @Unique private static final ResourceLocation COPY = new ResourceLocation("stratus:copy.png");
@Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", shift = At.Shift.AFTER))
private void setDoing(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
@@ -47,10 +58,67 @@ public class GuiNewChatMixin {
: linesToDraw;
}
- @Shadow @Final private List<ChatLine> drawnChatLines;
+ @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;"))
+ private Object captureChatLine(List<ChatLine> instance, int i) {
+ stratus$chatLine = instance.get(i);
+ return stratus$chatLine;
+ }
+
+ @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;clamp_double(DDD)D"), to = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;enableBlend()V")))
+ private void captureDrawRect(int left, int top, int right, int bottom, int color) {
+ drawRect(left, top, right, bottom, color);
+ final int k1 = Mouse.getX() * UResolution.getScaledWidth() / this.mc.displayWidth;
+ final int l1 = UResolution.getScaledHeight() - Mouse.getY() * UResolution.getScaledHeight() / this.mc.displayHeight - 1;
+ int mouseX = k1 - ((GuiIngameForgeHook) mc.ingameGUI).getX() - 2;
+ int mouseY = l1 - ((GuiIngameForgeHook) mc.ingameGUI).getY() - 20;
+ if (mouseX >= left && mouseY <= bottom && mouseX - 9 <= right && mouseY >= top) {
+ stratus$shouldCopy = true;
+ GlStateManager.enableRescaleNormal();
+ GlStateManager.enableBlend();
+ GlStateManager.enableDepth();
+ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
+ GlStateManager.pushMatrix();
+ mc.getTextureManager().bindTexture(COPY);
+ GlStateManager.enableRescaleNormal();
+ GlStateManager.enableAlpha();
+ GlStateManager.alphaFunc(516, 0.1f);
+ GlStateManager.enableBlend();
+ GlStateManager.blendFunc(770, 771);
+ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
+ stratus$x = right;
+ stratus$y = top;
+ Gui.drawModalRectWithCustomSizedTexture(right, top, 0f, 0f, 9, 9, 9, 9);
+ GlStateManager.disableAlpha();
+ GlStateManager.disableRescaleNormal();
+ GlStateManager.disableLighting();
+ GlStateManager.popMatrix();
+ } else if (stratus$shouldCopy) {
+ stratus$shouldCopy = false;
+ }
+ }
@Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD))
private List<ChatLine> injected(GuiNewChat instance) {
return ChatSearchingKt.filterMessages(drawnChatLines);
}
+
+ @Override
+ public int getX() {
+ return stratus$x;
+ }
+
+ @Override
+ public int getY() {
+ return stratus$y;
+ }
+
+ @Override
+ public boolean shouldCopy() {
+ return stratus$shouldCopy;
+ }
+
+ @Override
+ public String copyString() {
+ return stratus$chatLine.getChatComponent().getFormattedText();
+ }
}
diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt
index 653c265..ba2e739 100644
--- a/src/main/kotlin/com/raeids/stratus/Stratus.kt
+++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt
@@ -3,6 +3,7 @@ package com.raeids.stratus
import com.raeids.stratus.command.StratusCommand
import com.raeids.stratus.config.StratusConfig
import com.raeids.stratus.hook.ChatTabs
+import com.raeids.stratus.hook.GuiNewChatHook
import com.raeids.stratus.mixin.GuiNewChatAccessor
import com.raeids.stratus.updater.Updater
import com.raeids.stratus.utils.RenderHelper
@@ -14,6 +15,7 @@ import net.minecraft.client.gui.GuiChat
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.settings.KeyBinding
import net.minecraft.client.shader.Framebuffer
+import net.minecraftforge.client.event.MouseEvent
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
import net.minecraftforge.fml.client.registry.ClientRegistry
import net.minecraftforge.fml.common.Mod
@@ -22,6 +24,8 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.input.Keyboard
+import java.awt.Toolkit
+import java.awt.datatransfer.StringSelection
import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
@@ -65,6 +69,18 @@ object Stratus {
}
@SubscribeEvent
+ fun onMouseClick(event: MouseEvent) {
+ val hook = Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook
+ if (hook.shouldCopy()) {
+ try {
+ Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(hook.copyString()), null)
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ }
+ }
+
+ @SubscribeEvent
fun onTickEvent(event: TickEvent.ClientTickEvent) {
if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) {
if (doTheThing) {
diff --git a/src/main/resources/assets/stratus/copy.png b/src/main/resources/assets/stratus/copy.png
new file mode 100644
index 0000000..f21d724
--- /dev/null
+++ b/src/main/resources/assets/stratus/copy.png
Binary files differ
diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json
index 574b29e..35f3de0 100644
--- a/src/main/resources/mixins.stratus.json
+++ b/src/main/resources/mixins.stratus.json
@@ -7,6 +7,7 @@
"GuiChatMixin",
"GuiNewChatAccessor",
"GuiUtilRenderComponentsMixin",
+ "GuiIngameForgeMixin",
"GuiNewChatMixin"
],
"verbose": true