Skip to content

Commit 2f94633

Browse files
committed
completely fixed chathead offset
1 parent 53cfedd commit 2f94633

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ private void drawClosing(int updateCounter, CallbackInfo ci) {
9494
ChatWindow hud = chatting$config().getChatWindow();
9595

9696
if (closing && hud.getAnimationHeight() - (hud.getHeight() + hud.getPaddingY() * 2) * hud.getScale() > 9 * hud.getScale()) {
97-
int height = (chatting$config().getChatWindow().getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(true) : calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused));
97+
int height = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(true) : calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused));
9898
for (int m = 0; m < this.drawnChatLines.size() && m < height / 9; ++m) {
9999
ChatLine chatLine = this.drawnChatLines.get(m);
100100
if (chatLine != null) {
101-
int unFocusHeight = (chatting$config().getChatWindow().getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(false) : calculateChatboxHeight(this.mc.gameSettings.chatHeightUnfocused));
101+
int unFocusHeight = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(false) : calculateChatboxHeight(this.mc.gameSettings.chatHeightUnfocused));
102102
boolean shouldShow = (chatting$config().getFade() && m >= totalLines) || m >= unFocusHeight / 9;
103103
if (!getChatOpen() && shouldShow) {
104104
int q = m * 9;

src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_Movable.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import cc.polyfrost.oneconfig.hud.Position;
44
import cc.polyfrost.oneconfig.internal.hud.HudCore;
55
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.ChatLine;
67
import net.minecraft.client.gui.GuiNewChat;
78
import net.minecraft.client.gui.ScaledResolution;
89
import net.minecraft.util.MathHelper;
910
import org.polyfrost.chatting.chat.ChatWindow;
1011
import org.polyfrost.chatting.config.ChattingConfig;
12+
import org.polyfrost.chatting.hook.ChatLineHook;
1113
import org.polyfrost.chatting.utils.ModCompatHooks;
1214
import org.spongepowered.asm.mixin.Mixin;
1315
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.Unique;
1417
import org.spongepowered.asm.mixin.injection.*;
1518
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1619
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
@@ -20,6 +23,8 @@ public abstract class GuiNewChatMixin_Movable {
2023

2124
@Shadow public abstract int getChatWidth();
2225

26+
@Unique private static ChatLine currentLine;
27+
2328
@ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V", ordinal = 0))
2429
private void translate(Args args) {
2530
ChatWindow hud = ChattingConfig.INSTANCE.getChatWindow();
@@ -52,7 +57,7 @@ private void exampleChat(int updateCounter, CallbackInfo ci) {
5257
private int mouseX(int constant) {
5358
ChattingConfig config = ChattingConfig.INSTANCE;
5459
ChatWindow hud = config.getChatWindow();
55-
return (int) ((hud.position.getX()) + (hud.getPaddingX() + 1 + (config.getShowChatHeads() && config.getOffsetNonPlayerMessages() ? 8 : 0)) * hud.getScale());
60+
return (int) ((hud.position.getX()) + (hud.getPaddingX() + 1) * hud.getScale());
5661
}
5762

5863
@ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 27))
@@ -62,14 +67,26 @@ private int mouseY(int constant) {
6267
return height - (int) (hud.position.getBottomY() - hud.getPaddingY() * hud.getScale() + ModCompatHooks.getChatPosition());
6368
}
6469

70+
@ModifyVariable(method = "getChatComponent", at = @At("STORE"), ordinal = 0)
71+
private ChatLine capture(ChatLine chatLine) {
72+
currentLine = chatLine;
73+
return chatLine;
74+
}
75+
76+
@ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 0))
77+
private int offset(int value) {
78+
return ((ChatLineHook) currentLine).chatting$hasDetected() || ChattingConfig.INSTANCE.getOffsetNonPlayerMessages() ? ModCompatHooks.getChatHeadOffset() : 0;
79+
}
80+
6581
@Redirect(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F", ordinal = 0))
6682
private float getScale(GuiNewChat instance) {
6783
return ChattingConfig.INSTANCE.getChatWindow().getScale();
6884
}
6985

70-
@Redirect(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F", ordinal = 1))
71-
private float getScale2(GuiNewChat instance) {
72-
return 1f;
86+
@ModifyArg(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", ordinal = 2))
87+
private float width(float value) {
88+
ChatWindow hud = ChattingConfig.INSTANCE.getChatWindow();
89+
return hud.position.getX() + hud.getWidth();
7390
}
7491

7592
}

0 commit comments

Comments
 (0)