From 45152c6073da786f9c0d07e00b27abf9b66e88ff Mon Sep 17 00:00:00 2001 From: Cyborgmas Date: Tue, 30 Jun 2020 15:01:24 +0200 Subject: [PATCH] Pass matrixstack in tooltip render events (#6885) --- .../client/event/RenderTooltipEvent.java | 33 ++++++++++++------- .../fml/client/gui/GuiUtils.java | 8 ++--- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/event/RenderTooltipEvent.java b/src/main/java/net/minecraftforge/client/event/RenderTooltipEvent.java index 2adad87bc..c2ecf3f61 100644 --- a/src/main/java/net/minecraftforge/client/event/RenderTooltipEvent.java +++ b/src/main/java/net/minecraftforge/client/event/RenderTooltipEvent.java @@ -24,6 +24,7 @@ import java.util.List; import javax.annotation.Nonnull; +import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextProperties; @@ -48,14 +49,16 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api @Nonnull protected final ItemStack stack; protected final List lines; + protected final MatrixStack matrixStack; protected int x; protected int y; protected FontRenderer fr; - public RenderTooltipEvent(@Nonnull ItemStack stack, @Nonnull List lines, int x, int y, @Nonnull FontRenderer fr) + public RenderTooltipEvent(@Nonnull ItemStack stack, @Nonnull List lines, MatrixStack matrixStack, int x, int y, @Nonnull FontRenderer fr) { this.stack = stack; this.lines = Collections.unmodifiableList(lines); // Leave editing to ItemTooltipEvent + this.matrixStack = matrixStack; this.x = x; this.y = y; this.fr = fr; @@ -81,6 +84,14 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api return lines; } + /** + * @return The MatrixStack of the current rendering context + */ + public MatrixStack getMatrixStack() + { + return matrixStack; + } + /** * @return The X position of the tooltip box. By default, the mouse X position. */ @@ -118,9 +129,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api private int screenHeight; private int maxWidth; - public Pre(@Nonnull ItemStack stack, @Nonnull List lines, int x, int y, int screenWidth, int screenHeight, int maxWidth, @Nonnull FontRenderer fr) + public Pre(@Nonnull ItemStack stack, @Nonnull List lines, MatrixStack matrixStack, int x, int y, int screenWidth, int screenHeight, int maxWidth, @Nonnull FontRenderer fr) { - super(stack, lines, x, y, fr); + super(stack, lines, matrixStack, x, y, fr); this.screenWidth = screenWidth; this.screenHeight = screenHeight; this.maxWidth = maxWidth; @@ -201,9 +212,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api private final int width; private final int height; - public Post(@Nonnull ItemStack stack, @Nonnull List textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height) + public Post(@Nonnull ItemStack stack, @Nonnull List textLines, MatrixStack matrixStack,int x, int y, @Nonnull FontRenderer fr, int width, int height) { - super(stack, textLines, x, y, fr); + super(stack, textLines, matrixStack, x, y, fr); this.width = width; this.height = height; } @@ -230,8 +241,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api */ public static class PostBackground extends Post { - public PostBackground(@Nonnull ItemStack stack, @Nonnull List textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height) - { super(stack, textLines, x, y, fr, width, height); } + public PostBackground(@Nonnull ItemStack stack, @Nonnull List textLines, MatrixStack matrixStack, int x, int y, @Nonnull FontRenderer fr, int width, int height) + { super(stack, textLines, matrixStack, x, y, fr, width, height); } } /** @@ -239,8 +250,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api */ public static class PostText extends Post { - public PostText(@Nonnull ItemStack stack, @Nonnull List textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height) - { super(stack, textLines, x, y, fr, width, height); } + public PostText(@Nonnull ItemStack stack, @Nonnull List textLines, MatrixStack matrixStack, int x, int y, @Nonnull FontRenderer fr, int width, int height) + { super(stack, textLines, matrixStack, x, y, fr, width, height); } } /** @@ -255,10 +266,10 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api private int borderStart; private int borderEnd; - public Color(@Nonnull ItemStack stack, @Nonnull List textLines, int x, int y, @Nonnull FontRenderer fr, int background, int borderStart, + public Color(@Nonnull ItemStack stack, @Nonnull List textLines, MatrixStack matrixStack, int x, int y, @Nonnull FontRenderer fr, int background, int borderStart, int borderEnd) { - super(stack, textLines, x, y, fr); + super(stack, textLines, matrixStack, x, y, fr); this.originalBackground = background; this.originalBorderStart = borderStart; this.originalBorderEnd = borderEnd; diff --git a/src/main/java/net/minecraftforge/fml/client/gui/GuiUtils.java b/src/main/java/net/minecraftforge/fml/client/gui/GuiUtils.java index 21dc9b829..12905b247 100644 --- a/src/main/java/net/minecraftforge/fml/client/gui/GuiUtils.java +++ b/src/main/java/net/minecraftforge/fml/client/gui/GuiUtils.java @@ -287,7 +287,7 @@ public class GuiUtils { if (!textLines.isEmpty()) { - RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font); + RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mStack, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font); if (MinecraftForge.EVENT_BUS.post(event)) return; mouseX = event.getX(); @@ -375,7 +375,7 @@ public class GuiUtils tooltipY = screenHeight - tooltipHeight - 4; final int zLevel = 400; - RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, textLines, tooltipX, tooltipY, font, backgroundColor, borderColorStart, borderColorEnd); + RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, textLines, mStack, tooltipX, tooltipY, font, backgroundColor, borderColorStart, borderColorEnd); MinecraftForge.EVENT_BUS.post(colorEvent); backgroundColor = colorEvent.getBackground(); borderColorStart = colorEvent.getBorderStart(); @@ -394,7 +394,7 @@ public class GuiUtils drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); - MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, tooltipX, tooltipY, font, tooltipTextWidth, tooltipHeight)); + MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, mStack, tooltipX, tooltipY, font, tooltipTextWidth, tooltipHeight)); IRenderTypeBuffer.Impl renderType = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer()); mStack.translate(0.0D, 0.0D, zLevel); @@ -416,7 +416,7 @@ public class GuiUtils renderType.finish(); mStack.pop(); - MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight)); + MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, mStack, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight)); RenderSystem.enableDepthTest(); RenderSystem.enableRescaleNormal();