| 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.gizmos.GizmoStyle;
|
| 9 | import net.minecraft.gizmos.Gizmos;
|
| 10 | import net.minecraft.gizmos.TextGizmo.Style;
|
| 11 | import net.minecraft.tags.FluidTags;
|
| 12 | import net.minecraft.util.ARGB;
|
| 13 | import net.minecraft.util.debug.DebugValueAccess;
|
| 14 | import net.minecraft.world.level.LevelReader;
|
| 15 | import net.minecraft.world.level.material.FluidState;
|
| 16 | import net.minecraft.world.phys.AABB;
|
| 17 | import net.minecraft.world.phys.Vec3;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class WaterDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
|
| 21 | private final Minecraft minecraft;
|
| 22 |
|
| 23 | public WaterDebugRenderer(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 | BlockPos pos = this.minecraft.player.blockPosition();
|
| 32 | LevelReader level = this.minecraft.player.level();
|
| 33 |
|
| 34 | for (BlockPos blockPos : BlockPos.betweenClosed(pos.offset(-10, -10, -10), pos.offset(10, 10, 10))) {
|
| 35 | FluidState fluidState = level.getFluidState(blockPos);
|
| 36 | if (fluidState.is(FluidTags.WATER)) {
|
| 37 | double height = blockPos.getY() + fluidState.getHeight(level, blockPos);
|
| 38 | Gizmos.cuboid(
|
| 39 | new AABB(blockPos.getX() + 0.01F, blockPos.getY() + 0.01F, blockPos.getZ() + 0.01F, blockPos.getX() + 0.99F, height, blockPos.getZ() + 0.99F),
|
| 40 | GizmoStyle.fill(ARGB.colorFromFloat(0.15F, 0.0F, 1.0F, 0.0F))
|
| 41 | );
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | for (BlockPos blockPos : BlockPos.betweenClosed(pos.offset(-10, -10, -10), pos.offset(10, 10, 10))) {
|
| 46 | FluidState fluidState = level.getFluidState(blockPos);
|
| 47 | if (fluidState.is(FluidTags.WATER)) {
|
| 48 | Gizmos.billboardText(
|
| 49 | String.valueOf(fluidState.getAmount()),
|
| 50 | Vec3.atLowerCornerWithOffset(blockPos, 0.5, fluidState.getHeight(level, blockPos), 0.5),
|
| 51 | Style.forColorAndCentered(-16777216)
|
| 52 | );
|
| 53 | }
|
| 54 | }
|
| 55 | }
|
| 56 | }
|
| 57 |
|