diff --git a/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch
index 9a2857019a..78c2a2b83e 100644
--- a/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch
+++ b/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch
@@ -82,11 +82,31 @@
}
public void setComponentTooltipForNextFrame(Font p_408650_, List This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
+ * This event is {@linkplain Cancellable cancellable}.
* 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.Background} to not be fired.
This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}, - * only on the {@linkplain LogicalSide#CLIENT logical client}.
+ * Fired only on the {@linkplain LogicalSide#CLIENT logical client}. */ public static final class GatherComponents extends MutableEvent implements Cancellable { public static final CancellableEventBusThis event is {@linkplain Cancelable 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.Background} will not be fired.
+ *This event is {@linkplain Cancellable cancellable}. + * If this event is cancelled, then the tooltip will not be rendered. * - *
This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}, - * only on the {@linkplain LogicalSide#CLIENT logical client}.
+ * Fired only on the {@linkplain LogicalSide#CLIENT logical client}. */ public static final class Pre extends RenderTooltipEvent implements Cancellable { public static final CancellableEventBus BUS = CancellableEventBus.create(Pre.class);
@@ -219,14 +215,20 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
private final int screenWidth;
private final int screenHeight;
private final ClientTooltipPositioner positioner;
+ @Nullable
+ private ResourceLocation background;
+ @Nullable
+ private final ResourceLocation originalBackground;
@ApiStatus.Internal
- public Pre(@NotNull ItemStack stack, GuiGraphics graphics, int x, int y, int screenWidth, int screenHeight, @NotNull Font font, @NotNull List components, @NotNull ClientTooltipPositioner positioner)
+ public Pre(@NotNull ItemStack stack, GuiGraphics graphics, int x, int y, int screenWidth, int screenHeight, @NotNull Font font, @NotNull List components, @NotNull ClientTooltipPositioner positioner, @Nullable ResourceLocation background)
{
super(stack, graphics, x, y, font, components);
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.positioner = positioner;
+ this.background = background;
+ this.originalBackground = background;
}
/**
@@ -282,17 +284,40 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
{
this.y = y;
}
- }
+ /**
+ * @return the potentially modified background's prefix, can be null for default
+ */
+ public @Nullable ResourceLocation getBackground() {
+ return background;
+ }
+
+ /**
+ * Sets the new prefix for the background texture
+ */
+ public void setBackground(@Nullable ResourceLocation background) {
+ this.background = background;
+ }
+
+ /**
+ * @return the original tooltip background's prefix, can be null for default
+ */
+ public @Nullable ResourceLocation getOriginalBackground() {
+ return originalBackground;
+ }
+ }
/**
* Fired when the tooltip background prefix is determined.
* This can be used to modify the textures to be used for the tooltip background.
*
- * This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
+ * This event is not {@linkplain Cancellable cancellable}.
*
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.
+ *
+ * @deprecated Behavior will be merged into {@link RenderTooltipEvent.Pre}.
*/
+ @Deprecated(forRemoval=true, since="1.21.10")
public static final class Background extends RenderTooltipEvent {
public static final EventBus BUS = EventBus.create(Background.class);
diff --git a/src/test/generated/closed_module/module-info.dat b/src/test/generated/closed_module/module-info.dat
index 27639b2fc4..5ab551c147 100644
Binary files a/src/test/generated/closed_module/module-info.dat and b/src/test/generated/closed_module/module-info.dat differ
diff --git a/src/test/generated/render_tooltip_test/data/forge/test_instance/render_tooltip_test/stack_present_in_pre.json b/src/test/generated/render_tooltip_test/data/forge/test_instance/render_tooltip_test/stack_present_in_pre.json
new file mode 100644
index 0000000000..83b5a0aa5a
--- /dev/null
+++ b/src/test/generated/render_tooltip_test/data/forge/test_instance/render_tooltip_test/stack_present_in_pre.json
@@ -0,0 +1,7 @@
+{
+ "type": "minecraft:function",
+ "environment": "minecraft:default",
+ "function": "forge:render_tooltip_test/stack_present_in_pre",
+ "max_ticks": 100,
+ "structure": "forge:empty3x3x3"
+}
\ No newline at end of file
diff --git a/src/test/java/net/minecraftforge/debug/client/RenderTooltipTest.java b/src/test/java/net/minecraftforge/debug/client/RenderTooltipTest.java
new file mode 100644
index 0000000000..720fa1023b
--- /dev/null
+++ b/src/test/java/net/minecraftforge/debug/client/RenderTooltipTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) Forge Development LLC and contributors
+ * SPDX-License-Identifier: LGPL-2.1-only
+ */
+
+package net.minecraftforge.debug.client;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.inventory.InventoryScreen;
+import net.minecraft.core.Holder;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.gametest.framework.GameTestHelper;
+import net.minecraft.world.entity.player.Inventory;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.Items;
+import net.minecraftforge.client.event.AddGuiOverlayLayersEvent;
+import net.minecraftforge.client.event.RenderTooltipEvent;
+import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
+import net.minecraftforge.gametest.GameTest;
+import net.minecraftforge.gametest.GameTestNamespace;
+import net.minecraftforge.test.BaseTestMod;
+
+import java.util.Random;
+
+@GameTestNamespace("forge")
+@Mod(RenderTooltipTest.MODID)
+public class RenderTooltipTest extends BaseTestMod {
+ public static final String MODID = "render_tooltip_test";
+ private static boolean testMode = false;
+ private static int shouldOpen = 0;
+ // Need some randomness so this test isn't asinine.
+ private static Object[] possibleChoices = BuiltInRegistries.ITEM.listElements().map(Holder::get).map(Item::getDefaultInstance).toArray();
+ private static int itemStack = 0;
+ private static ItemStack lastItemstackSeenInEvent = null;
+ public RenderTooltipTest(FMLJavaModLoadingContext context) {
+ super(context, false, false);
+ AddGuiOverlayLayersEvent.getBus(context.getModBusGroup()).addListener(event -> {
+ event.getLayeredDraw().addWithCondition(rl("render_tooltip_test"), (gg, dt) -> {
+ gg.setTooltipForNextFrame(Minecraft.getInstance().font, (ItemStack) possibleChoices[itemStack], 50, 50);
+ }, () -> testMode) ;
+ });
+
+ RenderTooltipEvent.Pre.BUS.addListener(event -> {
+ lastItemstackSeenInEvent = event.getItemStack();
+ });
+
+ TickEvent.RenderTickEvent.Pre.BUS.addListener(event -> {
+ // renderTooltip only runs if a screen is open so we have to open SOMETHING at SOME POINT for this test to work.
+ if (shouldOpen == 1) {
+ Minecraft.getInstance().setScreen(new InventoryScreen(Minecraft.getInstance().player));
+ shouldOpen = 2;
+ } else if (shouldOpen == 2) {
+ Minecraft.getInstance().setScreen(null);
+ shouldOpen = 0;
+ }
+ });
+ }
+
+ @GameTest
+ public static void stack_present_in_pre(GameTestHelper helper) {
+ testMode = true;
+ shouldOpen = 1;
+ itemStack = new Random().nextInt(possibleChoices.length);
+ helper.runAfterDelay(10, () -> {
+ testMode = false;
+ var copyOfLastSeen = lastItemstackSeenInEvent;
+ boolean testPassed = lastItemstackSeenInEvent == possibleChoices[itemStack];
+ lastItemstackSeenInEvent = null;
+ helper.assertTrue(testPassed, "Itemstack from last tooltip was not correct. Was " + copyOfLastSeen + " expected " + possibleChoices[itemStack]);
+ helper.succeed();
+ });
+ }
+}
diff --git a/src/test/resources/render_tooltip_test/META-INF/mods.toml b/src/test/resources/render_tooltip_test/META-INF/mods.toml
new file mode 100644
index 0000000000..c361869e8e
--- /dev/null
+++ b/src/test/resources/render_tooltip_test/META-INF/mods.toml
@@ -0,0 +1 @@
+clientSideOnly=true
\ No newline at end of file