diff --git a/patches/net/minecraft/client/gui/GuiGraphics.java.patch b/patches/net/minecraft/client/gui/GuiGraphics.java.patch
index 60a00e141e..caca78e363 100644
--- a/patches/net/minecraft/client/gui/GuiGraphics.java.patch
+++ b/patches/net/minecraft/client/gui/GuiGraphics.java.patch
@@ -155,8 +155,9 @@
int i1 = vector2ic.y();
this.pose.pushPose();
int j1 = 400;
-+ net.neoforged.neoforge.client.event.RenderTooltipEvent.Color colorEvent = net.neoforged.neoforge.client.ClientHooks.onRenderTooltipColor(this.tooltipStack, this, l, i1, preEvent.getFont(), p_282615_);
- TooltipRenderUtil.renderTooltipBackground(this, l, i1, i, j, 400, p_371327_);
+- TooltipRenderUtil.renderTooltipBackground(this, l, i1, i, j, 400, p_371327_);
++ var textureEvent = net.neoforged.neoforge.client.ClientHooks.onRenderTooltipTexture(this.tooltipStack, this, l, i1, preEvent.getFont(), p_282615_, p_371327_);
++ TooltipRenderUtil.renderTooltipBackground(this, l, i1, i, j, 400, textureEvent.getTexture());
this.pose.translate(0.0F, 0.0F, 400.0F);
int k1 = i1;
diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
index a1b1166a57..0132b8a863 100644
--- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
+++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java
@@ -774,11 +774,8 @@ public static RenderTooltipEvent.Pre onRenderTooltipPre(ItemStack stack, GuiGrap
return preEvent;
}
- // TODO porting: potentially replace with a background texture event
- public static RenderTooltipEvent.Color onRenderTooltipColor(ItemStack stack, GuiGraphics graphics, int x, int y, Font font, List This event is {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.
* If this event is cancelled, then the list of components will be empty, causing the tooltip to not be rendered and
- * the corresponding {@link RenderTooltipEvent.Pre} and {@link RenderTooltipEvent.Color} to not be fired.
This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus}, * only on the {@linkplain LogicalSide#CLIENT logical client}.
@@ -179,7 +182,7 @@ public void setMaxWidth(int maxWidth) { * *This event is {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}. * If this event is cancelled, then the tooltip will not be rendered and the corresponding - * {@link RenderTooltipEvent.Color} will not be fired.
+ * {@link RenderTooltipEvent.Texture} will not be fired. * *This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus}, * only on the {@linkplain LogicalSide#CLIENT logical client}.
@@ -247,136 +250,51 @@ public void setY(int y) { } /** - * Fired when the colours for the tooltip background are determined. - * This can be used to modify the background color and the border's gradient colors. + * Fired when the textures for the tooltip background are determined. + * This can be used to modify the background and frame texture. * - *This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.
+ *This event is not {@linkplain ICancellableEvent cancellable}.
* *This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus}, * only on the {@linkplain LogicalSide#CLIENT logical client}.
*/ - public static class Color extends RenderTooltipEvent { - private final int originalBackground; - private final int originalBorderStart; - private final int originalBorderEnd; - private int backgroundStart; - private int backgroundEnd; - private int borderStart; - private int borderEnd; + public static class Texture extends RenderTooltipEvent { + @Nullable + private final ResourceLocation originalTexture; + @Nullable + private ResourceLocation texture; @ApiStatus.Internal - public Color(ItemStack stack, GuiGraphics graphics, int x, int y, Font fr, int background, int borderStart, int borderEnd, List+ * The given {@link ResourceLocation} will be prefixed with {@code tooltip/} and suffixed with {@code _background} + * and {@code _frame} to determine the background and frame texture respectively */ - public int getOriginalBorderEnd() { - return originalBorderEnd; + public void setTexture(@Nullable ResourceLocation texture) { + this.texture = texture; } } } diff --git a/tests/src/main/java/net/neoforged/neoforge/oldtest/client/CustomTooltipTest.java b/tests/src/main/java/net/neoforged/neoforge/oldtest/client/CustomTooltipTest.java index 1057944878..cb83eda472 100644 --- a/tests/src/main/java/net/neoforged/neoforge/oldtest/client/CustomTooltipTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/oldtest/client/CustomTooltipTest.java @@ -18,6 +18,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -115,6 +116,8 @@ public static void onRegisterClientTooltipComponentFactories(RegisterClientToolt } private static class ClientEventHandler { + private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(ID, "test"); + @SubscribeEvent public static void gatherTooltips(RenderTooltipEvent.GatherComponents event) { if (event.getItemStack().getItem() == Items.STICK) { @@ -126,12 +129,9 @@ public static void gatherTooltips(RenderTooltipEvent.GatherComponents event) { } @SubscribeEvent - public static void preTooltip(RenderTooltipEvent.Color event) { + public static void preTooltip(RenderTooltipEvent.Texture event) { if (event.getItemStack().getItem() == Items.APPLE) { - event.setBackgroundStart(0xFF0000FF); - event.setBackgroundEnd(0xFFFFFF00); - event.setBorderStart(0xFFFF0000); - event.setBorderEnd(0xFF000011); + event.setTexture(TEXTURE); } } } diff --git a/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png new file mode 100644 index 0000000000..1f5f803bf5 Binary files /dev/null and b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png differ diff --git a/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png.mcmeta b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png.mcmeta new file mode 100644 index 0000000000..c0435eb685 --- /dev/null +++ b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_background.png.mcmeta @@ -0,0 +1,11 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 100, + "height": 100, + "border": 9, + "stretch_inner": true + } + } +} diff --git a/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png new file mode 100644 index 0000000000..34c5e37f1a Binary files /dev/null and b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png differ diff --git a/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png.mcmeta b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png.mcmeta new file mode 100644 index 0000000000..e107d241a7 --- /dev/null +++ b/tests/src/main/resources/assets/custom_tooltip_test/textures/gui/sprites/tooltip/test_frame.png.mcmeta @@ -0,0 +1,11 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 100, + "height": 100, + "border": 10, + "stretch_inner": true + } + } +}