Class ItemOpacityRenderer
java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.gui.ItemOpacityRenderer
Items drawn in a GUI at an opacity, fixed or animated: a HUD card fading in with its icon, a slot greying out.
ItemOpacityRenderer.render(graphics, stack, x, y, 0.5F); // half see-through
ItemOpacityRenderer.renderWithDecorations(graphics, font, stack, x, y, 0.5F); // with its count and bar
var fade = ItemOpacityRenderer.OpacityTween.in(10).start(); // keep it, and draw each frame:
ItemOpacityRenderer.render(graphics, stack, x, y, fade);
ItemOpacityRenderer.withOpacity(0.5F, () -> graphics.renderItem(stack, x, y)); // anything that draws items
The game draws most items solid (blocks, beds, anything with a block entity model), which an alpha can't see
through: it only darkens them. So while the shader color's alpha is under 1, every item a GuiGraphics draws
is drawn with a see-through version of its render type (the same texture, translucent), and fades as flat items do;
enchantment glints stay as they are. That holds for items the game itself draws too, so a mod that fades a part of
the HUD through the shader color fades its items with it.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn opacity eased from one value to another over a time, for an item fading in or out. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidrender(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.world.item.ItemStack stack, int x, int y, float opacity) Draws an item asGuiGraphics.renderFakeItem(net.minecraft.world.item.ItemStack, int, int)does, at an opacity from 0 to 1.static voidrender(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.world.item.ItemStack stack, int x, int y, ItemOpacityRenderer.OpacityTween fade) Draws an item at the opacity a fade is at now.static voidrenderWithDecorations(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, net.minecraft.world.item.ItemStack stack, int x, int y, float opacity) Draws an item with its count and durability bar, as a slot shows it, at an opacity from 0 to 1.static voidrenderWithDecorations(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, net.minecraft.world.item.ItemStack stack, int x, int y, ItemOpacityRenderer.OpacityTween fade) Draws an item with its count and durability bar at the opacity a fade is at now.static voidwithOpacity(float opacity, Runnable draw) Runs drawing at an opacity from 0 to 1: the shader color's alpha is scaled by it meanwhile, so the items drawn (and the text and sprites, which already fade by it) are see-through.
-
Method Details
-
render
public static void render(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.world.item.ItemStack stack, int x, int y, float opacity) Draws an item asGuiGraphics.renderFakeItem(net.minecraft.world.item.ItemStack, int, int)does, at an opacity from 0 to 1. -
render
public static void render(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.world.item.ItemStack stack, int x, int y, ItemOpacityRenderer.OpacityTween fade) Draws an item at the opacity a fade is at now. -
renderWithDecorations
public static void renderWithDecorations(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, net.minecraft.world.item.ItemStack stack, int x, int y, float opacity) Draws an item with its count and durability bar, as a slot shows it, at an opacity from 0 to 1. -
renderWithDecorations
public static void renderWithDecorations(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, net.minecraft.world.item.ItemStack stack, int x, int y, ItemOpacityRenderer.OpacityTween fade) Draws an item with its count and durability bar at the opacity a fade is at now. -
withOpacity
Runs drawing at an opacity from 0 to 1: the shader color's alpha is scaled by it meanwhile, so the items drawn (and the text and sprites, which already fade by it) are see-through. Nothing is drawn at 0. The shader color is put back after.
-