| 1 | package net.minecraft.client.renderer.debug;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
| 4 | import it.unimi.dsi.fastutil.longs.LongSet;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.Minecraft;
|
| 8 | import net.minecraft.client.renderer.culling.Frustum;
|
| 9 | import net.minecraft.core.BlockPos;
|
| 10 | import net.minecraft.core.SectionPos;
|
| 11 | import net.minecraft.gizmos.Gizmos;
|
| 12 | import net.minecraft.gizmos.TextGizmo.Style;
|
| 13 | import net.minecraft.util.ARGB;
|
| 14 | import net.minecraft.util.debug.DebugValueAccess;
|
| 15 | import net.minecraft.world.level.Level;
|
| 16 | import net.minecraft.world.level.LightLayer;
|
| 17 | import net.minecraft.world.phys.Vec3;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class LightDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
|
| 21 | private final Minecraft minecraft;
|
| 22 | private final boolean showBlockLight;
|
| 23 | private final boolean showSkyLight;
|
| 24 | private static final int MAX_RENDER_DIST = 10;
|
| 25 |
|
| 26 | public LightDebugRenderer(final Minecraft minecraft, final boolean showBlockLight, final boolean showSkyLight) {
|
| 27 | this.minecraft = minecraft;
|
| 28 | this.showBlockLight = showBlockLight;
|
| 29 | this.showSkyLight = showSkyLight;
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | public void emitGizmos(
|
| 34 | final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
|
| 35 | ) {
|
| 36 | Level level = this.minecraft.level;
|
| 37 | BlockPos playerPos = BlockPos.containing(camX, camY, camZ);
|
| 38 | LongSet set = new LongOpenHashSet();
|
| 39 |
|
| 40 | for (BlockPos blockPos : BlockPos.betweenClosed(playerPos.offset(-10, -10, -10), playerPos.offset(10, 10, 10))) {
|
| 41 | int skyBrightness = level.getBrightness(LightLayer.SKY, blockPos);
|
| 42 | long sectionNode = SectionPos.blockToSection(blockPos.asLong());
|
| 43 | if (set.add(sectionNode)) {
|
| 44 | Gizmos.billboardText(
|
| 45 | level.getChunkSource().getLightEngine().getDebugData(LightLayer.SKY, SectionPos.of(sectionNode)),
|
| 46 | new Vec3(
|
| 47 | SectionPos.sectionToBlockCoord(SectionPos.x(sectionNode), 8),
|
| 48 | SectionPos.sectionToBlockCoord(SectionPos.y(sectionNode), 8),
|
| 49 | SectionPos.sectionToBlockCoord(SectionPos.z(sectionNode), 8)
|
| 50 | ),
|
| 51 | Style.forColorAndCentered(-65536).withScale(4.8F)
|
| 52 | );
|
| 53 | }
|
| 54 |
|
| 55 | if (skyBrightness != 15 && this.showSkyLight) {
|
| 56 | int color = ARGB.srgbLerp(skyBrightness / 15.0F, -16776961, -16711681);
|
| 57 | Gizmos.billboardText(String.valueOf(skyBrightness), Vec3.atLowerCornerWithOffset(blockPos, 0.5, 0.25, 0.5), Style.forColorAndCentered(color));
|
| 58 | }
|
| 59 |
|
| 60 | if (this.showBlockLight) {
|
| 61 | int blockBrightness = level.getBrightness(LightLayer.BLOCK, blockPos);
|
| 62 | if (blockBrightness != 0) {
|
| 63 | int color = ARGB.srgbLerp(blockBrightness / 15.0F, -5636096, -256);
|
| 64 | Gizmos.billboardText(String.valueOf(level.getBrightness(LightLayer.BLOCK, blockPos)), Vec3.atCenterOf(blockPos), Style.forColorAndCentered(color));
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 | }
|
| 69 | }
|
| 70 |
|