RenderRegionCache.java

net.minecraft.client.renderer.chunk.RenderRegionCache

信息

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

    TODO

字段/常量

  • sectionCopyCache
    • 类型: Long2ObjectMap<SectionCopy>
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public RenderSectionRegion createRegion(ClientLevel level, long sectionNode) @ L16

  • 方法名:createRegion
  • 源码定位:L16
  • 返回类型:RenderSectionRegion
  • 修饰符:public

参数:

  • level: ClientLevel
  • sectionNode: long

说明:

TODO

private SectionCopy getSectionDataCopy(Level level, int sectionX, int sectionY, int sectionZ) @ L40

  • 方法名:getSectionDataCopy
  • 源码定位:L40
  • 返回类型:SectionCopy
  • 修饰符:private

参数:

  • level: Level
  • sectionX: int
  • sectionY: int
  • sectionZ: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RenderRegionCache {
    private final Long2ObjectMap<SectionCopy> sectionCopyCache = new Long2ObjectOpenHashMap<>();
 
    public RenderSectionRegion createRegion(ClientLevel level, long sectionNode) {
        int sectionX = SectionPos.x(sectionNode);
        int sectionY = SectionPos.y(sectionNode);
        int sectionZ = SectionPos.z(sectionNode);
        int minSectionX = sectionX - 1;
        int minSectionY = sectionY - 1;
        int minSectionZ = sectionZ - 1;
        int maxSectionX = sectionX + 1;
        int maxSectionY = sectionY + 1;
        int maxSectionZ = sectionZ + 1;
        SectionCopy[] regionSections = new SectionCopy[27];
 
        for (int regionSectionZ = minSectionZ; regionSectionZ <= maxSectionZ; regionSectionZ++) {
            for (int regionSectionY = minSectionY; regionSectionY <= maxSectionY; regionSectionY++) {
                for (int regionSectionX = minSectionX; regionSectionX <= maxSectionX; regionSectionX++) {
                    int index = RenderSectionRegion.index(minSectionX, minSectionY, minSectionZ, regionSectionX, regionSectionY, regionSectionZ);
                    regionSections[index] = this.getSectionDataCopy(level, regionSectionX, regionSectionY, regionSectionZ);
                }
            }
        }
 
        return new RenderSectionRegion(level, minSectionX, minSectionY, minSectionZ, regionSections);
    }
 
    private SectionCopy getSectionDataCopy(Level level, int sectionX, int sectionY, int sectionZ) {
        return this.sectionCopyCache.computeIfAbsent(SectionPos.asLong(sectionX, sectionY, sectionZ), k -> {
            LevelChunk chunk = level.getChunk(sectionX, sectionZ);
            return new SectionCopy(chunk, chunk.getSectionIndexFromSectionY(sectionY));
        });
    }
}

引用的其他类

  • ClientLevel

    • 引用位置: 参数
  • RenderSectionRegion

    • 引用位置: 方法调用/构造调用/返回值
    • 关联成员: RenderSectionRegion(), RenderSectionRegion.index()
  • SectionCopy

    • 引用位置: 字段/构造调用/返回值
    • 关联成员: SectionCopy()
  • SectionPos

    • 引用位置: 方法调用
    • 关联成员: SectionPos.asLong(), SectionPos.x(), SectionPos.y(), SectionPos.z()
  • Level

    • 引用位置: 参数