| 1 | package net.minecraft.client.renderer.debug;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.renderer.culling.Frustum;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.core.Direction;
|
| 9 | import net.minecraft.gizmos.GizmoStyle;
|
| 10 | import net.minecraft.gizmos.Gizmos;
|
| 11 | import net.minecraft.util.debug.DebugValueAccess;
|
| 12 | import net.minecraft.world.level.BlockGetter;
|
| 13 | import net.minecraft.world.level.block.Blocks;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 | import net.minecraft.world.phys.AABB;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class SolidFaceRenderer implements DebugRenderer.SimpleDebugRenderer {
|
| 21 | private final Minecraft minecraft;
|
| 22 |
|
| 23 | public SolidFaceRenderer(final Minecraft minecraft) {
|
| 24 | this.minecraft = minecraft;
|
| 25 | }
|
| 26 |
|
| 27 | @Override
|
| 28 | public void emitGizmos(
|
| 29 | final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
|
| 30 | ) {
|
| 31 | BlockGetter level = this.minecraft.player.level();
|
| 32 | BlockPos playerPos = BlockPos.containing(camX, camY, camZ);
|
| 33 |
|
| 34 | for (BlockPos blockPos : BlockPos.betweenClosed(playerPos.offset(-6, -6, -6), playerPos.offset(6, 6, 6))) {
|
| 35 | BlockState blockState = level.getBlockState(blockPos);
|
| 36 | if (!blockState.is(Blocks.AIR)) {
|
| 37 | VoxelShape shape = blockState.getShape(level, blockPos);
|
| 38 |
|
| 39 | for (AABB outlineBox : shape.toAabbs()) {
|
| 40 | AABB aabb = outlineBox.move(blockPos).inflate(0.002);
|
| 41 | int color = -2130771968;
|
| 42 | Vec3 min = aabb.getMinPosition();
|
| 43 | Vec3 max = aabb.getMaxPosition();
|
| 44 | addFaceIfSturdy(blockPos, blockState, level, Direction.WEST, min, max, -2130771968);
|
| 45 | addFaceIfSturdy(blockPos, blockState, level, Direction.SOUTH, min, max, -2130771968);
|
| 46 | addFaceIfSturdy(blockPos, blockState, level, Direction.EAST, min, max, -2130771968);
|
| 47 | addFaceIfSturdy(blockPos, blockState, level, Direction.NORTH, min, max, -2130771968);
|
| 48 | addFaceIfSturdy(blockPos, blockState, level, Direction.DOWN, min, max, -2130771968);
|
| 49 | addFaceIfSturdy(blockPos, blockState, level, Direction.UP, min, max, -2130771968);
|
| 50 | }
|
| 51 | }
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | private static void addFaceIfSturdy(
|
| 56 | final BlockPos blockPos,
|
| 57 | final BlockState blockState,
|
| 58 | final BlockGetter level,
|
| 59 | final Direction direction,
|
| 60 | final Vec3 cornerA,
|
| 61 | final Vec3 cornerB,
|
| 62 | final int color
|
| 63 | ) {
|
| 64 | if (blockState.isFaceSturdy(level, blockPos, direction)) {
|
| 65 | Gizmos.rect(cornerA, cornerB, direction, GizmoStyle.fill(color));
|
| 66 | }
|
| 67 | }
|
| 68 | }
|
| 69 |
|