AdvancementTab.java

net.minecraft.client.gui.screens.advancements.AdvancementTab

信息

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

    TODO

字段/常量

  • minecraft

    • 类型: Minecraft
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • screen

    • 类型: AdvancementsScreen
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • type

    • 类型: AdvancementTabType
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • index

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

      TODO

  • rootNode

    • 类型: AdvancementNode
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • display

    • 类型: DisplayInfo
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • icon

    • 类型: ItemStack
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

  • title

    • 类型: Component
    • 修饰符: private final
    • 源码定位: L32
    • 说明:

      TODO

  • root

    • 类型: AdvancementWidget
    • 修饰符: private final
    • 源码定位: L33
    • 说明:

      TODO

  • widgets

    • 类型: Map<AdvancementHolder,AdvancementWidget>
    • 修饰符: private final
    • 源码定位: L34
    • 说明:

      TODO

  • scrollX

    • 类型: double
    • 修饰符: private
    • 源码定位: L35
    • 说明:

      TODO

  • scrollY

    • 类型: double
    • 修饰符: private
    • 源码定位: L36
    • 说明:

      TODO

  • minX

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

      TODO

  • minY

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

      TODO

  • maxX

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

      TODO

  • maxY

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

      TODO

  • fade

    • 类型: float
    • 修饰符: private
    • 源码定位: L41
    • 说明:

      TODO

  • centered

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L42
    • 说明:

      TODO

内部类/嵌套类型

构造器

public AdvancementTab(Minecraft minecraft, AdvancementsScreen screen, AdvancementTabType type, int index, AdvancementNode rootNode, DisplayInfo display) @ L44

  • 构造器名:AdvancementTab
  • 源码定位:L44
  • 修饰符:public

参数:

  • minecraft: Minecraft
  • screen: AdvancementsScreen
  • type: AdvancementTabType
  • index: int
  • rootNode: AdvancementNode
  • display: DisplayInfo

说明:

TODO

方法

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

public AdvancementTabType getType() @ L57

  • 方法名:getType
  • 源码定位:L57
  • 返回类型:AdvancementTabType
  • 修饰符:public

参数:

说明:

TODO

public int getIndex() @ L61

  • 方法名:getIndex
  • 源码定位:L61
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public AdvancementNode getRootNode() @ L65

  • 方法名:getRootNode
  • 源码定位:L65
  • 返回类型:AdvancementNode
  • 修饰符:public

参数:

说明:

TODO

public Component getTitle() @ L69

  • 方法名:getTitle
  • 源码定位:L69
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public DisplayInfo getDisplay() @ L73

  • 方法名:getDisplay
  • 源码定位:L73
  • 返回类型:DisplayInfo
  • 修饰符:public

参数:

说明:

TODO

public void extractTab(GuiGraphicsExtractor graphics, int xo, int yo, int mouseX, int mouseY, boolean selected) @ L77

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

参数:

  • graphics: GuiGraphicsExtractor
  • xo: int
  • yo: int
  • mouseX: int
  • mouseY: int
  • selected: boolean

说明:

TODO

public void extractIcon(GuiGraphicsExtractor graphics, int xo, int yo) @ L86

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

参数:

  • graphics: GuiGraphicsExtractor
  • xo: int
  • yo: int

说明:

TODO

public void extractContents(GuiGraphicsExtractor graphics, int windowLeft, int windowTop) @ L90

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

参数:

  • graphics: GuiGraphicsExtractor
  • windowLeft: int
  • windowTop: int

说明:

TODO

public void extractTooltips(GuiGraphicsExtractor graphics, int mouseX, int mouseY, int xo, int yo) @ L119

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

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • xo: int
  • yo: int

说明:

TODO

public boolean isMouseOver(int xo, int yo, double mx, double my) @ L141

  • 方法名:isMouseOver
  • 源码定位:L141
  • 返回类型:boolean
  • 修饰符:public

参数:

  • xo: int
  • yo: int
  • mx: double
  • my: double

说明:

TODO

public static AdvancementTab create(Minecraft minecraft, AdvancementsScreen screen, int index, AdvancementNode root) @ L145

  • 方法名:create
  • 源码定位:L145
  • 返回类型:AdvancementTab
  • 修饰符:public static

