BeaconRenderer.java

net.minecraft.client.renderer.blockentity.BeaconRenderer

信息

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

    TODO

字段/常量

  • BEAM_LOCATION

    • 类型: Identifier
    • 修饰符: public static final
    • 源码定位: L26
    • 说明:

      TODO

  • MAX_RENDER_Y

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

      TODO

  • BEAM_SCALE_THRESHOLD

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

      TODO

  • SOLID_BEAM_RADIUS

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

      TODO

  • BEAM_GLOW_RADIUS

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

      TODO

内部类/嵌套类型

构造器

方法

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

public BeaconRenderState createRenderState() @ L32

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

参数:

说明:

TODO

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

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

参数:

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

说明:

TODO

public static <T extends BlockEntity &BeaconBeamOwner> void extract(T blockEntity, BeaconRenderState state, float partialTicks, Vec3 cameraPosition) @ L43

  • 方法名:extract
  • 源码定位:L43
  • 返回类型:<T extends BlockEntity &BeaconBeamOwner> void
  • 修饰符:public static

参数:

  • blockEntity: T
  • state: BeaconRenderState
  • partialTicks: float
  • cameraPosition: Vec3

说明:

TODO

public void submit(BeaconRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) @ L51

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

参数:

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

说明:

TODO

private static void submitBeaconBeam(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, float beamRadiusScale, float animationTime, int beamStart, int height, int color) @ L69

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

参数:

  • poseStack: PoseStack
  • submitNodeCollector: SubmitNodeCollector
  • beamRadiusScale: float
  • animationTime: float
  • beamStart: int
  • height: int
  • color: int

说明:

TODO

public static void submitBeaconBeam(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, Identifier beamLocation, float scale, float animationTime, int beamStart, int height, int color, float solidBeamRadius, float beamGlowRadius) @ L77

  • 方法名:submitBeaconBeam
  • 源码定位:L77
  • 返回类型:void
  • 修饰符:public static

参数:

  • poseStack: PoseStack
  • submitNodeCollector: SubmitNodeCollector
  • beamLocation: Identifier
  • scale: float
  • animationTime: float
  • beamStart: int
  • height: int
  • color: int
  • solidBeamRadius: float
  • beamGlowRadius: float

说明:

TODO

private static void renderPart(PoseStack.Pose pose, VertexConsumer builder, int color, int beamStart, int beamEnd, float wnx, float wnz, float enx, float enz, float wsx, float wsz, float esx, float esz, float uu1, float uu2, float vv1, float vv2) @ L150

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

参数:

  • pose: PoseStack.Pose
  • builder: VertexConsumer
  • color: int
  • beamStart: int
  • beamEnd: int
  • wnx: float
  • wnz: float
  • enx: float
  • enz: float
  • wsx: float
  • wsz: float
  • esx: float
  • esz: float
  • uu1: float
  • uu2: float
  • vv1: float
  • vv2: float

说明:

TODO

private static void renderQuad(PoseStack.Pose pose, VertexConsumer builder, int color, int beamStart, int beamEnd, float wnx, float wnz, float enx, float enz, float uu1, float uu2, float vv1, float vv2) @ L175

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

参数:

  • pose: PoseStack.Pose
  • builder: VertexConsumer
  • color: int
  • beamStart: int
  • beamEnd: int
  • wnx: float
  • wnz: float
  • enx: float
  • enz: float
  • uu1: float
  • uu2: float
  • vv1: float
  • vv2: float

说明:

TODO

private static void addVertex(PoseStack.Pose pose, VertexConsumer builder, int color, int y, float x, float z, float u, float v) @ L196

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

参数:

  • pose: PoseStack.Pose
  • builder: VertexConsumer
  • color: int
  • y: int
  • x: float
  • z: float
  • u: float
  • v: float

说明:

TODO

