aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2021-09-29 13:27:28 -0700
committerAnthony Hilyard <anthony.hilyard@gmail.com>2021-09-29 13:27:28 -0700
commit8c02a2a7e0d2e2951cdc6a4382a6aa8f235ec63b (patch)
tree6afeb1c55253dbcbce3510fb7d64b55dda647dcd
parent211793ac73a3aaa98835c9ac25fa4583a72bb03a (diff)
downloadIceberg-8c02a2a7e0d2e2951cdc6a4382a6aa8f235ec63b.tar.gz
Iceberg-8c02a2a7e0d2e2951cdc6a4382a6aa8f235ec63b.tar.bz2
Iceberg-8c02a2a7e0d2e2951cdc6a4382a6aa8f235ec63b.zip
Added extended tooltip rendering events to facilitate customization.
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/events/RenderTooltipExtEvent.java57
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java16
3 files changed, 70 insertions, 5 deletions
diff --git a/gradle.properties b/gradle.properties
index bfc1894..7a5db84 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,6 +6,6 @@ org.gradle.daemon=false
name=Iceberg
group=com.anthonyhilyard.iceberg
author=anthonyhilyard
-version=1.0.9
+version=1.0.10
mcVersion=1.16.5
forgeVersion=36.2.2 \ No newline at end of file
diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/RenderTooltipExtEvent.java b/src/main/java/com/anthonyhilyard/iceberg/events/RenderTooltipExtEvent.java
new file mode 100644
index 0000000..dfb1364
--- /dev/null
+++ b/src/main/java/com/anthonyhilyard/iceberg/events/RenderTooltipExtEvent.java
@@ -0,0 +1,57 @@
+package com.anthonyhilyard.iceberg.events;
+
+import java.util.List;
+
+import com.mojang.blaze3d.matrix.MatrixStack;
+
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.text.ITextProperties;
+import net.minecraftforge.client.event.RenderTooltipEvent;
+
+public class RenderTooltipExtEvent
+{
+ public static class Pre extends RenderTooltipEvent.Pre
+ {
+ private boolean comparisonTooltip = false;
+ public Pre(ItemStack stack, List<? extends ITextProperties> lines, MatrixStack matrixStack, int x, int y, int screenWidth, int screenHeight, int maxWidth, FontRenderer font, boolean comparison)
+ {
+ super(stack, lines, matrixStack, x, y, screenWidth, screenHeight, maxWidth, font);
+ comparisonTooltip = comparison;
+ }
+ public boolean isComparison() { return comparisonTooltip; }
+ }
+
+ public static class PostBackground extends RenderTooltipEvent.PostBackground
+ {
+ private boolean comparisonTooltip = false;
+ public PostBackground(ItemStack stack, List<? extends ITextProperties> textLines, MatrixStack matrixStack, int x, int y, FontRenderer font, int width, int height, boolean comparison)
+ {
+ super(stack, textLines, matrixStack, x, y, font, width, height);
+ comparisonTooltip = comparison;
+ }
+ public boolean isComparison() { return comparisonTooltip; }
+ }
+
+ public static class PostText extends RenderTooltipEvent.PostText
+ {
+ private boolean comparisonTooltip = false;
+ public PostText(ItemStack stack, List<? extends ITextProperties> textLines, MatrixStack matrixStack, int x, int y, FontRenderer font, int width, int height, boolean comparison)
+ {
+ super(stack, textLines, matrixStack, x, y, font, width, height);
+ comparisonTooltip = comparison;
+ }
+ public boolean isComparison() { return comparisonTooltip; }
+ }
+
+ public static class Color extends RenderTooltipEvent.Color
+ {
+ private boolean comparisonTooltip = false;
+ public Color(ItemStack stack, List<? extends ITextProperties> textLines, MatrixStack matrixStack, int x, int y, FontRenderer font, int background, int borderStart, int borderEnd, boolean comparison)
+ {
+ super(stack, textLines, matrixStack, x, y, font, background, borderStart, borderEnd);
+ comparisonTooltip = comparison;
+ }
+ public boolean isComparison() { return comparisonTooltip; }
+ }
+}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
index 69039db..bc5f081 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
@@ -5,6 +5,7 @@ import java.util.List;
import javax.annotation.Nonnull;
+import com.anthonyhilyard.iceberg.events.RenderTooltipExtEvent;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
@@ -85,11 +86,18 @@ public class Tooltips
}
}
- @SuppressWarnings("deprecation")
public static void renderItemTooltip(@Nonnull final ItemStack stack, MatrixStack mStack, TooltipInfo info,
Rectangle2d rect, int screenWidth, int screenHeight,
int backgroundColor, int borderColorStart, int borderColorEnd)
{
+ renderItemTooltip(stack, mStack, info, rect, screenWidth, screenHeight, backgroundColor, borderColorStart, borderColorEnd, false);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static void renderItemTooltip(@Nonnull final ItemStack stack, MatrixStack mStack, TooltipInfo info,
+ Rectangle2d rect, int screenWidth, int screenHeight,
+ int backgroundColor, int borderColorStart, int borderColorEnd, boolean comparison)
+ {
if (info.getLines().isEmpty())
{
return;
@@ -99,7 +107,7 @@ public class Tooltips
int rectY = rect.getY() + 18;
int maxTextWidth = rect.getWidth() - 8;
- RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, info.getLines(), mStack, rectX, rectY, screenWidth, screenHeight, maxTextWidth, info.getFont());
+ RenderTooltipExtEvent.Pre event = new RenderTooltipExtEvent.Pre(stack, info.getLines(), mStack, rectX, rectY, screenWidth, screenHeight, maxTextWidth, info.getFont(), comparison);
if (MinecraftForge.EVENT_BUS.post(event))
{
return;
@@ -171,7 +179,7 @@ public class Tooltips
}
final int zLevel = 400;
- RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, info.getLines(), mStack, tooltipX, tooltipY, info.getFont(), backgroundColor, borderColorStart, borderColorEnd);
+ RenderTooltipExtEvent.Color colorEvent = new RenderTooltipExtEvent.Color(stack, info.getLines(), mStack, tooltipX, tooltipY, info.getFont(), backgroundColor, borderColorStart, borderColorEnd, comparison);
MinecraftForge.EVENT_BUS.post(colorEvent);
backgroundColor = colorEvent.getBackground();
borderColorStart = colorEvent.getBorderStart();
@@ -216,7 +224,7 @@ public class Tooltips
renderType.endBatch();
mStack.popPose();
- MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, info.getLines(), mStack, tooltipX, tooltipTop, info.getFont(), tooltipTextWidth, tooltipHeight));
+ MinecraftForge.EVENT_BUS.post(new RenderTooltipExtEvent.PostText(stack, info.getLines(), mStack, tooltipX, tooltipTop, info.getFont(), tooltipTextWidth, tooltipHeight, comparison));
RenderSystem.enableDepthTest();
RenderSystem.enableRescaleNormal();