参数:

  • minecraft: Minecraft
  • screen: AdvancementsScreen
  • index: int
  • root: AdvancementNode

说明:

TODO

public void scroll(double x, double y) @ L162

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

参数:

  • x: double
  • y: double

说明:

TODO

public boolean canScrollHorizontally() @ L172

  • 方法名:canScrollHorizontally
  • 源码定位:L172
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean canScrollVertically() @ L176

  • 方法名:canScrollVertically
  • 源码定位:L176
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public void addAdvancement(AdvancementNode node) @ L180

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

参数:

  • node: AdvancementNode

说明:

TODO

private void addWidget(AdvancementWidget widget, AdvancementHolder advancement) @ L188

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

参数:

  • widget: AdvancementWidget
  • advancement: AdvancementHolder

说明:

TODO

public AdvancementWidget getWidget(AdvancementHolder advancement) @ L204

  • 方法名:getWidget
  • 源码定位:L204
  • 返回类型:AdvancementWidget
  • 修饰符:public

参数:

  • advancement: AdvancementHolder

说明:

TODO

public AdvancementsScreen getScreen() @ L208

  • 方法名:getScreen
  • 源码定位:L208
  • 返回类型:AdvancementsScreen
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class AdvancementTab {
    private final Minecraft minecraft;
    private final AdvancementsScreen screen;
    private final AdvancementTabType type;
    private final int index;
    private final AdvancementNode rootNode;
    private final DisplayInfo display;
    private final ItemStack icon;
    private final Component title;
    private final AdvancementWidget root;
    private final Map<AdvancementHolder, AdvancementWidget> widgets = Maps.newLinkedHashMap();
    private double scrollX;
    private double scrollY;
    private int minX = Integer.MAX_VALUE;
    private int minY = Integer.MAX_VALUE;
    private int maxX = Integer.MIN_VALUE;
    private int maxY = Integer.MIN_VALUE;
    private float fade;
    private boolean centered;
 
    public AdvancementTab(Minecraft minecraft, AdvancementsScreen screen, AdvancementTabType type, int index, AdvancementNode rootNode, DisplayInfo display) {
        this.minecraft = minecraft;
        this.screen = screen;
        this.type = type;
        this.index = index;
        this.rootNode = rootNode;
        this.display = display;
        this.icon = display.getIcon().create();
        this.title = display.getTitle();
        this.root = new AdvancementWidget(this, minecraft, rootNode, display);
        this.addWidget(this.root, rootNode.holder());
    }
 
    public AdvancementTabType getType() {
        return this.type;
    }
 
    public int getIndex() {
        return this.index;
    }
 
    public AdvancementNode getRootNode() {
        return this.rootNode;
    }
 
    public Component getTitle() {
        return this.title;
    }
 
    public DisplayInfo getDisplay() {
        return this.display;
    }
 
    public void extractTab(GuiGraphicsExtractor graphics, int xo, int yo, int mouseX, int mouseY, boolean selected) {
        int tabX = xo + this.type.getX(this.index);
        int tabY = yo + this.type.getY(this.index);
        this.type.extractRenderState(graphics, tabX, tabY, selected, this.index);
        if (!selected && mouseX > tabX && mouseY > tabY && mouseX < tabX + this.type.getWidth() && mouseY < tabY + this.type.getHeight()) {
            graphics.requestCursor(CursorTypes.POINTING_HAND);
        }
    }
 
    public void extractIcon(GuiGraphicsExtractor graphics, int xo, int yo) {
        this.type.extractIcon(graphics, xo, yo, this.index, this.icon);
    }
 
    public void extractContents(GuiGraphicsExtractor graphics, int windowLeft, int windowTop) {
        if (!this.centered) {
            this.scrollX = 117 - (this.maxX + this.minX) / 2;
            this.scrollY = 56 - (this.maxY + this.minY) / 2;
            this.centered = true;
        }
 
        graphics.enableScissor(windowLeft, windowTop, windowLeft + 234, windowTop + 113);
        graphics.pose().pushMatrix();
        graphics.pose().translate(windowLeft, windowTop);
        Identifier background = this.display.getBackground().map(ClientAsset.ResourceTexture::texturePath).orElse(TextureManager.INTENTIONAL_MISSING_TEXTURE);
        int intScrollX = Mth.floor(this.scrollX);
        int intScrollY = Mth.floor(this.scrollY);
        int left = intScrollX % 16;
        int top = intScrollY % 16;
 
        for (int x = -1; x <= 15; x++) {
            for (int y = -1; y <= 8; y++) {
                graphics.blit(RenderPipelines.GUI_TEXTURED, background, left + 16 * x, top + 16 * y, 0.0F, 0.0F, 16, 16, 16, 16);
            }
        }
 
        this.root.extractConnectivity(graphics, intScrollX, intScrollY, true);
        this.root.extractConnectivity(graphics, intScrollX, intScrollY, false);
        this.root.extractRenderState(graphics, intScrollX, intScrollY);
        graphics.pose().popMatrix();
        graphics.disableScissor();
    }
 
    public void extractTooltips(GuiGraphicsExtractor graphics, int mouseX, int mouseY, int xo, int yo) {
        graphics.fill(0, 0, 234, 113, Mth.floor(this.fade * 255.0F) << 24);
        boolean hovering = false;
        int intScrollX = Mth.floor(this.scrollX);
        int intScrollY = Mth.floor(this.scrollY);
        if (mouseX > 0 && mouseX < 234 && mouseY > 0 && mouseY < 113) {
            for (AdvancementWidget widget : this.widgets.values()) {
                if (widget.isMouseOver(intScrollX, intScrollY, mouseX, mouseY)) {
                    hovering = true;
                    widget.extractHover(graphics, intScrollX, intScrollY, this.fade, xo, yo);
                    break;
                }
            }
        }
 
        if (hovering) {
            this.fade = Mth.clamp(this.fade + 0.02F, 0.0F, 0.3F);
        } else {
            this.fade = Mth.clamp(this.fade - 0.04F, 0.0F, 1.0F);
        }
    }
 
    public boolean isMouseOver(int xo, int yo, double mx, double my) {
        return this.type.isMouseOver(xo, yo, this.index, mx, my);
    }
 
    public static @Nullable AdvancementTab create(Minecraft minecraft, AdvancementsScreen screen, int index, AdvancementNode root) {
        Optional<DisplayInfo> display = root.advancement().display();
        if (display.isEmpty()) {
            return null;
        } else {
            for (AdvancementTabType type : AdvancementTabType.values()) {
                if (index < type.getMax()) {
                    return new AdvancementTab(minecraft, screen, type, index, root, display.get());
                }
 
                index -= type.getMax();
            }
 
            return null;
        }
    }
 
    public void scroll(double x, double y) {
        if (this.canScrollHorizontally()) {
            this.scrollX = Mth.clamp(this.scrollX + x, (double)(-(this.maxX - 234)), 0.0);
        }
 
        if (this.canScrollVertically()) {
            this.scrollY = Mth.clamp(this.scrollY + y, (double)(-(this.maxY - 113)), 0.0);
        }
    }
 
    public boolean canScrollHorizontally() {
        return this.maxX - this.minX > 234;
    }
 
    public boolean canScrollVertically() {
        return this.maxY - this.minY > 113;
    }
 
    public void addAdvancement(AdvancementNode node) {
        Optional<DisplayInfo> display = node.advancement().display();
        if (!display.isEmpty()) {
            AdvancementWidget widget = new AdvancementWidget(this, this.minecraft, node, display.get());
            this.addWidget(widget, node.holder());
        }
    }
 
    private void addWidget(AdvancementWidget widget, AdvancementHolder advancement) {
        this.widgets.put(advancement, widget);
        int x0 = widget.getX();
        int x1 = x0 + 28;
        int y0 = widget.getY();
        int y1 = y0 + 27;
        this.minX = Math.min(this.minX, x0);
        this.maxX = Math.max(this.maxX, x1);
        this.minY = Math.min(this.minY, y0);
        this.maxY = Math.max(this.maxY, y1);
 
        for (AdvancementWidget other : this.widgets.values()) {
            other.attachToParent();
        }
    }
 
    public @Nullable AdvancementWidget getWidget(AdvancementHolder advancement) {
        return this.widgets.get(advancement);
    }
 
    public AdvancementsScreen getScreen() {
        return this.screen;
    }
}

引用的其他类