diff --git a/patches/net/minecraft/client/gui/Gui.java.patch b/patches/net/minecraft/client/gui/Gui.java.patch index 35244230158..e31c381c5df 100644 --- a/patches/net/minecraft/client/gui/Gui.java.patch +++ b/patches/net/minecraft/client/gui/Gui.java.patch @@ -158,7 +158,7 @@ } } -+ if (renderer.renderGuiIcon(instance, this, graphics, x, y, 0, alpha)) continue; ++ if (renderer.extractGuiIcon(instance, this, graphics, x + 3, y + 3, 18, 18, ARGB.white(alpha))) continue; graphics.blitSprite(RenderPipelines.GUI_TEXTURED, getMobEffectSprite(effect), x + 3, y + 3, 18, 18, ARGB.white(alpha)); } } diff --git a/patches/net/minecraft/client/gui/screens/inventory/EffectsInInventory.java.patch b/patches/net/minecraft/client/gui/screens/inventory/EffectsInInventory.java.patch index 983550d018d..4305513ce28 100644 --- a/patches/net/minecraft/client/gui/screens/inventory/EffectsInInventory.java.patch +++ b/patches/net/minecraft/client/gui/screens/inventory/EffectsInInventory.java.patch @@ -27,9 +27,9 @@ Component duration = MobEffectUtil.formatDuration(effect, 1.0F, this.minecraft.level.tickRateManager().tickrate()); int textureWidth = this.extractBackground(graphics, font, effectText, duration, x0, y0, isAmbient, maxWidth); - this.extractText(graphics, effectText, duration, font, x0, y0, textureWidth, yStep, mouseX, mouseY); -+ if (!renderer.renderInventoryText(effect, screen, graphics, x0, y0, 0)) -+ this.renderText(graphics, effectText, duration, font, x0, y0, textureWidth, yStep, mouseX, mouseY, effect); -+ if (!renderer.renderInventoryIcon(effect, screen, graphics, x0 + 7, y0, 0)) ++ if (!renderer.extractInventoryText(effect, screen, graphics, x0 + 32, y0 + 7, textureWidth - 32 - 7, net.minecraft.util.CommonColors.WHITE)) ++ this.extractText(graphics, effectText, duration, font, x0, y0, textureWidth, yStep, mouseX, mouseY, effect); ++ if (!renderer.extractInventoryIcon(effect, screen, graphics, x0 + 7, y0 + 7, 18, 18, net.minecraft.util.CommonColors.WHITE)) graphics.blitSprite(RenderPipelines.GUI_TEXTURED, Gui.getMobEffectSprite(effect.getEffect()), x0 + 7, y0 + 7, 18, 18); y0 += yStep; } @@ -41,9 +41,9 @@ private void extractText( GuiGraphicsExtractor graphics, Component effectText, Component duration, Font font, int x0, int y0, int textureWidth, int yStep, int mouseX, int mouseY ) { -+ renderText(graphics, effectText, duration, font, x0, y0, textureWidth, yStep, mouseX, mouseY, null); ++ extractText(graphics, effectText, duration, font, x0, y0, textureWidth, yStep, mouseX, mouseY, null); + } -+ private void renderText( ++ private void extractText( + GuiGraphicsExtractor graphics, Component effectText, Component duration, Font font, int x0, int y0, int textureWidth, int yStep, int mouseX, int mouseY, @org.jspecify.annotations.Nullable MobEffectInstance effectInstance + ) { int textX = x0 + 32; diff --git a/src/client/java/net/neoforged/neoforge/client/extensions/common/IClientMobEffectExtensions.java b/src/client/java/net/neoforged/neoforge/client/extensions/common/IClientMobEffectExtensions.java index 529e4dad2e1..c5e68918dba 100644 --- a/src/client/java/net/neoforged/neoforge/client/extensions/common/IClientMobEffectExtensions.java +++ b/src/client/java/net/neoforged/neoforge/client/extensions/common/IClientMobEffectExtensions.java @@ -8,15 +8,14 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.util.ARGB; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.neoforged.fml.LogicalSide; -/** - * {@linkplain LogicalSide#CLIENT Client-only} extensions to {@link MobEffect}. - * - * @see RegisterClientExtensionsEvent - */ +/// [Client-only][LogicalSide#CLIENT] extensions to [MobEffect]. +/// +/// @see RegisterClientExtensionsEvent public interface IClientMobEffectExtensions { IClientMobEffectExtensions DEFAULT = new IClientMobEffectExtensions() {}; @@ -28,69 +27,108 @@ static IClientMobEffectExtensions of(MobEffect effect) { return ClientExtensionsManager.MOB_EFFECT_EXTENSIONS.getOrDefault(effect, DEFAULT); } - /** - * Queries whether the given effect should be shown in the player's inventory. - *
- * By default, this returns {@code true}. - */ + /// @return Whether the given effect should be shown in the player's inventory + /// @implNote By default, this returns `true`. default boolean isVisibleInInventory(MobEffectInstance instance) { return true; } - /** - * Queries whether the given effect should be shown in the HUD. - *
- * By default, this returns {@code true}. - */ + /// @return Whether the given effect should be shown in the HUD + /// @implNote By default, this returns `true`. default boolean isVisibleInGui(MobEffectInstance instance) { return true; } - /** - * Renders the icon of the specified effect in the player's inventory. - * This can be used to render icons from your own texture sheet. - * - * @param instance The effect instance - * @param screen The effect-rendering screen - * @param guiGraphics The gui graphics - * @param x The x coordinate - * @param y The y coordinate - * @param blitOffset The blit offset - * @return true to prevent default rendering, false otherwise - */ + /// Renders the icon of the specified effect in the player's inventory. + /// This can be used to render icons from your own texture sheet. + /// + /// @param instance The effect instance + /// @param screen The effect-rendering screen + /// @param guiGraphics The gui graphics + /// @param x The x coordinate + /// @param y The y coordinate + /// @param blitOffset The blit offset + /// @return `true` to prevent default rendering, `false` otherwise + /// @deprecated Use [IClientMobEffectExtensions#extractInventoryIcon] + @Deprecated(forRemoval = true, since = "26.1.2") default boolean renderInventoryIcon(MobEffectInstance instance, AbstractContainerScreen> screen, GuiGraphicsExtractor guiGraphics, int x, int y, int blitOffset) { return false; } - /** - * Renders the text of the specified effect in the player's inventory. - * - * @param instance The effect instance - * @param screen The effect-rendering screen - * @param guiGraphics The gui graphics - * @param x The x coordinate - * @param y The y coordinate - * @param blitOffset The blit offset - * @return true to prevent default rendering, false otherwise - */ + /// Extracts the icon of the specified effect in the player's inventory. + /// + /// @param instance The effect instance + /// @param screen The effect-rendering screen + /// @param graphics The gui graphics + /// @param x The x coordinate to render at + /// @param y The y coordinate to render at + /// @param width Available width of canvas to render in + /// @param height Available height of canvas to render in + /// @param color Color multiplicator of the icon + /// @return `true` to prevent default rendering, `false` otherwise + default boolean extractInventoryIcon(MobEffectInstance instance, AbstractContainerScreen> screen, GuiGraphicsExtractor graphics, int x, int y, int width, int height, int color) { + return renderInventoryIcon(instance, screen, graphics, x, y - 7, 0); // -7 for renderInventoryIcon() to receive improperly aligned argument to not break existing mods + } + + /// Renders the text of the specified effect in the player's inventory. + /// + /// @param instance The effect instance + /// @param screen The effect-rendering screen + /// @param guiGraphics The gui graphics + /// @param x The x coordinate + /// @param y The y coordinate + /// @param blitOffset The blit offset + /// @return `true` to prevent default rendering, `false` otherwise + /// @deprecated Use [IClientMobEffectExtensions#extractInventoryText] + @Deprecated(forRemoval = true, since = "26.1.2") default boolean renderInventoryText(MobEffectInstance instance, AbstractContainerScreen> screen, GuiGraphicsExtractor guiGraphics, int x, int y, int blitOffset) { return false; } - /** - * Renders the icon of the specified effect on the player's HUD. - * This can be used to render icons from your own texture sheet. - * - * @param instance The effect instance - * @param gui The gui - * @param guiGraphics The gui graphics - * @param x The x coordinate - * @param y The y coordinate - * @param z The z depth - * @param alpha The alpha value. Blinks when the effect is about to run out - * @return true to prevent default rendering, false otherwise - */ + /// Extracts the text of the specified effect in the player's inventory. + /// + /// @param instance The effect instance + /// @param screen The effect-rendering screen + /// @param graphics The gui graphics + /// @param x The x coordinate + /// @param y The y coordinate + /// @param canvasWidth Available pixels, rendering anything wider than this amount of pixels may overlap with other GUI elements or go out of bounds + /// @param color Desired color of text, serving as a hint of best color to use for it to be distinct from background + /// @return `true` to prevent default rendering, `false` otherwise + default boolean extractInventoryText(MobEffectInstance instance, AbstractContainerScreen> screen, GuiGraphicsExtractor graphics, int x, int y, int canvasWidth, int color) { + return renderInventoryText(instance, screen, graphics, x - 32, y - 7, 0); // -32 and -7 for renderInventoryText() to receive improperly aligned arguments to not break existing mods + } + + /// Renders the icon of the specified effect on the player's HUD. + /// This can be used to render icons from your own texture sheet. + /// + /// @param instance The effect instance + /// @param gui The gui + /// @param guiGraphics The gui graphics + /// @param x The x coordinate + /// @param y The y coordinate + /// @param z The z depth + /// @param alpha The alpha value. Blinks when the effect is about to run out + /// @return `true` to prevent default rendering, `false` otherwise + /// @deprecated Use [IClientMobEffectExtensions#extractGuiIcon] + @Deprecated(forRemoval = true, since = "26.1.2") default boolean renderGuiIcon(MobEffectInstance instance, Gui gui, GuiGraphicsExtractor guiGraphics, int x, int y, float z, float alpha) { return false; } + + /// Extracts the icon of the specified effect on the player's HUD. + /// This can be used to render icons from your own texture sheet. + /// + /// @param instance The effect instance + /// @param gui The gui + /// @param graphics The gui graphics + /// @param x The x coordinate + /// @param y The y coordinate + /// @param width Available width of canvas to render in + /// @param height Available height of canvas to render in + /// @param color Color multiplicator of the icon + /// @return `true` to prevent default rendering, `false` otherwise + default boolean extractGuiIcon(MobEffectInstance instance, Gui gui, GuiGraphicsExtractor graphics, int x, int y, int width, int height, int color) { + return renderGuiIcon(instance, gui, graphics, x - 3, y - 3, 0f, ARGB.alpha(color) / 255f); // -3 for renderGuiIcon() to receive improperly aligned arguments to not break existing mods + } }