ChestRenderer.java

net.minecraft.client.renderer.blockentity.ChestRenderer

信息

  • 全限定名:net.minecraft.client.renderer.blockentity.ChestRenderer
  • 类型:public class
  • 包:net.minecraft.client.renderer.blockentity
  • 源码路径:src/main/java/net/minecraft/client/renderer/blockentity/ChestRenderer.java
  • 起始行号:L40
  • 实现:BlockEntityRenderer<T,ChestRenderState>
  • 职责:

    TODO

字段/常量

  • LAYERS

    • 类型: MultiblockChestResources<ModelLayerLocation>
    • 修饰符: public static final
    • 源码定位: L41
    • 说明:

      TODO

  • TRANSFORMATIONS

    • 类型: Map<Direction,Transformation>
    • 修饰符: private static final
    • 源码定位: L44
    • 说明:

      TODO

  • sprites

    • 类型: SpriteGetter
    • 修饰符: private final
    • 源码定位: L45
    • 说明:

      TODO

  • models

    • 类型: MultiblockChestResources<ChestModel>
    • 修饰符: private final
    • 源码定位: L46
    • 说明:

      TODO

  • xmasTextures

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

      TODO

内部类/嵌套类型

构造器

public ChestRenderer(BlockEntityRendererProvider.Context context) @ L49

  • 构造器名:ChestRenderer
  • 源码定位:L49
  • 修饰符:public

参数:

  • context: BlockEntityRendererProvider.Context

说明:

TODO

方法

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

public static boolean xmasTextures() @ L55

  • 方法名:xmasTextures
  • 源码定位:L55
  • 返回类型:boolean
  • 修饰符:public static

参数:

说明:

TODO

public ChestRenderState createRenderState() @ L59

  • 方法名:createRenderState
  • 源码定位:L59
  • 返回类型:ChestRenderState
  • 修饰符:public

参数:

说明:

TODO

public void extractRenderState(T blockEntity, ChestRenderState state, float partialTicks, Vec3 cameraPosition, ModelFeatureRenderer.CrumblingOverlay breakProgress) @ L63

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

参数:

  • blockEntity: T
  • state: ChestRenderState
  • partialTicks: float
  • cameraPosition: Vec3
  • breakProgress: ModelFeatureRenderer.CrumblingOverlay

说明:

TODO

public void submit(ChestRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) @ L85

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

参数:

  • state: ChestRenderState
  • poseStack: PoseStack
  • submitNodeCollector: SubmitNodeCollector
  • camera: CameraRenderState

说明:

TODO

private static ChestRenderState.ChestMaterialType getChestMaterial(BlockEntity entity, boolean xmasTextures) @ L99

  • 方法名:getChestMaterial
  • 源码定位:L99
  • 返回类型:ChestRenderState.ChestMaterialType
  • 修饰符:private static

参数:

  • entity: BlockEntity
  • xmasTextures: boolean

说明:

TODO

public static Transformation modelTransformation(Direction facing) @ L116

  • 方法名:modelTransformation
  • 源码定位:L116
  • 返回类型:Transformation
  • 修饰符:public static

参数:

  • facing: Direction

说明:

TODO

private static Transformation createModelTransformation(Direction facing) @ L120

  • 方法名:createModelTransformation
  • 源码定位:L120
  • 返回类型:Transformation
  • 修饰符:private static

参数:

  • facing: Direction

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ChestRenderer<T extends BlockEntity & LidBlockEntity> implements BlockEntityRenderer<T, ChestRenderState> {
    public static final MultiblockChestResources<ModelLayerLocation> LAYERS = new MultiblockChestResources<>(
        ModelLayers.CHEST, ModelLayers.DOUBLE_CHEST_LEFT, ModelLayers.DOUBLE_CHEST_RIGHT
    );
    private static final Map<Direction, Transformation> TRANSFORMATIONS = Util.makeEnumMap(Direction.class, ChestRenderer::createModelTransformation);
    private final SpriteGetter sprites;
    private final MultiblockChestResources<ChestModel> models;
    private final boolean xmasTextures;
 
    public ChestRenderer(BlockEntityRendererProvider.Context context) {
        this.sprites = context.sprites();
        this.xmasTextures = xmasTextures();
        this.models = LAYERS.map(layer -> new ChestModel(context.bakeLayer(layer)));
    }
 
    public static boolean xmasTextures() {
        return SpecialDates.isExtendedChristmas();
    }
 
    public ChestRenderState createRenderState() {
        return new ChestRenderState();
    }
 
    public void extractRenderState(
        T blockEntity, ChestRenderState state, float partialTicks, Vec3 cameraPosition, ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
    ) {
        BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
        boolean hasLevel = blockEntity.getLevel() != null;
        BlockState blockState = hasLevel ? blockEntity.getBlockState() : Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
        state.type = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
        state.facing = blockState.getValue(ChestBlock.FACING);
        state.material = getChestMaterial(blockEntity, this.xmasTextures);
        DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combineResult;
        if (hasLevel && blockState.getBlock() instanceof ChestBlock chestBlock) {
            combineResult = chestBlock.combine(blockState, blockEntity.getLevel(), blockEntity.getBlockPos(), true);
        } else {
            combineResult = DoubleBlockCombiner.Combiner::acceptNone;
        }
 
        state.open = combineResult.apply(ChestBlock.opennessCombiner(blockEntity)).get(partialTicks);
        if (state.type != ChestType.SINGLE) {
            state.lightCoords = combineResult.apply(new BrightnessCombiner<>()).applyAsInt(state.lightCoords);
        }
    }
 
    public void submit(ChestRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
        poseStack.pushPose();
        poseStack.mulPose(modelTransformation(state.facing));
        float open = state.open;
        open = 1.0F - open;
        open = 1.0F - open * open * open;
        SpriteId spriteId = Sheets.chooseSprite(state.material, state.type);
        ChestModel model = this.models.select(state.type);
        submitNodeCollector.submitModel(
            model, open, poseStack, state.lightCoords, OverlayTexture.NO_OVERLAY, -1, spriteId, this.sprites, 0, state.breakProgress
        );
        poseStack.popPose();
    }
 
    private static ChestRenderState.ChestMaterialType getChestMaterial(BlockEntity entity, boolean xmasTextures) {
        if (entity.getBlockState().getBlock() instanceof CopperChestBlock copperChestBlock) {
            return switch (copperChestBlock.getState()) {
                case UNAFFECTED -> ChestRenderState.ChestMaterialType.COPPER_UNAFFECTED;
                case EXPOSED -> ChestRenderState.ChestMaterialType.COPPER_EXPOSED;
                case WEATHERED -> ChestRenderState.ChestMaterialType.COPPER_WEATHERED;
                case OXIDIZED -> ChestRenderState.ChestMaterialType.COPPER_OXIDIZED;
            };
        } else if (entity instanceof EnderChestBlockEntity) {
            return ChestRenderState.ChestMaterialType.ENDER_CHEST;
        } else if (xmasTextures) {
            return ChestRenderState.ChestMaterialType.CHRISTMAS;
        } else {
            return entity instanceof TrappedChestBlockEntity ? ChestRenderState.ChestMaterialType.TRAPPED : ChestRenderState.ChestMaterialType.REGULAR;
        }
    }
 
    public static Transformation modelTransformation(Direction facing) {
        return TRANSFORMATIONS.get(facing);
    }
 
    private static Transformation createModelTransformation(Direction facing) {
        return new Transformation(new Matrix4f().rotationAround(Axis.YP.rotationDegrees(-facing.toYRot()), 0.5F, 0.0F, 0.5F));
    }
}

引用的其他类