Class ItemOpacityRenderer

java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.gui.ItemOpacityRenderer

public final class ItemOpacityRenderer extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    An opacity eased from one value to another over a time, for an item fading in or out.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    render(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.world.item.ItemStack stack, int x, int y, float opacity)
    Draws an item as GuiGraphics.renderFakeItem(net.minecraft.world.item.ItemStack, int, int) does, at an opacity from 0 to 1.
    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.
    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.
    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.
    static void
    withOpacity(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 as GuiGraphics.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

      public static void withOpacity(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. Nothing is drawn at 0. The shader color is put back after.