LeashFeatureRenderer.java

net.minecraft.client.renderer.feature.LeashFeatureRenderer

信息

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

    TODO

字段/常量

  • LEASH_RENDER_STEPS

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

      TODO

  • LEASH_WIDTH

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

      TODO

内部类/嵌套类型

构造器

方法

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

public void renderSolid(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource) @ L21

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

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource

说明:

TODO

private static void renderLeash(Matrix4f pose, MultiBufferSource bufferSource, EntityRenderState.LeashState leashState) @ L27

  • 方法名:renderLeash
  • 源码定位:L27
  • 返回类型:void
  • 修饰符:private static

参数:

  • pose: Matrix4f
  • bufferSource: MultiBufferSource
  • leashState: EntityRenderState.LeashState

说明:

TODO

private static void addVertexPair(VertexConsumer builder, Matrix4fc pose, float dx, float dy, float dz, float fudge, float dxOff, float dzOff, int k, boolean backwards, EntityRenderState.LeashState state) @ L46

  • 方法名:addVertexPair
  • 源码定位:L46
  • 返回类型:void
  • 修饰符:private static

参数:

  • builder: VertexConsumer
  • pose: Matrix4fc
  • dx: float
  • dy: float
  • dz: float
  • fudge: float
  • dxOff: float
  • dzOff: float
  • k: int
  • backwards: boolean
  • state: EntityRenderState.LeashState

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class LeashFeatureRenderer {
    private static final int LEASH_RENDER_STEPS = 24;
    private static final float LEASH_WIDTH = 0.05F;
 
    public void renderSolid(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource) {
        for (SubmitNodeStorage.LeashSubmit leashSubmit : nodeCollection.getLeashSubmits()) {
            renderLeash(leashSubmit.pose(), bufferSource, leashSubmit.leashState());
        }
    }
 
    private static void renderLeash(Matrix4f pose, MultiBufferSource bufferSource, EntityRenderState.LeashState leashState) {
        float dx = (float)(leashState.end.x - leashState.start.x);
        float dy = (float)(leashState.end.y - leashState.start.y);
        float dz = (float)(leashState.end.z - leashState.start.z);
        float offsetFactor = Mth.invSqrt(dx * dx + dz * dz) * 0.05F / 2.0F;
        float dxOff = dz * offsetFactor;
        float dzOff = dx * offsetFactor;
        pose.translate((float)leashState.offset.x, (float)leashState.offset.y, (float)leashState.offset.z);
        VertexConsumer builder = bufferSource.getBuffer(RenderTypes.leash());
 
        for (int k = 0; k <= 24; k++) {
            addVertexPair(builder, pose, dx, dy, dz, 0.05F, dxOff, dzOff, k, false, leashState);
        }
 
        for (int k = 24; k >= 0; k--) {
            addVertexPair(builder, pose, dx, dy, dz, 0.0F, dxOff, dzOff, k, true, leashState);
        }
    }
 
    private static void addVertexPair(
        VertexConsumer builder,
        Matrix4fc pose,
        float dx,
        float dy,
        float dz,
        float fudge,
        float dxOff,
        float dzOff,
        int k,
        boolean backwards,
        EntityRenderState.LeashState state
    ) {
        float progress = k / 24.0F;
        int block = (int)Mth.lerp(progress, (float)state.startBlockLight, (float)state.endBlockLight);
        int sky = (int)Mth.lerp(progress, (float)state.startSkyLight, (float)state.endSkyLight);
        int lightCoords = LightCoordsUtil.pack(block, sky);
        float colorModifier = k % 2 == (backwards ? 1 : 0) ? 0.7F : 1.0F;
        float r = 0.5F * colorModifier;
        float g = 0.4F * colorModifier;
        float b = 0.3F * colorModifier;
        float x = dx * progress;
        float y;
        if (state.slack) {
            y = dy > 0.0F ? dy * progress * progress : dy - dy * (1.0F - progress) * (1.0F - progress);
        } else {
            y = dy * progress;
        }
 
        float z = dz * progress;
        builder.addVertex(pose, x - dxOff, y + fudge, z + dzOff).setColor(r, g, b, 1.0F).setLight(lightCoords);
        builder.addVertex(pose, x + dxOff, y + 0.05F - fudge, z - dzOff).setColor(r, g, b, 1.0F).setLight(lightCoords);
    }
}

引用的其他类