GuiRenderState.java

net.minecraft.client.renderer.state.gui.GuiRenderState

信息

  • 全限定名:net.minecraft.client.renderer.state.gui.GuiRenderState
  • 类型:public class
  • 包:net.minecraft.client.renderer.state.gui
  • 源码路径:src/main/java/net/minecraft/client/renderer/state/gui/GuiRenderState.java
  • 起始行号:L21
  • 职责:

    TODO

字段/常量

  • DEBUG_RECTANGLE_COLOR

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

      TODO

  • strata

    • 类型: List<GuiRenderState.Node>
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • firstStratumAfterBlur

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

      TODO

  • current

    • 类型: GuiRenderState.Node
    • 修饰符: private
    • 源码定位: L25
    • 说明:

      TODO

  • itemModelIdentities

    • 类型: Set<Object>
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • lastElementBounds

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

      TODO

  • panoramaRenderState

    • 类型: PanoramaRenderState
    • 修饰符: public
    • 源码定位: L28
    • 说明:

      TODO

  • clearColorOverride

    • 类型: int
    • 修饰符: public
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.renderer.state.gui.GuiRenderState.Node

    • 类型: class
    • 修饰符: private static
    • 源码定位: L270
    • 说明:

      TODO

  • net.minecraft.client.renderer.state.gui.GuiRenderState.TraverseRange

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L325
    • 说明:

      TODO

构造器

public GuiRenderState() @ L31

  • 构造器名:GuiRenderState
  • 源码定位:L31
  • 修饰符:public

参数:

说明:

TODO

方法

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

public void nextStratum() @ L35

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

参数:

说明:

TODO

public void blurBeforeThisStratum() @ L40

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

参数:

说明:

TODO

public void up() @ L48

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

参数:

说明:

TODO

public void addItem(GuiItemRenderState itemState) @ L56

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

参数:

  • itemState: GuiItemRenderState

说明:

TODO

public void addText(GuiTextRenderState textState) @ L64

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

参数:

  • textState: GuiTextRenderState

说明:

TODO

public void addPicturesInPictureState(PictureInPictureRenderState picturesInPictureState) @ L71

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

参数:

  • picturesInPictureState: PictureInPictureRenderState

说明:

TODO

public void addGuiElement(GuiElementRenderState blitState) @ L78

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

参数:

  • blitState: GuiElementRenderState

说明:

TODO

private void addDebugRectangleIfEnabled(ScreenRectangle bounds) @ L85

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

参数:

  • bounds: ScreenRectangle

说明:

TODO

private boolean findAppropriateNode(ScreenArea screenArea) @ L97

  • 方法名:findAppropriateNode
  • 源码定位:L97
  • 返回类型:boolean
  • 修饰符:private

参数:

  • screenArea: ScreenArea

说明:

TODO

private void navigateToAboveHighestElementWithIntersectingBounds(ScreenRectangle bounds) @ L113

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

参数:

  • bounds: ScreenRectangle

说明:

TODO

private boolean hasIntersection(ScreenRectangle bounds, List<?extends ScreenArea> states) @ L142

  • 方法名:hasIntersection
  • 源码定位:L142
  • 返回类型:boolean
  • 修饰符:private

参数:

  • bounds: ScreenRectangle
  • states: List<?extends ScreenArea>

说明:

TODO

public void addBlitToCurrentLayer(BlitRenderState blitState) @ L155

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

参数:

  • blitState: BlitRenderState

说明:

TODO

public void addGlyphToCurrentLayer(GuiElementRenderState glyphState) @ L159

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

参数:

  • glyphState: GuiElementRenderState

说明:

TODO

