SectionCopy.java

net.minecraft.client.renderer.chunk.SectionCopy

信息

  • 全限定名:net.minecraft.client.renderer.chunk.SectionCopy
  • 类型:package-private class
  • 包:net.minecraft.client.renderer.chunk
  • 源码路径:src/main/java/net/minecraft/client/renderer/chunk/SectionCopy.java
  • 起始行号:L23
  • 职责:

    TODO

字段/常量

  • blockEntities

    • 类型: Map<BlockPos,BlockEntity>
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • section

    • 类型: PalettedContainer<BlockState>
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • debug

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

      TODO

  • levelHeightAccessor

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

      TODO

内部类/嵌套类型

构造器

SectionCopy(LevelChunk levelChunk, int sectionIndex) @ L29

  • 构造器名:SectionCopy
  • 源码定位:L29
  • 修饰符:package-private

参数:

  • levelChunk: LevelChunk
  • sectionIndex: int

说明:

TODO

方法

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

public BlockEntity getBlockEntity(BlockPos pos) @ L46

  • 方法名:getBlockEntity
  • 源码定位:L46
  • 返回类型:BlockEntity
  • 修饰符:public

参数:

  • pos: BlockPos

说明:

TODO

public BlockState getBlockState(BlockPos pos) @ L50

  • 方法名:getBlockState
  • 源码定位:L50
  • 返回类型:BlockState
  • 修饰符:public

参数:

  • pos: BlockPos

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
class SectionCopy {
    private final Map<BlockPos, BlockEntity> blockEntities;
    private final @Nullable PalettedContainer<BlockState> section;
    private final boolean debug;
    private final LevelHeightAccessor levelHeightAccessor;
 
    SectionCopy(LevelChunk levelChunk, int sectionIndex) {
        this.levelHeightAccessor = levelChunk;
        this.debug = levelChunk.getLevel().isDebug();
        this.blockEntities = ImmutableMap.copyOf(levelChunk.getBlockEntities());
        if (levelChunk instanceof EmptyLevelChunk) {
            this.section = null;
        } else {
            LevelChunkSection[] sections = levelChunk.getSections();
            if (sectionIndex >= 0 && sectionIndex < sections.length) {
                LevelChunkSection levelChunkSection = sections[sectionIndex];
                this.section = levelChunkSection.hasOnlyAir() ? null : levelChunkSection.getStates().copy();
            } else {
                this.section = null;
            }
        }
    }
 
    public @Nullable BlockEntity getBlockEntity(BlockPos pos) {
        return this.blockEntities.get(pos);
    }
 
    public BlockState getBlockState(BlockPos pos) {
        int x = pos.getX();
        int y = pos.getY();
        int z = pos.getZ();
        if (this.debug) {
            BlockState blockState = null;
            if (y == 60) {
                blockState = Blocks.BARRIER.defaultBlockState();
            }
 
            if (y == 70) {
                blockState = DebugLevelSource.getBlockStateFor(x, z);
            }
 
            return blockState == null ? Blocks.AIR.defaultBlockState() : blockState;
        } else if (this.section == null) {
            return Blocks.AIR.defaultBlockState();
        } else {
            try {
                return this.section.get(x & 15, y & 15, z & 15);
            } catch (Throwable var8) {
                CrashReport report = CrashReport.forThrowable(var8, "Getting block state");
                CrashReportCategory category = report.addCategory("Block being got");
                category.setDetail("Location", () -> CrashReportCategory.formatLocation(this.levelHeightAccessor, x, y, z));
                throw new ReportedException(report);
            }
        }
    }
}

引用的其他类