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 javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.text.ITextProperties;
|
import net.minecraft.util.text.ITextProperties;
|
||||||
|
@ -48,14 +49,16 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected final ItemStack stack;
|
protected final ItemStack stack;
|
||||||
protected final List<? extends ITextProperties> lines;
|
protected final List<? extends ITextProperties> lines;
|
||||||
|
protected final MatrixStack matrixStack;
|
||||||
protected int x;
|
protected int x;
|
||||||
protected int y;
|
protected int y;
|
||||||
protected FontRenderer fr;
|
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.stack = stack;
|
||||||
this.lines = Collections.unmodifiableList(lines); // Leave editing to ItemTooltipEvent
|
this.lines = Collections.unmodifiableList(lines); // Leave editing to ItemTooltipEvent
|
||||||
|
this.matrixStack = matrixStack;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.fr = fr;
|
this.fr = fr;
|
||||||
|
@ -81,6 +84,14 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||||
return lines;
|
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.
|
* @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 screenHeight;
|
||||||
private int maxWidth;
|
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.screenWidth = screenWidth;
|
||||||
this.screenHeight = screenHeight;
|
this.screenHeight = screenHeight;
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
|
@ -201,9 +212,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
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.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
@ -230,8 +241,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||||
*/
|
*/
|
||||||
public static class PostBackground extends Post
|
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)
|
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, x, y, fr, width, 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 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)
|
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, x, y, fr, width, 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 borderStart;
|
||||||
private int borderEnd;
|
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)
|
int borderEnd)
|
||||||
{
|
{
|
||||||
super(stack, textLines, x, y, fr);
|
super(stack, textLines, matrixStack, x, y, fr);
|
||||||
this.originalBackground = background;
|
this.originalBackground = background;
|
||||||
this.originalBorderStart = borderStart;
|
this.originalBorderStart = borderStart;
|
||||||
this.originalBorderEnd = borderEnd;
|
this.originalBorderEnd = borderEnd;
|
||||||
|
|
|
@ -287,7 +287,7 @@ public class GuiUtils
|
||||||
{
|
{
|
||||||
if (!textLines.isEmpty())
|
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))
|
if (MinecraftForge.EVENT_BUS.post(event))
|
||||||
return;
|
return;
|
||||||
mouseX = event.getX();
|
mouseX = event.getX();
|
||||||
|
@ -375,7 +375,7 @@ public class GuiUtils
|
||||||
tooltipY = screenHeight - tooltipHeight - 4;
|
tooltipY = screenHeight - tooltipHeight - 4;
|
||||||
|
|
||||||
final int zLevel = 400;
|
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);
|
MinecraftForge.EVENT_BUS.post(colorEvent);
|
||||||
backgroundColor = colorEvent.getBackground();
|
backgroundColor = colorEvent.getBackground();
|
||||||
borderColorStart = colorEvent.getBorderStart();
|
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 - 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);
|
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());
|
IRenderTypeBuffer.Impl renderType = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer());
|
||||||
mStack.translate(0.0D, 0.0D, zLevel);
|
mStack.translate(0.0D, 0.0D, zLevel);
|
||||||
|
@ -416,7 +416,7 @@ public class GuiUtils
|
||||||
renderType.finish();
|
renderType.finish();
|
||||||
mStack.pop();
|
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.enableDepthTest();
|
||||||
RenderSystem.enableRescaleNormal();
|
RenderSystem.enableRescaleNormal();
|
||||||
|
|
Loading…
Reference in a new issue