Skip to content

Commit

Permalink
better chat closing rendering (might increase fps
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jul 30, 2024
1 parent 0de9a27 commit 7f6c041
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
28 changes: 3 additions & 25 deletions src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,6 @@ private IChatComponent handleAddDrawnLine(IChatComponent iChatComponent) {
@Unique
private long chatting$time;

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V"))
private void drawClosing(int updateCounter, CallbackInfo ci) {
ChatWindow hud = chatting$config().getChatWindow();

if (chatting$closing && hud.getAnimationHeight() - (hud.getHeight() + hud.getPaddingY() * 2) * hud.getScale() > 9 * hud.getScale()) {
int height = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(true) : calculateChatboxHeight(this.mc.gameSettings.chatHeightFocused));
for (int m = 0; m < this.drawnChatLines.size() && m < height / 9; ++m) {
ChatLine chatLine = this.drawnChatLines.get(m);
if (chatLine != null) {
int unFocusHeight = (hud.getCustomChatHeight() ? Chatting.INSTANCE.getChatHeight(false) : calculateChatboxHeight(this.mc.gameSettings.chatHeightUnfocused));
boolean shouldShow = (chatting$config().getFade() && m >= chatting$totalLines) || m >= unFocusHeight / 9;
if (!getChatOpen() && shouldShow) {
int q = m * 9;
String string = chatLine.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 0xFFFFFFFF, chatLine);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
}
}
}
}

@Inject(method = "drawChat", at = @At("HEAD"))
private void checkScreenshotKeybind(int j2, CallbackInfo ci) {
Expand Down Expand Up @@ -175,7 +152,7 @@ private void startScissor(int updateCounter, CallbackInfo ci) {
int mcScale = new ScaledResolution(mc).getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
int height = (int) hud.getAnimationHeight();
GL11.glScissor((int) ((hud.position.getX() - 1) * mcScale), mc.displayHeight - (int) (hud.position.getBottomY() + hud.getScale()) * mcScale, (int) ((hud.getAnimationWidth() + 1 + (ChattingConfig.INSTANCE.getExtendBG() ? 0 : 20)) * mcScale), (int) ((height + hud.getScale()) * mcScale));
GL11.glScissor((int) ((hud.position.getX() - 3) * mcScale), mc.displayHeight - (int) (hud.position.getBottomY() + hud.getScale()) * mcScale, (int) ((hud.getAnimationWidth() + 3 + (ChattingConfig.INSTANCE.getExtendBG() ? 0 : 20)) * mcScale), (int) ((height + hud.getScale()) * mcScale));
}

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V"))
Expand Down Expand Up @@ -208,7 +185,8 @@ private int fadeTime(int value) {

@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatOpen()Z"))
private boolean noFade(GuiNewChat instance) {
return !chatting$config().getFade() || instance.getChatOpen();
ChatWindow hud = chatting$config().getChatWindow();
return !chatting$config().getFade() || instance.getChatOpen() || (chatting$closing && hud.getAnimationHeight() - (hud.getHeight() + hud.getPaddingY() * 2) * hud.getScale() > 9 * hud.getScale());
}

@Unique
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.polyfrost.chatting.mixin;

import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiNewChat;
import org.polyfrost.chatting.Chatting;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -14,7 +12,7 @@ public class GuiNewChatMixin_ChatPeek {

@Inject(method = "getChatOpen", at = @At("HEAD"), cancellable = true)
private void chatPeek(CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(UMinecraft.getMinecraft().currentScreen instanceof GuiChat || Chatting.INSTANCE.getPeeking());
if (Chatting.INSTANCE.getPeeking()) cir.setReturnValue(true);
}

}

0 comments on commit 7f6c041

Please sign in to comment.