public Set<Object> getItemModelIdentities() @ L163

  • 方法名:getItemModelIdentities
  • 源码定位:L163
  • 返回类型:Set
  • 修饰符:public
  • 参数:

    说明:

    TODO

    public void forEachElement(Consumer<GuiElementRenderState> consumer, GuiRenderState.TraverseRange range) @ L167

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

    参数:

    • consumer: Consumer
    • range: GuiRenderState.TraverseRange

    说明:

    TODO

    public void forEachItem(Consumer<GuiItemRenderState> consumer) @ L185

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

    参数:

    • consumer: Consumer

    说明:

    TODO

    public void forEachText(Consumer<GuiTextRenderState> consumer) @ L199

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

    参数:

    • consumer: Consumer

    说明:

    TODO

    public void forEachPictureInPicture(Consumer<PictureInPictureRenderState> consumer) @ L212

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

    参数:

    • consumer: Consumer

    说明:

    TODO

    public void sortElements(Comparator<GuiElementRenderState> comparator) @ L226

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

    参数:

    • comparator: Comparator

    说明:

    TODO

    private void traverse(Consumer<GuiRenderState.Node> consumer, GuiRenderState.TraverseRange range) @ L238

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

    参数:

    • consumer: Consumer<GuiRenderState.Node>
    • range: GuiRenderState.TraverseRange

    说明:

    TODO

    private void traverse(GuiRenderState.Node node, Consumer<GuiRenderState.Node> consumer) @ L253

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

    参数:

    • node: GuiRenderState.Node
    • consumer: Consumer<GuiRenderState.Node>

    说明:

    TODO

    public void reset() @ L260

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

    参数:

    说明:

    TODO

    代码

    @OnlyIn(Dist.CLIENT)
    public class GuiRenderState {
        private static final int DEBUG_RECTANGLE_COLOR = 2000962815;
        private final List<GuiRenderState.Node> strata = new ArrayList<>();
        private int firstStratumAfterBlur = Integer.MAX_VALUE;
        private GuiRenderState.Node current;
        private final Set<Object> itemModelIdentities = new HashSet<>();
        private @Nullable ScreenRectangle lastElementBounds;
        public @Nullable PanoramaRenderState panoramaRenderState;
        public int clearColorOverride;
     
        public GuiRenderState() {
            this.nextStratum();
        }
     
        public void nextStratum() {
            this.current = new GuiRenderState.Node(null);
            this.strata.add(this.current);
        }
     
        public void blurBeforeThisStratum() {
            if (this.firstStratumAfterBlur != Integer.MAX_VALUE) {
                throw new IllegalStateException("Can only blur once per frame");
            } else {
                this.firstStratumAfterBlur = this.strata.size() - 1;
            }
        }
     
        public void up() {
            if (this.current.up == null) {
                this.current.up = new GuiRenderState.Node(this.current);
            }
     
            this.current = this.current.up;
        }
     
        public void addItem(GuiItemRenderState itemState) {
            if (this.findAppropriateNode(itemState)) {
                this.itemModelIdentities.add(itemState.itemStackRenderState().getModelIdentity());
                this.current.addItem(itemState);
                this.addDebugRectangleIfEnabled(itemState.bounds());
            }
        }
     
        public void addText(GuiTextRenderState textState) {
            if (this.findAppropriateNode(textState)) {
                this.current.addText(textState);
                this.addDebugRectangleIfEnabled(textState.bounds());
            }
        }
     
        public void addPicturesInPictureState(PictureInPictureRenderState picturesInPictureState) {
            if (this.findAppropriateNode(picturesInPictureState)) {
                this.current.addPicturesInPictureState(picturesInPictureState);
                this.addDebugRectangleIfEnabled(picturesInPictureState.bounds());
            }
        }
     
        public void addGuiElement(GuiElementRenderState blitState) {
            if (this.findAppropriateNode(blitState)) {
                this.current.addGuiElement(blitState);
                this.addDebugRectangleIfEnabled(blitState.bounds());
            }
        }
     
        private void addDebugRectangleIfEnabled(@Nullable ScreenRectangle bounds) {
            if (SharedConstants.DEBUG_RENDER_UI_LAYERING_RECTANGLES && bounds != null) {
                this.up();
                this.current
                    .addGuiElement(
                        new ColoredRectangleRenderState(
                            RenderPipelines.GUI, TextureSetup.noTexture(), new Matrix3x2f(), 0, 0, 10000, 10000, 2000962815, 2000962815, bounds
                        )
                    );
            }
        }
     
        private boolean findAppropriateNode(ScreenArea screenArea) {
            ScreenRectangle bounds = screenArea.bounds();
            if (bounds == null) {
                return false;
            } else {
                if (this.lastElementBounds != null && this.lastElementBounds.encompasses(bounds)) {
                    this.up();
                } else {
                    this.navigateToAboveHighestElementWithIntersectingBounds(bounds);
                }
     
                this.lastElementBounds = bounds;
                return true;
            }
        }
     
        private void navigateToAboveHighestElementWithIntersectingBounds(ScreenRectangle bounds) {
            GuiRenderState.Node node = this.strata.getLast();
     
            while (node.up != null) {
                node = node.up;
            }
     
            boolean found = false;
     
            while (!found) {
                found = this.hasIntersection(bounds, node.elementStates)
                    || this.hasIntersection(bounds, node.itemStates)
                    || this.hasIntersection(bounds, node.textStates)
                    || this.hasIntersection(bounds, node.picturesInPictureStates);
                if (node.parent == null) {
                    break;
                }
     
                if (!found) {
                    node = node.parent;
                }
            }
     
            this.current = node;
            if (found) {
                this.up();
            }
        }
     
        private boolean hasIntersection(ScreenRectangle bounds, @Nullable List<? extends ScreenArea> states) {
            if (states != null) {
                for (ScreenArea area : states) {
                    ScreenRectangle existingBounds = area.bounds();
                    if (existingBounds != null && existingBounds.intersects(bounds)) {
                        return true;
                    }
                }
            }
     
            return false;
        }
     
        public void addBlitToCurrentLayer(BlitRenderState blitState) {
            this.current.addGuiElement(blitState);
        }
     
        public void addGlyphToCurrentLayer(GuiElementRenderState glyphState) {
            this.current.addGlyph(glyphState);
        }
     
        public Set<Object> getItemModelIdentities() {
            return this.itemModelIdentities;
        }
     
        public void forEachElement(Consumer<GuiElementRenderState> consumer, GuiRenderState.TraverseRange range) {
            this.traverse(node -> {
                if (node.elementStates != null || node.glyphStates != null) {
                    if (node.elementStates != null) {
                        for (GuiElementRenderState elementState : node.elementStates) {
                            consumer.accept(elementState);
                        }
                    }
     
                    if (node.glyphStates != null) {
                        for (GuiElementRenderState glyphState : node.glyphStates) {
                            consumer.accept(glyphState);
                        }
                    }
                }
            }, range);
        }
     
        public void forEachItem(Consumer<GuiItemRenderState> consumer) {
            GuiRenderState.Node currentBackup = this.current;
            this.traverse(node -> {
                if (node.itemStates != null) {
                    this.current = node;
     
                    for (GuiItemRenderState itemState : node.itemStates) {
                        consumer.accept(itemState);
                    }
                }
            }, GuiRenderState.TraverseRange.ALL);
            this.current = currentBackup;
        }
     
        public void forEachText(Consumer<GuiTextRenderState> consumer) {
            GuiRenderState.Node currentBackup = this.current;
            this.traverse(node -> {
                if (node.textStates != null) {
                    for (GuiTextRenderState textState : node.textStates) {
                        this.current = node;
                        consumer.accept(textState);
                    }
                }
            }, GuiRenderState.TraverseRange.ALL);
            this.current = currentBackup;
        }
     
        public void forEachPictureInPicture(Consumer<PictureInPictureRenderState> consumer) {
            GuiRenderState.Node currentBackup = this.current;
            this.traverse(node -> {
                if (node.picturesInPictureStates != null) {
                    this.current = node;
     
                    for (PictureInPictureRenderState pictureInPictureState : node.picturesInPictureStates) {
                        consumer.accept(pictureInPictureState);
                    }
                }
            }, GuiRenderState.TraverseRange.ALL);
            this.current = currentBackup;
        }
     
        public void sortElements(Comparator<GuiElementRenderState> comparator) {
            this.traverse(node -> {
                if (node.elementStates != null) {
                    if (SharedConstants.DEBUG_SHUFFLE_UI_RENDERING_ORDER) {
                        Collections.shuffle(node.elementStates);
                    }
     
                    node.elementStates.sort(comparator);
                }
            }, GuiRenderState.TraverseRange.ALL);
        }
     
        private void traverse(Consumer<GuiRenderState.Node> consumer, GuiRenderState.TraverseRange range) {
            int startIndex = 0;
            int endIndex = this.strata.size();
            if (range == GuiRenderState.TraverseRange.BEFORE_BLUR) {
                endIndex = Math.min(this.firstStratumAfterBlur, this.strata.size());
            } else if (range == GuiRenderState.TraverseRange.AFTER_BLUR) {
                startIndex = this.firstStratumAfterBlur;
            }
     
            for (int i = startIndex; i < endIndex; i++) {
                GuiRenderState.Node stratum = this.strata.get(i);
                this.traverse(stratum, consumer);
            }
        }
     
        private void traverse(GuiRenderState.Node node, Consumer<GuiRenderState.Node> consumer) {
            consumer.accept(node);
            if (node.up != null) {
                this.traverse(node.up, consumer);
            }
        }
     
        public void reset() {
            this.itemModelIdentities.clear();
            this.strata.clear();
            this.firstStratumAfterBlur = Integer.MAX_VALUE;
            this.nextStratum();
            this.panoramaRenderState = null;
            this.clearColorOverride = 0;
        }
     
        @OnlyIn(Dist.CLIENT)
        private static class Node {
            public final GuiRenderState.@Nullable Node parent;
            public GuiRenderState.@Nullable Node up;
            public @Nullable List<GuiElementRenderState> elementStates;
            public @Nullable List<GuiElementRenderState> glyphStates;
            public @Nullable List<GuiItemRenderState> itemStates;
            public @Nullable List<GuiTextRenderState> textStates;
            public @Nullable List<PictureInPictureRenderState> picturesInPictureStates;
     
            private Node(GuiRenderState.@Nullable Node parent) {
                this.parent = parent;
            }
     
            public void addItem(GuiItemRenderState itemState) {
                if (this.itemStates == null) {
                    this.itemStates = new ArrayList<>();
                }
     
                this.itemStates.add(itemState);
            }
     
            public void addText(GuiTextRenderState textState) {
                if (this.textStates == null) {
                    this.textStates = new ArrayList<>();
                }
     
                this.textStates.add(textState);
            }
     
            public void addPicturesInPictureState(PictureInPictureRenderState picturesInPictureState) {
                if (this.picturesInPictureStates == null) {
                    this.picturesInPictureStates = new ArrayList<>();
                }
     
                this.picturesInPictureStates.add(picturesInPictureState);
            }
     
            public void addGuiElement(GuiElementRenderState blitState) {
                if (this.elementStates == null) {
                    this.elementStates = new ArrayList<>();
                }
     
                this.elementStates.add(blitState);
            }
     
            public void addGlyph(GuiElementRenderState glyphState) {
                if (this.glyphStates == null) {
                    this.glyphStates = new ArrayList<>();
                }
     
                this.glyphStates.add(glyphState);
            }
        }
     
        @OnlyIn(Dist.CLIENT)
        public static enum TraverseRange {
            ALL,
            BEFORE_BLUR,
            AFTER_BLUR;
        }
    }

    引用的其他类