QuadCollection.java

net.minecraft.client.resources.model.geometry.QuadCollection

信息

  • 全限定名:net.minecraft.client.resources.model.geometry.QuadCollection
  • 类型:public class
  • 包:net.minecraft.client.resources.model.geometry
  • 源码路径:src/main/java/net/minecraft/client/resources/model/geometry/QuadCollection.java
  • 起始行号:L14
  • 职责:

    TODO

字段/常量

  • EMPTY

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

      TODO

  • FLAGS_NOT_COMPUTED

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

      TODO

  • all

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L17
    • 说明:

      TODO

  • unculled

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • north

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

      TODO

  • south

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • east

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • west

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • up

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

      TODO

  • down

    • 类型: List<BakedQuad>
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • materialFlags

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.resources.model.geometry.QuadCollection.Builder
    • 类型: class
    • 修饰符: public static
    • 源码定位: L88
    • 说明:

      TODO

构造器

private QuadCollection(List<BakedQuad> all, List<BakedQuad> unculled, List<BakedQuad> north, List<BakedQuad> south, List<BakedQuad> east, List<BakedQuad> west, List<BakedQuad> up, List<BakedQuad> down) @ L27

  • 构造器名:QuadCollection
  • 源码定位:L27
  • 修饰符:private

参数:

  • all: List
  • unculled: List
  • north: List
  • south: List
  • east: List
  • west: List
  • up: List
  • down: List

说明:

TODO

方法

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

private static int computeMaterialFlags(List<BakedQuad> quads) @ L47

  • 方法名:computeMaterialFlags
  • 源码定位:L47
  • 返回类型:int
  • 修饰符:private static

参数:

  • quads: List

说明:

TODO

public List<BakedQuad> getQuads(Direction direction) @ L58

  • 方法名:getQuads
  • 源码定位:L58
  • 返回类型:List
  • 修饰符:public

参数:

  • direction: Direction

说明:

TODO

public List<BakedQuad> getAll() @ L70

  • 方法名:getAll
  • 源码定位:L70
  • 返回类型:List
  • 修饰符:public

参数:

说明:

TODO

public int materialFlags() @ L74

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

参数:

说明:

TODO

public boolean hasMaterialFlag(int flag) @ L83

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

