Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion patches/net/minecraft/client/gui/Gui.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -57,11 +58,30 @@ default boolean isVisibleInGui(MobEffectInstance instance) {
* @param y The y coordinate
* @param blitOffset The blit offset
* @return true to prevent default rendering, false otherwise
* @deprecated Use {@link 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;
}

/**
Comment thread
DBotThePony marked this conversation as resolved.
Outdated
* Renders 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.
*
Expand All @@ -72,11 +92,29 @@ default boolean renderInventoryIcon(MobEffectInstance instance, AbstractContaine
* @param y The y coordinate
* @param blitOffset The blit offset
* @return true to prevent default rendering, false otherwise
* @deprecated Use {@link 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 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.
Expand All @@ -89,8 +127,28 @@ default boolean renderInventoryText(MobEffectInstance instance, AbstractContaine
* @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 {@link 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;
}

/**
* 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 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
}
}
Loading