SupportBlockRenderer.java

net.minecraft.client.renderer.debug.SupportBlockRenderer

信息

  • 全限定名:net.minecraft.client.renderer.debug.SupportBlockRenderer
  • 类型:public class
  • 包:net.minecraft.client.renderer.debug
  • 源码路径:src/main/java/net/minecraft/client/renderer/debug/SupportBlockRenderer.java
  • 起始行号:L24
  • 实现:DebugRenderer.SimpleDebugRenderer
  • 职责:

    TODO

字段/常量

  • minecraft

    • 类型: Minecraft
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • lastUpdateTime

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

      TODO

  • surroundEntities

    • 类型: List<Entity>
    • 修饰符: private
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

构造器

public SupportBlockRenderer(Minecraft minecraft) @ L29

  • 构造器名:SupportBlockRenderer
  • 源码定位:L29
  • 修饰符:public

参数:

  • minecraft: Minecraft

说明:

TODO

方法

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

public void emitGizmos(double camX, double camY, double camZ, DebugValueAccess debugValues, Frustum frustum, float partialTicks) @ L33

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

参数:

  • camX: double
  • camY: double
  • camZ: double
  • debugValues: DebugValueAccess
  • frustum: Frustum
  • partialTicks: float

说明:

TODO

private void drawHighlights(Entity entity, DoubleSupplier biasGetter, int color) @ L54

  • 方法名:drawHighlights
  • 源码定位:L54
  • 返回类型:void
  • 修饰符:private

参数:

  • entity: Entity
  • biasGetter: DoubleSupplier
  • color: int

说明:

TODO

private double getBias(Entity entity) @ L66

  • 方法名:getBias
  • 源码定位:L66
  • 返回类型:double
  • 修饰符:private

参数:

  • entity: Entity

说明:

TODO

private void highlightPosition(BlockPos pos, double offset, int color) @ L70

  • 方法名:highlightPosition
  • 源码定位:L70
  • 返回类型:void
  • 修饰符:private

参数:

  • pos: BlockPos
  • offset: double
  • color: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SupportBlockRenderer implements DebugRenderer.SimpleDebugRenderer {
    private final Minecraft minecraft;
    private double lastUpdateTime = Double.MIN_VALUE;
    private List<Entity> surroundEntities = Collections.emptyList();
 
    public SupportBlockRenderer(Minecraft minecraft) {
        this.minecraft = minecraft;
    }
 
    @Override
    public void emitGizmos(double camX, double camY, double camZ, DebugValueAccess debugValues, Frustum frustum, float partialTicks) {
        double time = Util.getNanos();
        if (time - this.lastUpdateTime > 1.0E8) {
            this.lastUpdateTime = time;
            Entity cameraEntity = this.minecraft.getCameraEntity();
            this.surroundEntities = ImmutableList.copyOf(cameraEntity.level().getEntities(cameraEntity, cameraEntity.getBoundingBox().inflate(16.0)));
        }
 
        Player player = this.minecraft.player;
        if (player != null && player.mainSupportingBlockPos.isPresent()) {
            this.drawHighlights(player, () -> 0.0, -65536);
        }
 
        for (Entity entity : this.surroundEntities) {
            if (entity != player) {
                this.drawHighlights(entity, () -> this.getBias(entity), -16711936);
            }
        }
    }
 
    private void drawHighlights(Entity entity, DoubleSupplier biasGetter, int color) {
        entity.mainSupportingBlockPos.ifPresent(bp -> {
            double bias = biasGetter.getAsDouble();
            BlockPos supportingBlock = entity.getOnPos();
            this.highlightPosition(supportingBlock, 0.02 + bias, color);
            BlockPos effect = entity.getOnPosLegacy();
            if (!effect.equals(supportingBlock)) {
                this.highlightPosition(effect, 0.04 + bias, -16711681);
            }
        });
    }
 
    private double getBias(Entity entity) {
        return 0.02 * (String.valueOf(entity.getId() + 0.132453657).hashCode() % 1000) / 1000.0;
    }
 
    private void highlightPosition(BlockPos pos, double offset, int color) {
        double fromX = pos.getX() - 2.0 * offset;
        double fromY = pos.getY() - 2.0 * offset;
        double fromZ = pos.getZ() - 2.0 * offset;
        double toX = fromX + 1.0 + 4.0 * offset;
        double toY = fromY + 1.0 + 4.0 * offset;
        double toZ = fromZ + 1.0 + 4.0 * offset;
        Gizmos.cuboid(new AABB(fromX, fromY, fromZ, toX, toY, toZ), GizmoStyle.stroke(ARGB.color(0.4F, color)));
        VoxelShape shape = this.minecraft.level.getBlockState(pos).getCollisionShape(this.minecraft.level, pos, CollisionContext.empty()).move(pos);
        GizmoStyle style = GizmoStyle.stroke(color);
 
        for (AABB aabb : shape.toAabbs()) {
            Gizmos.cuboid(aabb, style);
        }
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 参数/字段
  • Frustum

    • 引用位置: 参数
  • DebugRenderer

    • 引用位置: 实现
  • BlockPos

    • 引用位置: 参数
  • GizmoStyle

    • 引用位置: 方法调用
    • 关联成员: GizmoStyle.stroke()
  • Gizmos

    • 引用位置: 方法调用
    • 关联成员: Gizmos.cuboid()
  • ARGB

    • 引用位置: 方法调用
    • 关联成员: ARGB.color()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.getNanos()
  • DebugValueAccess

    • 引用位置: 参数
  • Entity

    • 引用位置: 参数/字段
  • AABB

    • 引用位置: 构造调用
    • 关联成员: AABB()
  • CollisionContext

    • 引用位置: 方法调用
    • 关联成员: CollisionContext.empty()