Pass matrixstack in tooltip render events (#6885)
This commit is contained in:
parent
46c9dec421
commit
45152c6073
2 changed files with 26 additions and 15 deletions
|
@ -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<? extends ITextProperties> lines;
|
||||
protected final MatrixStack matrixStack;
|
||||
protected int x;
|
||||
protected int y;
|
||||
protected FontRenderer fr;
|
||||
|
||||
public RenderTooltipEvent(@Nonnull ItemStack stack, @Nonnull List<? extends ITextProperties> lines, int x, int y, @Nonnull FontRenderer fr)
|
||||
public RenderTooltipEvent(@Nonnull ItemStack stack, @Nonnull List<? extends ITextProperties> 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<? extends ITextProperties> lines, int x, int y, int screenWidth, int screenHeight, int maxWidth, @Nonnull FontRenderer fr)
|
||||
public Pre(@Nonnull ItemStack stack, @Nonnull List<? extends ITextProperties> 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<? extends ITextProperties> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
|
||||
public Post(@Nonnull ItemStack stack, @Nonnull List<? extends ITextProperties> 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<? extends ITextProperties> 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<? extends ITextProperties> 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<? extends ITextProperties> 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<? extends ITextProperties> 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<? extends ITextProperties> textLines, int x, int y, @Nonnull FontRenderer fr, int background, int borderStart,
|
||||
public Color(@Nonnull ItemStack stack, @Nonnull List<? extends ITextProperties> 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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue