diff options
Diffstat (limited to 'src/main/java')
6 files changed, 61 insertions, 30 deletions
diff --git a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java b/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java index 22f180c..5e5b37a 100644 --- a/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java +++ b/src/main/java/org/polyfrost/chatting/hook/ChatLineHook.java @@ -5,11 +5,15 @@ import net.minecraft.client.network.NetworkPlayerInfo; import java.lang.ref.WeakReference; import java.util.HashSet; +import java.util.List; public interface ChatLineHook { HashSet<WeakReference<ChatLine>> chatLines = new HashSet<>(); boolean isDetected(); void setDetected(boolean detected); + List<ChatLine> getChildren(); + long getTimestamp(); + void setTimestamp(long timestamp); NetworkPlayerInfo getPlayerInfo(); void setPlayerInfo(NetworkPlayerInfo playerInfo); NetworkPlayerInfo getDetectedPlayerInfo(); diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java index cde09ea..6d137de 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatLineMixin.java @@ -17,6 +17,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; @Mixin(ChatLine.class) public class ChatLineMixin implements ChatLineHook { @@ -26,6 +28,23 @@ public class ChatLineMixin implements ChatLineHook { private NetworkPlayerInfo detectedPlayerInfo; private static long lastUniqueId = 0; private long uniqueId = 0; + private long timestamp; + private List<ChatLine> children = new ArrayList<>(); + + @Override + public List<ChatLine> getChildren() { + return children; + } + + @Override + public long getTimestamp() { + return timestamp; + } + + @Override + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } @Inject(method = "<init>", at = @At("RETURN")) private void onInit(int i, IChatComponent iChatComponent, int j, CallbackInfo ci) { diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java index 8d55e0a..dc95fa0 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java @@ -2,13 +2,6 @@ package org.polyfrost.chatting.mixin; import cc.polyfrost.oneconfig.libs.universal.UDesktop; import cc.polyfrost.oneconfig.libs.universal.UResolution; -import org.polyfrost.chatting.chat.*; -import org.polyfrost.chatting.config.ChattingConfig; -import org.polyfrost.chatting.gui.components.ClearButton; -import org.polyfrost.chatting.gui.components.ScreenshotButton; -import org.polyfrost.chatting.gui.components.SearchButton; -import org.polyfrost.chatting.hook.ChatLineHook; -import org.polyfrost.chatting.hook.GuiNewChatHook; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ChatLine; @@ -19,8 +12,13 @@ import net.minecraft.util.MathHelper; import net.minecraftforge.fml.client.config.GuiUtils; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Mouse; -import org.polyfrost.chatting.chat.ChatSearchingManager; -import org.polyfrost.chatting.chat.ChatShortcuts; +import org.polyfrost.chatting.chat.*; +import org.polyfrost.chatting.config.ChattingConfig; +import org.polyfrost.chatting.gui.components.ClearButton; +import org.polyfrost.chatting.gui.components.ScreenshotButton; +import org.polyfrost.chatting.gui.components.SearchButton; +import org.polyfrost.chatting.hook.ChatLineHook; +import org.polyfrost.chatting.hook.GuiNewChatHook; import org.polyfrost.chatting.utils.ModCompatHooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -72,6 +70,11 @@ public abstract class GuiChatMixin extends GuiScreen { } } + @Inject(method = "onGuiClosed", at = @At("HEAD")) + private void onGuiClosedHook(CallbackInfo ci) { + ModCompatHooks.setHoveredText(null); + } + @Inject(method = "updateScreen", at = @At("HEAD")) private void updateScreen(CallbackInfo ci) { if (ChattingConfig.INSTANCE.getChatSearch() && searchButton.isEnabled()) { @@ -95,6 +98,8 @@ public abstract class GuiChatMixin extends GuiScreen { @Inject(method = "drawScreen", at = @At("HEAD")) private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); + ChatLine hoveredLine = hook.getHoveredLine(Mouse.getY()); + ModCompatHooks.setHoveredText(hoveredLine); float f = mc.ingameGUI.getChatGUI().getChatScale(); int x = MathHelper.floor_float((float) mouseX / f); if (hook.isHovering() && (hook.getRight() + ModCompatHooks.getXOffset() + 3) <= x && (hook.getRight() + ModCompatHooks.getXOffset()) + 13 > x) { diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java index ca1c0df..2d65f7d 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMapMixin.java @@ -3,6 +3,7 @@ package org.polyfrost.chatting.mixin; import net.minecraft.client.gui.ChatLine; import net.minecraft.client.gui.GuiNewChat; import net.minecraft.util.IChatComponent; +import org.polyfrost.chatting.hook.ChatLineHook; import org.polyfrost.chatting.hook.GuiNewChatHook; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -12,6 +13,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import tv.twitch.chat.Chat; import java.util.ArrayList; import java.util.HashMap; @@ -50,6 +52,9 @@ public abstract class GuiNewChatMapMixin implements GuiNewChatHook { private void handleLineAdded(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { if (!displayOnly) { ChatLine masterLine = chatLines.get(0); + ChatLineHook masterHook = (ChatLineHook) masterLine; + masterHook.setTimestamp(System.currentTimeMillis()); + masterHook.getChildren().addAll(tempDrawnLines); for (ChatLine tempDrawnLine : tempDrawnLines) drawnToFull.put(tempDrawnLine, masterLine); }else { lastTempLine = null; diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java index 4733ab6..429270a 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java @@ -3,7 +3,13 @@ package org.polyfrost.chatting.mixin; import cc.polyfrost.oneconfig.libs.universal.UMouse; import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.utils.Notifications; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.*; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; import org.polyfrost.chatting.Chatting; import org.polyfrost.chatting.chat.ChatSearchingManager; import org.polyfrost.chatting.config.ChattingConfig; @@ -11,12 +17,6 @@ import org.polyfrost.chatting.hook.ChatLineHook; import org.polyfrost.chatting.hook.GuiNewChatHook; import org.polyfrost.chatting.utils.ModCompatHooks; import org.polyfrost.chatting.utils.RenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.*; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,6 +24,7 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import java.awt.datatransfer.StringSelection; @@ -66,19 +67,6 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private static final ResourceLocation DELETE = new ResourceLocation("chatting:delete.png"); - /*? - @Unique - private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); - @ModifyArg(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;<init>(ILnet/minecraft/util/IChatComponent;I)V")) - private IChatComponent handleAddDrawnLine(IChatComponent iChatComponent) { - if (!ChattingConfig.INSTANCE.getShowTimestamp()) return iChatComponent; - String time = " §7["+ sdf.format(new Date(System.currentTimeMillis())) + "]§r"; - iChatComponent.appendSibling(new ChatComponentText(time)); - return iChatComponent; - } - - */ - @Inject(method = "drawChat", at = @At("HEAD")) private void checkScreenshotKeybind(int j2, CallbackInfo ci) { if (Chatting.INSTANCE.getKeybind().isPressed()) { @@ -172,10 +160,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private int chatting$lastMouseY = 0; - @Inject(method = "getChatComponent", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;")) - private void storeMouseXAndY(int mouseX, int mouseY, CallbackInfoReturnable<IChatComponent> cir) { + @Unique + private ChatLine chatting$currentComponent; + + @Inject(method = "getChatComponent", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;"), locals = LocalCapture.CAPTURE_FAILHARD) + private void storeMouseXAndY(int mouseX, int mouseY, CallbackInfoReturnable<IChatComponent> cir, ScaledResolution scaledResolution, int i, float f, int j, int k, int l, int m) { chatting$lastMouseX = mouseX; chatting$lastMouseY = mouseY; + chatting$currentComponent = drawnChatLines.get(m); } @ModifyVariable(method = "getChatComponent", at = @At("STORE"), ordinal = 0) @@ -203,6 +195,11 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { } } + @ModifyVariable(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;getChatComponent()Lnet/minecraft/util/IChatComponent;"), index = 11) + private int fixOffsetForGetChatComponent(int value) { + return ModCompatHooks.getStartOffset(value, chatting$currentComponent); + } + @Override public int getRight() { return chatting$right; diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiUtilRenderComponentsMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiUtilRenderComponentsMixin.java index fd497a6..bed2eee 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiUtilRenderComponentsMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiUtilRenderComponentsMixin.java @@ -14,6 +14,7 @@ public class GuiUtilRenderComponentsMixin { if (ChattingConfig.INSTANCE.getShowChatHeads() && (ChattingConfig.INSTANCE.getOffsetNonPlayerMessages() || ChatHeadHooks.INSTANCE.detect(text, null))) { return fontRenderer.getStringWidth(text) + 10; } + // TODO: time thingy? return fontRenderer.getStringWidth(text); } } |