Fix CustomizeGuiOverlayEvent.DebugText and CustomizeGuiOverlayEvent.Chat not being fired. (#9982)

This commit is contained in:
Mysticdrew authored and GitHub committed 2024-05-24 08:33:52 -07:00
1 parent fd8a0f9c8b
commit c2c7f9b656
5 files changed
+96 -13

No files matched your search

@@ -28,6 +28,7 @@ import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.client.gui.components.LerpingBossEvent;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.screens.ConfirmScreen;
@@ -531,6 +532,25 @@ public class ForgeHooksClient {
return evt;
}
public static void onCustomizeChatEvent(GuiGraphics guiGraphics, ChatComponent chat, Window window, int mouseX, int mouseY, int tickCount) {
var minecraft = Minecraft.getInstance();
minecraft.getProfiler().push("chat");
CustomizeGuiOverlayEvent.Chat evt = new CustomizeGuiOverlayEvent.Chat(window, guiGraphics, minecraft.getFrameTime(), 0, chat.getHeight() - 40);
MinecraftForge.EVENT_BUS.post(evt);
guiGraphics.pose().pushPose();
// We give the absolute Y position of the chat component in the event and account for the chat component's own offsetting here.
guiGraphics.pose().translate(evt.getPosX(), (evt.getPosY() - chat.getHeight() + 40) / chat.getScale(), 0.0D);
chat.render(guiGraphics, tickCount, mouseX, mouseY, false);
guiGraphics.pose().popPose();
minecraft.getProfiler().pop();
}
public static void onCustomizeDebugEvent(GuiGraphics guiGraphics, Window window, float partialTick, List<String> text, boolean isLeft) {
var evt = new CustomizeGuiOverlayEvent.DebugText(window, guiGraphics, partialTick, text,
isLeft ? CustomizeGuiOverlayEvent.DebugText.Side.Left : CustomizeGuiOverlayEvent.DebugText.Side.Right);
MinecraftForge.EVENT_BUS.post(evt);
}
public static void onClientChangeGameType(PlayerInfo info, GameType currentGameMode, GameType newGameMode) {
if (currentGameMode != newGameMode) {
ClientPlayerChangeGameTypeEvent evt = new ClientPlayerChangeGameTypeEvent(info, currentGameMode, newGameMode);
@@ -15,6 +15,7 @@ import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.ApiStatus;
import java.util.ArrayList;
import java.util.List;
/**
* Fired when an overlay is about to be rendered to the screen to allow the user to modify it.
@@ -133,31 +134,46 @@ public abstract class CustomizeGuiOverlayEvent extends Event
*/
public static class DebugText extends CustomizeGuiOverlayEvent
{
private final ArrayList<String> left;
private final ArrayList<String> right;
private final List<String> text;
private final Side side;
@ApiStatus.Internal
public DebugText(Window window, GuiGraphics guiGraphics, float partialTick, ArrayList<String> left, ArrayList<String> right)
public DebugText(Window window, GuiGraphics guiGraphics, float partialTick, List<String> text, Side side)
{
super(window, guiGraphics, partialTick);
this.left = left;
this.right = right;
this.text = text;
this.side = side;
}
/**
* @return the modifiable list of text to render on the left side
* @return the modifiable list of text to render on the side
*/
public ArrayList<String> getLeft()
public List<String> getText()
{
return left;
return this.text;
}
@Deprecated(forRemoval = true, since = "1.20.6")
public List<String> getLeft() {
return Side.Left.equals(this.side) ? this.text : new ArrayList<>();
}
@Deprecated(forRemoval = true, since = "1.20.6")
public List<String> getRight() {
return Side.Right.equals(this.side) ? this.text : new ArrayList<>();
}
/**
* @return the modifiable list of text to render on the right side
* @return the side of the text getting rendered.
*/
public ArrayList<String> getRight()
{
return right;
public Side getSide() {
return this.side;
}
public enum Side {
Left,
Right
}
}