参数:

  • flag: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class QuadCollection {
    public static final QuadCollection EMPTY = new QuadCollection(List.of(), List.of(), List.of(), List.of(), List.of(), List.of(), List.of(), List.of());
    private static final int FLAGS_NOT_COMPUTED = -1;
    private final List<BakedQuad> all;
    private final List<BakedQuad> unculled;
    private final List<BakedQuad> north;
    private final List<BakedQuad> south;
    private final List<BakedQuad> east;
    private final List<BakedQuad> west;
    private final List<BakedQuad> up;
    private final List<BakedQuad> down;
    private int materialFlags = -1;
 
    private QuadCollection(
        List<BakedQuad> all,
        List<BakedQuad> unculled,
        List<BakedQuad> north,
        List<BakedQuad> south,
        List<BakedQuad> east,
        List<BakedQuad> west,
        List<BakedQuad> up,
        List<BakedQuad> down
    ) {
        this.all = all;
        this.unculled = unculled;
        this.north = north;
        this.south = south;
        this.east = east;
        this.west = west;
        this.up = up;
        this.down = down;
    }
 
    @BakedQuad.MaterialFlags
    private static int computeMaterialFlags(List<BakedQuad> quads) {
        int flags = 0;
 
        for (BakedQuad quad : quads) {
            flags |= quad.materialInfo().flags();
        }
 
        return flags;
    }
 
    public List<BakedQuad> getQuads(@Nullable Direction direction) {
        return switch (direction) {
            case null -> this.unculled;
            case NORTH -> this.north;
            case SOUTH -> this.south;
            case EAST -> this.east;
            case WEST -> this.west;
            case UP -> this.up;
            case DOWN -> this.down;
        };
    }
 
    public List<BakedQuad> getAll() {
        return this.all;
    }
 
    @BakedQuad.MaterialFlags
    public int materialFlags() {
        if (this.materialFlags == -1) {
            this.materialFlags = computeMaterialFlags(this.all);
        }
 
        return this.materialFlags;
    }
 
    public boolean hasMaterialFlag(@BakedQuad.MaterialFlags int flag) {
        return (this.materialFlags() & flag) != 0;
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class Builder {
        private final ImmutableList.Builder<BakedQuad> unculledFaces = ImmutableList.builder();
        private final Multimap<Direction, BakedQuad> culledFaces = ArrayListMultimap.create();
 
        public QuadCollection.Builder addCulledFace(Direction direction, BakedQuad quad) {
            this.culledFaces.put(direction, quad);
            return this;
        }
 
        public QuadCollection.Builder addUnculledFace(BakedQuad quad) {
            this.unculledFaces.add(quad);
            return this;
        }
 
        public QuadCollection.Builder addAll(QuadCollection quadCollection) {
            this.culledFaces.putAll(Direction.UP, quadCollection.up);
            this.culledFaces.putAll(Direction.DOWN, quadCollection.down);
            this.culledFaces.putAll(Direction.NORTH, quadCollection.north);
            this.culledFaces.putAll(Direction.SOUTH, quadCollection.south);
            this.culledFaces.putAll(Direction.EAST, quadCollection.east);
            this.culledFaces.putAll(Direction.WEST, quadCollection.west);
            this.unculledFaces.addAll(quadCollection.unculled);
            return this;
        }
 
        private static QuadCollection createFromSublists(
            List<BakedQuad> all, int unculledCount, int northCount, int southCount, int eastCount, int westCount, int upCount, int downCount
        ) {
            int index = 0;
            int var16;
            List<BakedQuad> unculled = all.subList(index, var16 = index + unculledCount);
            List<BakedQuad> north = all.subList(var16, index = var16 + northCount);
            int var18;
            List<BakedQuad> south = all.subList(index, var18 = index + southCount);
            List<BakedQuad> east = all.subList(var18, index = var18 + eastCount);
            int var20;
            List<BakedQuad> west = all.subList(index, var20 = index + westCount);
            List<BakedQuad> up = all.subList(var20, index = var20 + upCount);
            List<BakedQuad> down = all.subList(index, index + downCount);
            return new QuadCollection(all, unculled, north, south, east, west, up, down);
        }
 
        public QuadCollection build() {
            ImmutableList<BakedQuad> unculledFaces = this.unculledFaces.build();
            if (this.culledFaces.isEmpty()) {
                return unculledFaces.isEmpty()
                    ? QuadCollection.EMPTY
                    : new QuadCollection(unculledFaces, unculledFaces, List.of(), List.of(), List.of(), List.of(), List.of(), List.of());
            } else {
                ImmutableList.Builder<BakedQuad> quads = ImmutableList.builder();
                quads.addAll(unculledFaces);
                Collection<BakedQuad> north = this.culledFaces.get(Direction.NORTH);
                quads.addAll(north);
                Collection<BakedQuad> south = this.culledFaces.get(Direction.SOUTH);
                quads.addAll(south);
                Collection<BakedQuad> east = this.culledFaces.get(Direction.EAST);
                quads.addAll(east);
                Collection<BakedQuad> west = this.culledFaces.get(Direction.WEST);
                quads.addAll(west);
                Collection<BakedQuad> up = this.culledFaces.get(Direction.UP);
                quads.addAll(up);
                Collection<BakedQuad> down = this.culledFaces.get(Direction.DOWN);
                quads.addAll(down);
                return createFromSublists(quads.build(), unculledFaces.size(), north.size(), south.size(), east.size(), west.size(), up.size(), down.size());
            }
        }
    }
}

引用的其他类