DecoratedPotRenderer.java

net.minecraft.client.renderer.blockentity.DecoratedPotRenderer

信息

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

    TODO

字段/常量

  • TRANSFORMATIONS

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

      TODO

  • sprites

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

      TODO

  • NECK

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

      TODO

  • FRONT

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

      TODO

  • BACK

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

      TODO

  • LEFT

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

      TODO

  • RIGHT

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

      TODO

  • TOP

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

      TODO

  • BOTTOM

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

      TODO

  • neck

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L56
    • 说明:

      TODO

  • frontSide

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L57
    • 说明:

      TODO

  • backSide

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L58
    • 说明:

      TODO

  • leftSide

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L59
    • 说明:

      TODO

  • rightSide

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L60
    • 说明:

      TODO

  • top

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L61
    • 说明:

      TODO

  • bottom

    • 类型: ModelPart
    • 修饰符: private final
    • 源码定位: L62
    • 说明:

      TODO

  • WOBBLE_AMPLITUDE

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

      TODO

内部类/嵌套类型

构造器

public DecoratedPotRenderer(BlockEntityRendererProvider.Context context) @ L65

  • 构造器名:DecoratedPotRenderer
  • 源码定位:L65
  • 修饰符:public

参数:

  • context: BlockEntityRendererProvider.Context

说明:

TODO

public DecoratedPotRenderer(SpecialModelRenderer.BakingContext context) @ L69

  • 构造器名:DecoratedPotRenderer
  • 源码定位:L69
  • 修饰符:public

参数:

  • context: SpecialModelRenderer.BakingContext

说明:

TODO

public DecoratedPotRenderer(EntityModelSet entityModelSet, SpriteGetter sprites) @ L73

  • 构造器名:DecoratedPotRenderer
  • 源码定位:L73
  • 修饰符:public

参数:

  • entityModelSet: EntityModelSet
  • sprites: SpriteGetter

说明:

TODO

方法

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

public static LayerDefinition createBaseLayer() @ L86

  • 方法名:createBaseLayer
  • 源码定位:L86
  • 返回类型:LayerDefinition
  • 修饰符:public static

参数:

说明:

TODO

public static LayerDefinition createSidesLayer() @ L106

  • 方法名:createSidesLayer
  • 源码定位:L106
  • 返回类型:LayerDefinition
  • 修饰符:public static

参数:

说明:

TODO

private static SpriteId getSideSprite(Optional<Item> item) @ L117

  • 方法名:getSideSprite
  • 源码定位:L117
  • 返回类型:SpriteId
  • 修饰符:private static

参数:

  • item: Optional

说明:

TODO

public DecoratedPotRenderState createRenderState() @ L128

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

参数:

说明:

TODO

public void extractRenderState(DecoratedPotBlockEntity blockEntity, DecoratedPotRenderState state, float partialTicks, Vec3 cameraPosition, ModelFeatureRenderer.CrumblingOverlay breakProgress) @ L132

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

参数:

  • blockEntity: DecoratedPotBlockEntity
  • state: DecoratedPotRenderState
  • partialTicks: float
  • cameraPosition: Vec3
  • breakProgress: ModelFeatureRenderer.CrumblingOverlay

说明:

TODO

public void submit(DecoratedPotRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) @ L150

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

参数:

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

说明:

TODO

public static Transformation modelTransformation(Direction facing) @ L172

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

参数:

  • facing: Direction

说明:

TODO

private static Transformation createModelTransformation(Direction entityDirection) @ L176

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

参数:

  • entityDirection: Direction

说明:

TODO

public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, PotDecorations decorations, int outlineColor) @ L180

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

参数:

  • poseStack: PoseStack
  • submitNodeCollector: SubmitNodeCollector
  • lightCoords: int
  • overlayCoords: int
  • decorations: PotDecorations
  • outlineColor: int

说明:

TODO

public void getExtents(Consumer<Vector3fc> output) @ L246

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