public boolean shouldRenderOffScreen() @ L205

  • 方法名:shouldRenderOffScreen
  • 源码定位:L205
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public int getViewDistance() @ L210

  • 方法名:getViewDistance
  • 源码定位:L210
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public boolean shouldRender(T blockEntity, Vec3 cameraPosition) @ L215

  • 方法名:shouldRender
  • 源码定位:L215
  • 返回类型:boolean
  • 修饰符:public

参数:

  • blockEntity: T
  • cameraPosition: Vec3

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class BeaconRenderer<T extends BlockEntity & BeaconBeamOwner> implements BlockEntityRenderer<T, BeaconRenderState> {
    public static final Identifier BEAM_LOCATION = Identifier.withDefaultNamespace("textures/entity/beacon/beacon_beam.png");
    public static final int MAX_RENDER_Y = 2048;
    private static final float BEAM_SCALE_THRESHOLD = 96.0F;
    public static final float SOLID_BEAM_RADIUS = 0.2F;
    public static final float BEAM_GLOW_RADIUS = 0.25F;
 
    public BeaconRenderState createRenderState() {
        return new BeaconRenderState();
    }
 
    public void extractRenderState(
        T blockEntity, BeaconRenderState state, float partialTicks, Vec3 cameraPosition, ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
    ) {
        BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
        extract(blockEntity, state, partialTicks, cameraPosition);
    }
 
    public static <T extends BlockEntity & BeaconBeamOwner> void extract(T blockEntity, BeaconRenderState state, float partialTicks, Vec3 cameraPosition) {
        state.animationTime = blockEntity.getLevel() != null ? Math.floorMod(blockEntity.getLevel().getGameTime(), 40) + partialTicks : 0.0F;
        state.sections = blockEntity.getBeamSections().stream().map(section -> new BeaconRenderState.Section(section.getColor(), section.getHeight())).toList();
        float distanceToBeacon = (float)cameraPosition.subtract(state.blockPos.getCenter()).horizontalDistance();
        LocalPlayer player = Minecraft.getInstance().player;
        state.beamRadiusScale = player != null && player.isScoping() ? 1.0F : Math.max(1.0F, distanceToBeacon / 96.0F);
    }
 
    public void submit(BeaconRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
        int beamStart = 0;
 
        for (int i = 0; i < state.sections.size(); i++) {
            BeaconRenderState.Section beamSection = state.sections.get(i);
            submitBeaconBeam(
                poseStack,
                submitNodeCollector,
                state.beamRadiusScale,
                state.animationTime,
                beamStart,
                i == state.sections.size() - 1 ? 2048 : beamSection.height(),
                beamSection.color()
            );
            beamStart += beamSection.height();
        }
    }
 
    private static void submitBeaconBeam(
        PoseStack poseStack, SubmitNodeCollector submitNodeCollector, float beamRadiusScale, float animationTime, int beamStart, int height, int color
    ) {
        submitBeaconBeam(
            poseStack, submitNodeCollector, BEAM_LOCATION, 1.0F, animationTime, beamStart, height, color, 0.2F * beamRadiusScale, 0.25F * beamRadiusScale
        );
    }
 
    public static void submitBeaconBeam(
        PoseStack poseStack,
        SubmitNodeCollector submitNodeCollector,
        Identifier beamLocation,
        float scale,
        float animationTime,
        int beamStart,
        int height,
        int color,
        float solidBeamRadius,
        float beamGlowRadius
    ) {
        int beamEnd = beamStart + height;
        poseStack.pushPose();
        poseStack.translate(0.5, 0.0, 0.5);
        float scroll = height < 0 ? animationTime : -animationTime;
        float texVOff = Mth.frac(scroll * 0.2F - Mth.floor(scroll * 0.1F));
        poseStack.pushPose();
        {
        poseStack.mulPose(Axis.YP.rotationDegrees(animationTime * 2.25F - 45.0F));
        float wnx = 0.0F;
        float enz = 0.0F;
        float wsx = -solidBeamRadius;
        float wsz = 0.0F;
        float esx = 0.0F;
        float esz = -solidBeamRadius;
        float uu1 = 0.0F;
        float uu2 = 1.0F;
        float vv2 = -1.0F + texVOff;
        float vv1 = height * scale * (0.5F / solidBeamRadius) + vv2;
        submitNodeCollector.submitCustomGeometry(
            poseStack,
            RenderTypes.beaconBeam(beamLocation, false),
            (pose, buffer) -> renderPart(
                pose, buffer, color, beamStart, beamEnd, 0.0F, solidBeamRadius, solidBeamRadius, 0.0F, wsx, 0.0F, 0.0F, esz, 0.0F, 1.0F, vv1, vv2
            )
        );
        }
        poseStack.popPose();
        float wnx = -beamGlowRadius;
        float wnz = -beamGlowRadius;
        float enz = -beamGlowRadius;
        float wsx = -beamGlowRadius;
        float uu1 = 0.0F;
        float uu2 = 1.0F;
        float vv2 = -1.0F + texVOff;
        float vv1 = height * scale + vv2;
        submitNodeCollector.submitCustomGeometry(
            poseStack,
            RenderTypes.beaconBeam(beamLocation, true),
            (pose, buffer) -> renderPart(
                pose,
                buffer,
                ARGB.color(32, color),
                beamStart,
                beamEnd,
                wnx,
                wnz,
                beamGlowRadius,
                enz,
                wsx,
                beamGlowRadius,
                beamGlowRadius,
                beamGlowRadius,
                0.0F,
                1.0F,
                vv1,
                vv2
            )
        );
        poseStack.popPose();
    }
 
    private static void renderPart(
        PoseStack.Pose pose,
        VertexConsumer builder,
        int color,
        int beamStart,
        int beamEnd,
        float wnx,
        float wnz,
        float enx,
        float enz,
        float wsx,
        float wsz,
        float esx,
        float esz,
        float uu1,
        float uu2,
        float vv1,
        float vv2
    ) {
        renderQuad(pose, builder, color, beamStart, beamEnd, wnx, wnz, enx, enz, uu1, uu2, vv1, vv2);
        renderQuad(pose, builder, color, beamStart, beamEnd, esx, esz, wsx, wsz, uu1, uu2, vv1, vv2);
        renderQuad(pose, builder, color, beamStart, beamEnd, enx, enz, esx, esz, uu1, uu2, vv1, vv2);
        renderQuad(pose, builder, color, beamStart, beamEnd, wsx, wsz, wnx, wnz, uu1, uu2, vv1, vv2);
    }
 
    private static void renderQuad(
        PoseStack.Pose pose,
        VertexConsumer builder,
        int color,
        int beamStart,
        int beamEnd,
        float wnx,
        float wnz,
        float enx,
        float enz,
        float uu1,
        float uu2,
        float vv1,
        float vv2
    ) {
        addVertex(pose, builder, color, beamEnd, wnx, wnz, uu2, vv1);
        addVertex(pose, builder, color, beamStart, wnx, wnz, uu2, vv2);
        addVertex(pose, builder, color, beamStart, enx, enz, uu1, vv2);
        addVertex(pose, builder, color, beamEnd, enx, enz, uu1, vv1);
    }
 
    private static void addVertex(PoseStack.Pose pose, VertexConsumer builder, int color, int y, float x, float z, float u, float v) {
        builder.addVertex(pose, x, (float)y, z)
            .setColor(color)
            .setUv(u, v)
            .setOverlay(OverlayTexture.NO_OVERLAY)
            .setLight(15728880)
            .setNormal(pose, 0.0F, 1.0F, 0.0F);
    }
 
    @Override
    public boolean shouldRenderOffScreen() {
        return true;
    }
 
    @Override
    public int getViewDistance() {
        return Minecraft.getInstance().options.getEffectiveRenderDistance() * 16;
    }
 
    @Override
    public boolean shouldRender(T blockEntity, Vec3 cameraPosition) {
        return Vec3.atCenterOf(blockEntity.getBlockPos()).multiply(1.0, 0.0, 1.0).closerThan(cameraPosition.multiply(1.0, 0.0, 1.0), this.getViewDistance());
    }
}

引用的其他类