| 1 | package net.minecraft.client.renderer.debug;
|
| 2 |
|
| 3 | import java.util.ArrayList;
|
| 4 | import java.util.List;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.SharedConstants;
|
| 8 | import net.minecraft.client.renderer.culling.Frustum;
|
| 9 | import net.minecraft.core.BlockPos;
|
| 10 | import net.minecraft.gizmos.GizmoStyle;
|
| 11 | import net.minecraft.gizmos.Gizmos;
|
| 12 | import net.minecraft.network.protocol.game.DebugEntityNameGenerator;
|
| 13 | import net.minecraft.util.ARGB;
|
| 14 | import net.minecraft.util.debug.DebugPoiInfo;
|
| 15 | import net.minecraft.util.debug.DebugSubscriptions;
|
| 16 | import net.minecraft.util.debug.DebugValueAccess;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class PoiDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
|
| 20 | private static final int MAX_RENDER_DIST_FOR_POI_INFO = 30;
|
| 21 | private static final float TEXT_SCALE = 0.32F;
|
| 22 | private static final int ORANGE = -23296;
|
| 23 | private final BrainDebugRenderer brainRenderer;
|
| 24 |
|
| 25 | public PoiDebugRenderer(final BrainDebugRenderer brainRenderer) {
|
| 26 | this.brainRenderer = brainRenderer;
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public void emitGizmos(
|
| 31 | final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
|
| 32 | ) {
|
| 33 | BlockPos playerPos = BlockPos.containing(camX, camY, camZ);
|
| 34 | debugValues.forEachBlock(DebugSubscriptions.POIS, (pos, poi) -> {
|
| 35 | if (playerPos.closerThan(pos, 30.0)) {
|
| 36 | highlightPoi(pos);
|
| 37 | this.renderPoiInfo(poi, debugValues);
|
| 38 | }
|
| 39 | });
|
| 40 | this.brainRenderer.getGhostPois(debugValues).forEach((poiPos, value) -> {
|
| 41 | if (debugValues.getBlockValue(DebugSubscriptions.POIS, poiPos) == null) {
|
| 42 | if (playerPos.closerThan(poiPos, 30.0)) {
|
| 43 | this.renderGhostPoi(poiPos, (List<String>)value);
|
| 44 | }
|
| 45 | }
|
| 46 | });
|
| 47 | }
|
| 48 |
|
| 49 | private static void highlightPoi(final BlockPos poiPos) {
|
| 50 | float padding = 0.05F;
|
| 51 | Gizmos.cuboid(poiPos, 0.05F, GizmoStyle.fill(ARGB.colorFromFloat(0.3F, 0.2F, 0.2F, 1.0F)));
|
| 52 | }
|
| 53 |
|
| 54 | private void renderGhostPoi(final BlockPos poiPos, final List<String> names) {
|
| 55 | float padding = 0.05F;
|
| 56 | Gizmos.cuboid(poiPos, 0.05F, GizmoStyle.fill(ARGB.colorFromFloat(0.3F, 0.2F, 0.2F, 1.0F)));
|
| 57 | Gizmos.billboardTextOverBlock(names.toString(), poiPos, 0, -256, 0.32F);
|
| 58 | Gizmos.billboardTextOverBlock("Ghost POI", poiPos, 1, -65536, 0.32F);
|
| 59 | }
|
| 60 |
|
| 61 | private void renderPoiInfo(final DebugPoiInfo poi, final DebugValueAccess debugValues) {
|
| 62 | int row = 0;
|
| 63 | if (SharedConstants.DEBUG_BRAIN) {
|
| 64 | List<String> ticketHolderNames = this.getTicketHolderNames(poi, false, debugValues);
|
| 65 | if (ticketHolderNames.size() < 4) {
|
| 66 | renderTextOverPoi("Owners: " + ticketHolderNames, poi, row, -256);
|
| 67 | } else {
|
| 68 | renderTextOverPoi(ticketHolderNames.size() + " ticket holders", poi, row, -256);
|
| 69 | }
|
| 70 |
|
| 71 | row++;
|
| 72 | List<String> potentialTicketHolderNames = this.getTicketHolderNames(poi, true, debugValues);
|
| 73 | if (potentialTicketHolderNames.size() < 4) {
|
| 74 | renderTextOverPoi("Candidates: " + potentialTicketHolderNames, poi, row, -23296);
|
| 75 | } else {
|
| 76 | renderTextOverPoi(potentialTicketHolderNames.size() + " potential owners", poi, row, -23296);
|
| 77 | }
|
| 78 |
|
| 79 | row++;
|
| 80 | }
|
| 81 |
|
| 82 | renderTextOverPoi("Free tickets: " + poi.freeTicketCount(), poi, row, -256);
|
| 83 | renderTextOverPoi(poi.poiType().getRegisteredName(), poi, ++row, -1);
|
| 84 | }
|
| 85 |
|
| 86 | private static void renderTextOverPoi(final String text, final DebugPoiInfo poi, final int row, final int color) {
|
| 87 | Gizmos.billboardTextOverBlock(text, poi.pos(), row, color, 0.32F);
|
| 88 | }
|
| 89 |
|
| 90 | private List<String> getTicketHolderNames(final DebugPoiInfo poi, final boolean potential, final DebugValueAccess debugValues) {
|
| 91 | List<String> names = new ArrayList<>();
|
| 92 | debugValues.forEachEntity(DebugSubscriptions.BRAINS, (entity, brainDump) -> {
|
| 93 | boolean include = potential ? brainDump.hasPotentialPoi(poi.pos()) : brainDump.hasPoi(poi.pos());
|
| 94 | if (include) {
|
| 95 | names.add(DebugEntityNameGenerator.getEntityName(entity.getUUID()));
|
| 96 | }
|
| 97 | });
|
| 98 | return names;
|
| 99 | }
|
| 100 | }
|
| 101 |
|