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

@@ -9,6 +9,15 @@
private final SubtitleOverlay subtitleOverlay;
private final SpectatorGui spectatorGui;
private final PlayerTabOverlay tabList;
@@ -320,7 +_,7 @@
Window window = this.minecraft.getWindow();
int i = Mth.floor(this.minecraft.mouseHandler.xpos() * (double)window.getGuiScaledWidth() / (double)window.getScreenWidth());
int j = Mth.floor(this.minecraft.mouseHandler.ypos() * (double)window.getGuiScaledHeight() / (double)window.getScreenHeight());
- this.chat.render(p_329202_, this.tickCount, i, j, false);
+ net.minecraftforge.client.ForgeHooksClient.onCustomizeChatEvent(p_329202_, this.chat, window, i, j, this.tickCount);
}
}
@@ -444,6 +_,8 @@
for (MobEffectInstance mobeffectinstance : Ordering.natural().reverse().sortedCopy(collection)) {
@@ -69,7 +69,7 @@
list.add("");
boolean flag = this.minecraft.getSingleplayerServer() != null;
list.add(
@@ -176,7 +_,12 @@
@@ -176,11 +_,18 @@
+ (this.renderNetworkCharts ? " visible" : " hidden")
);
list.add("For help: press F3 + Q");
@@ -79,10 +79,16 @@
+ protected void drawGameInformation(GuiGraphics p_281525_) {
+ List<String> list = this.getGameInformation();
+ list.addAll(this.getOverlayHelp());
+ net.minecraftforge.client.ForgeHooksClient.onCustomizeDebugEvent(p_281525_, minecraft.getWindow(), minecraft.getFrameTime(), list, true);
+ this.renderLines(p_281525_, list, true);
}
protected void drawSystemInformation(GuiGraphics p_281261_) {
List<String> list = this.getSystemInformation();
+ net.minecraftforge.client.ForgeHooksClient.onCustomizeDebugEvent(p_281261_, minecraft.getWindow(), minecraft.getFrameTime(), list, false);
this.renderLines(p_281261_, list, false);
}
@@ -529,6 +_,7 @@
list.add("");
list.add(ChatFormatting.UNDERLINE + "Targeted Entity");
@@ -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
}
}
@@ -0,0 +1,32 @@
package net.minecraftforge.debug.client;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
@Mod(CustomizeGuiOverlayEventTest.MODID)
public class CustomizeGuiOverlayEventTest
{
private static final boolean ENABLED = false;
public static final String MODID = "custom_gui_event_test";
public CustomizeGuiOverlayEventTest() {
if(ENABLED) {
MinecraftForge.EVENT_BUS.addListener(this::onRenderOverlaychat);
MinecraftForge.EVENT_BUS.addListener(this::onRenderOverlayDebug);
}
}
public void onRenderOverlayDebug(CustomizeGuiOverlayEvent.DebugText event) {
if(CustomizeGuiOverlayEvent.DebugText.Side.Left == event.getSide()) {
event.getText().add("Left Side");
} else {
event.getText().add("Right Side");
}
}
public void onRenderOverlaychat(CustomizeGuiOverlayEvent.Chat event) {
event.setPosY(-200);
}
}