参数:

  • output: Consumer

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class DecoratedPotRenderer implements BlockEntityRenderer<DecoratedPotBlockEntity, DecoratedPotRenderState> {
    private static final Map<Direction, Transformation> TRANSFORMATIONS = Util.makeEnumMap(Direction.class, DecoratedPotRenderer::createModelTransformation);
    private final SpriteGetter sprites;
    private static final String NECK = "neck";
    private static final String FRONT = "front";
    private static final String BACK = "back";
    private static final String LEFT = "left";
    private static final String RIGHT = "right";
    private static final String TOP = "top";
    private static final String BOTTOM = "bottom";
    private final ModelPart neck;
    private final ModelPart frontSide;
    private final ModelPart backSide;
    private final ModelPart leftSide;
    private final ModelPart rightSide;
    private final ModelPart top;
    private final ModelPart bottom;
    private static final float WOBBLE_AMPLITUDE = 0.125F;
 
    public DecoratedPotRenderer(BlockEntityRendererProvider.Context context) {
        this(context.entityModelSet(), context.sprites());
    }
 
    public DecoratedPotRenderer(SpecialModelRenderer.BakingContext context) {
        this(context.entityModelSet(), context.sprites());
    }
 
    public DecoratedPotRenderer(EntityModelSet entityModelSet, SpriteGetter sprites) {
        this.sprites = sprites;
        ModelPart baseRoot = entityModelSet.bakeLayer(ModelLayers.DECORATED_POT_BASE);
        this.neck = baseRoot.getChild("neck");
        this.top = baseRoot.getChild("top");
        this.bottom = baseRoot.getChild("bottom");
        ModelPart sidesRoot = entityModelSet.bakeLayer(ModelLayers.DECORATED_POT_SIDES);
        this.frontSide = sidesRoot.getChild("front");
        this.backSide = sidesRoot.getChild("back");
        this.leftSide = sidesRoot.getChild("left");
        this.rightSide = sidesRoot.getChild("right");
    }
 
    public static LayerDefinition createBaseLayer() {
        MeshDefinition mesh = new MeshDefinition();
        PartDefinition root = mesh.getRoot();
        CubeDeformation inflate = new CubeDeformation(0.2F);
        CubeDeformation deflate = new CubeDeformation(-0.1F);
        root.addOrReplaceChild(
            "neck",
            CubeListBuilder.create()
                .texOffs(0, 0)
                .addBox(4.0F, 17.0F, 4.0F, 8.0F, 3.0F, 8.0F, deflate)
                .texOffs(0, 5)
                .addBox(5.0F, 20.0F, 5.0F, 6.0F, 1.0F, 6.0F, inflate),
            PartPose.offsetAndRotation(0.0F, 37.0F, 16.0F, (float) Math.PI, 0.0F, 0.0F)
        );
        CubeListBuilder topBottomPlane = CubeListBuilder.create().texOffs(-14, 13).addBox(0.0F, 0.0F, 0.0F, 14.0F, 0.0F, 14.0F);
        root.addOrReplaceChild("top", topBottomPlane, PartPose.offsetAndRotation(1.0F, 16.0F, 1.0F, 0.0F, 0.0F, 0.0F));
        root.addOrReplaceChild("bottom", topBottomPlane, PartPose.offsetAndRotation(1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F));
        return LayerDefinition.create(mesh, 32, 32);
    }
 
    public static LayerDefinition createSidesLayer() {
        MeshDefinition mesh = new MeshDefinition();
        PartDefinition root = mesh.getRoot();
        CubeListBuilder sidePlane = CubeListBuilder.create().texOffs(1, 0).addBox(0.0F, 0.0F, 0.0F, 14.0F, 16.0F, 0.0F, EnumSet.of(Direction.NORTH));
        root.addOrReplaceChild("back", sidePlane, PartPose.offsetAndRotation(15.0F, 16.0F, 1.0F, 0.0F, 0.0F, (float) Math.PI));
        root.addOrReplaceChild("left", sidePlane, PartPose.offsetAndRotation(1.0F, 16.0F, 1.0F, 0.0F, (float) (-Math.PI / 2), (float) Math.PI));
        root.addOrReplaceChild("right", sidePlane, PartPose.offsetAndRotation(15.0F, 16.0F, 15.0F, 0.0F, (float) (Math.PI / 2), (float) Math.PI));
        root.addOrReplaceChild("front", sidePlane, PartPose.offsetAndRotation(1.0F, 16.0F, 15.0F, (float) Math.PI, 0.0F, 0.0F));
        return LayerDefinition.create(mesh, 16, 16);
    }
 
    private static SpriteId getSideSprite(Optional<Item> item) {
        if (item.isPresent()) {
            SpriteId result = Sheets.getDecoratedPotSprite(DecoratedPotPatterns.getPatternFromItem(item.get()));
            if (result != null) {
                return result;
            }
        }
 
        return Sheets.DECORATED_POT_SIDE;
    }
 
    public DecoratedPotRenderState createRenderState() {
        return new DecoratedPotRenderState();
    }
 
    public void extractRenderState(
        DecoratedPotBlockEntity blockEntity,
        DecoratedPotRenderState state,
        float partialTicks,
        Vec3 cameraPosition,
        ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
    ) {
        BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
        state.decorations = blockEntity.getDecorations();
        state.direction = blockEntity.getDirection();
        DecoratedPotBlockEntity.WobbleStyle wobbleStyle = blockEntity.lastWobbleStyle;
        if (wobbleStyle != null && blockEntity.getLevel() != null) {
            state.wobbleProgress = ((float)(blockEntity.getLevel().getGameTime() - blockEntity.wobbleStartedAtTick) + partialTicks) / wobbleStyle.duration;
        } else {
            state.wobbleProgress = 0.0F;
        }
    }
 
    public void submit(DecoratedPotRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
        poseStack.pushPose();
        poseStack.mulPose(modelTransformation(state.direction));
        if (state.wobbleProgress >= 0.0F && state.wobbleProgress <= 1.0F) {
            if (state.wobbleStyle == DecoratedPotBlockEntity.WobbleStyle.POSITIVE) {
                float amplitude = 0.015625F;
                float deltaTime = state.wobbleProgress * (float) (Math.PI * 2);
                float tiltX = -1.5F * (Mth.cos(deltaTime) + 0.5F) * Mth.sin(deltaTime / 2.0F);
                poseStack.rotateAround(Axis.XP.rotation(tiltX * 0.015625F), 0.5F, 0.0F, 0.5F);
                float tiltZ = Mth.sin(deltaTime);
                poseStack.rotateAround(Axis.ZP.rotation(tiltZ * 0.015625F), 0.5F, 0.0F, 0.5F);
            } else {
                float turnAngle = Mth.sin(-state.wobbleProgress * 3.0F * (float) Math.PI) * 0.125F;
                float linearDecayFactor = 1.0F - state.wobbleProgress;
                poseStack.rotateAround(Axis.YP.rotation(turnAngle * linearDecayFactor), 0.5F, 0.0F, 0.5F);
            }
        }
 
        this.submit(poseStack, submitNodeCollector, state.lightCoords, OverlayTexture.NO_OVERLAY, state.decorations, 0);
        poseStack.popPose();
    }
 
    public static Transformation modelTransformation(Direction facing) {
        return TRANSFORMATIONS.get(facing);
    }
 
    private static Transformation createModelTransformation(Direction entityDirection) {
        return new Transformation(new Matrix4f().rotateAround(Axis.YP.rotationDegrees(180.0F - entityDirection.toYRot()), 0.5F, 0.5F, 0.5F));
    }
 
    public void submit(
        PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, PotDecorations decorations, int outlineColor
    ) {
        RenderType renderType = Sheets.DECORATED_POT_BASE.renderType(RenderTypes::entitySolid);
        TextureAtlasSprite sprite = this.sprites.get(Sheets.DECORATED_POT_BASE);
        submitNodeCollector.submitModelPart(this.neck, poseStack, renderType, lightCoords, overlayCoords, sprite, false, false, -1, null, outlineColor);
        submitNodeCollector.submitModelPart(this.top, poseStack, renderType, lightCoords, overlayCoords, sprite, false, false, -1, null, outlineColor);
        submitNodeCollector.submitModelPart(this.bottom, poseStack, renderType, lightCoords, overlayCoords, sprite, false, false, -1, null, outlineColor);
        SpriteId frontSprite = getSideSprite(decorations.front());
        submitNodeCollector.submitModelPart(
            this.frontSide,
            poseStack,
            frontSprite.renderType(RenderTypes::entitySolid),
            lightCoords,
            overlayCoords,
            this.sprites.get(frontSprite),
            false,
            false,
            -1,
            null,
            outlineColor
        );
        SpriteId backSprite = getSideSprite(decorations.back());
        submitNodeCollector.submitModelPart(
            this.backSide,
            poseStack,
            backSprite.renderType(RenderTypes::entitySolid),
            lightCoords,
            overlayCoords,
            this.sprites.get(backSprite),
            false,
            false,
            -1,
            null,
            outlineColor
        );
        SpriteId leftSprite = getSideSprite(decorations.left());
        submitNodeCollector.submitModelPart(
            this.leftSide,
            poseStack,
            leftSprite.renderType(RenderTypes::entitySolid),
            lightCoords,
            overlayCoords,
            this.sprites.get(leftSprite),
            false,
            false,
            -1,
            null,
            outlineColor
        );
        SpriteId rightSprite = getSideSprite(decorations.right());
        submitNodeCollector.submitModelPart(
            this.rightSide,
            poseStack,
            rightSprite.renderType(RenderTypes::entitySolid),
            lightCoords,
            overlayCoords,
            this.sprites.get(rightSprite),
            false,
            false,
            -1,
            null,
            outlineColor
        );
    }
 
    public void getExtents(Consumer<Vector3fc> output) {
        PoseStack poseStack = new PoseStack();
        this.neck.getExtentsForGui(poseStack, output);
        this.top.getExtentsForGui(poseStack, output);
        this.bottom.getExtentsForGui(poseStack, output);
    }
}

引用的其他类