CyclingSlotBackground.java

net.minecraft.client.gui.screens.inventory.CyclingSlotBackground

信息

  • 全限定名:net.minecraft.client.gui.screens.inventory.CyclingSlotBackground
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.inventory
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/CyclingSlotBackground.java
  • 起始行号:L14
  • 职责:

    TODO

字段/常量

  • ICON_CHANGE_TICK_RATE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

  • ICON_SIZE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

  • ICON_TRANSITION_TICK_DURATION

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • slotIndex

    • 类型: int
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • icons

    • 类型: List<Identifier>
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • tick

    • 类型: int
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • iconIndex

    • 类型: int
    • 修饰符: private
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

public CyclingSlotBackground(int slotIndex) @ L23

  • 构造器名:CyclingSlotBackground
  • 源码定位:L23
  • 修饰符:public

参数:

  • slotIndex: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void tick(List<Identifier> newIcons) @ L27

  • 方法名:tick
  • 源码定位:L27
  • 返回类型:void
  • 修饰符:public

参数:

  • newIcons: List

说明:

TODO

public void extractRenderState(AbstractContainerMenu menu, GuiGraphicsExtractor graphics, float a, int left, int top) @ L38

  • 方法名:extractRenderState
  • 源码定位:L38
  • 返回类型:void
  • 修饰符:public

参数:

  • menu: AbstractContainerMenu
  • graphics: GuiGraphicsExtractor
  • a: float
  • left: int
  • top: int

说明:

TODO

private void extractIcon(Slot slot, Identifier iconIdentifier, float alphaProgress, GuiGraphicsExtractor graphics, int left, int top) @ L52

  • 方法名:extractIcon
  • 源码定位:L52
  • 返回类型:void
  • 修饰符:private

参数:

  • slot: Slot
  • iconIdentifier: Identifier
  • alphaProgress: float
  • graphics: GuiGraphicsExtractor
  • left: int
  • top: int

说明:

TODO

private float getIconTransitionTransparency(float a) @ L56

  • 方法名:getIconTransitionTransparency
  • 源码定位:L56
  • 返回类型:float
  • 修饰符:private

参数:

  • a: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CyclingSlotBackground {
    private static final int ICON_CHANGE_TICK_RATE = 30;
    private static final int ICON_SIZE = 16;
    private static final int ICON_TRANSITION_TICK_DURATION = 4;
    private final int slotIndex;
    private List<Identifier> icons = List.of();
    private int tick;
    private int iconIndex;
 
    public CyclingSlotBackground(int slotIndex) {
        this.slotIndex = slotIndex;
    }
 
    public void tick(List<Identifier> newIcons) {
        if (!this.icons.equals(newIcons)) {
            this.icons = newIcons;
            this.iconIndex = 0;
        }
 
        if (!this.icons.isEmpty() && ++this.tick % 30 == 0) {
            this.iconIndex = (this.iconIndex + 1) % this.icons.size();
        }
    }
 
    public void extractRenderState(AbstractContainerMenu menu, GuiGraphicsExtractor graphics, float a, int left, int top) {
        Slot slot = menu.getSlot(this.slotIndex);
        if (!this.icons.isEmpty() && !slot.hasItem()) {
            boolean shouldTransition = this.icons.size() > 1 && this.tick >= 30;
            float alphaProgress = shouldTransition ? this.getIconTransitionTransparency(a) : 1.0F;
            if (alphaProgress < 1.0F) {
                int previousIconIndex = Math.floorMod(this.iconIndex - 1, this.icons.size());
                this.extractIcon(slot, this.icons.get(previousIconIndex), 1.0F - alphaProgress, graphics, left, top);
            }
 
            this.extractIcon(slot, this.icons.get(this.iconIndex), alphaProgress, graphics, left, top);
        }
    }
 
    private void extractIcon(Slot slot, Identifier iconIdentifier, float alphaProgress, GuiGraphicsExtractor graphics, int left, int top) {
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, iconIdentifier, left + slot.x, top + slot.y, 16, 16, ARGB.white(alphaProgress));
    }
 
    private float getIconTransitionTransparency(float a) {
        float elapsedTransitionTime = this.tick % 30 + a;
        return Math.min(elapsedTransitionTime, 4.0F) / 4.0F;
    }
}

引用的其他类