| 1 | package net.minecraft.client.renderer.debug;
|
| 2 |
|
| 3 | import com.google.common.collect.Iterables;
|
| 4 | import com.google.common.collect.Lists;
|
| 5 | import com.google.common.collect.Maps;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Locale;
|
| 8 | import java.util.Map;
|
| 9 | import java.util.Objects;
|
| 10 | import java.util.UUID;
|
| 11 | import net.fabricmc.api.EnvType;
|
| 12 | import net.fabricmc.api.Environment;
|
| 13 | import net.minecraft.client.Minecraft;
|
| 14 | import net.minecraft.client.renderer.culling.Frustum;
|
| 15 | import net.minecraft.core.BlockPos;
|
| 16 | import net.minecraft.gizmos.Gizmos;
|
| 17 | import net.minecraft.util.debug.DebugBrainDump;
|
| 18 | import net.minecraft.util.debug.DebugSubscriptions;
|
| 19 | import net.minecraft.util.debug.DebugValueAccess;
|
| 20 | import net.minecraft.world.entity.Entity;
|
| 21 | import org.jspecify.annotations.Nullable;
|
| 22 |
|
| 23 | @Environment(EnvType.CLIENT)
|
| 24 | public class BrainDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
|
| 25 | private static final boolean SHOW_NAME_FOR_ALL = true;
|
| 26 | private static final boolean SHOW_PROFESSION_FOR_ALL = false;
|
| 27 | private static final boolean SHOW_BEHAVIORS_FOR_ALL = false;
|
| 28 | private static final boolean SHOW_ACTIVITIES_FOR_ALL = false;
|
| 29 | private static final boolean SHOW_INVENTORY_FOR_ALL = false;
|
| 30 | private static final boolean SHOW_GOSSIPS_FOR_ALL = false;
|
| 31 | private static final boolean SHOW_HEALTH_FOR_ALL = false;
|
| 32 | private static final boolean SHOW_WANTS_GOLEM_FOR_ALL = true;
|
| 33 | private static final boolean SHOW_ANGER_LEVEL_FOR_ALL = false;
|
| 34 | private static final boolean SHOW_NAME_FOR_SELECTED = true;
|
| 35 | private static final boolean SHOW_PROFESSION_FOR_SELECTED = true;
|
| 36 | private static final boolean SHOW_BEHAVIORS_FOR_SELECTED = true;
|
| 37 | private static final boolean SHOW_ACTIVITIES_FOR_SELECTED = true;
|
| 38 | private static final boolean SHOW_MEMORIES_FOR_SELECTED = true;
|
| 39 | private static final boolean SHOW_INVENTORY_FOR_SELECTED = true;
|
| 40 | private static final boolean SHOW_GOSSIPS_FOR_SELECTED = true;
|
| 41 | private static final boolean SHOW_HEALTH_FOR_SELECTED = true;
|
| 42 | private static final boolean SHOW_WANTS_GOLEM_FOR_SELECTED = true;
|
| 43 | private static final boolean SHOW_ANGER_LEVEL_FOR_SELECTED = true;
|
| 44 | private static final int MAX_RENDER_DIST_FOR_BRAIN_INFO = 30;
|
| 45 | private static final int MAX_TARGETING_DIST = 8;
|
| 46 | private static final float TEXT_SCALE = 0.32F;
|
| 47 | private static final int CYAN = -16711681;
|
| 48 | private static final int GRAY = -3355444;
|
| 49 | private static final int PINK = -98404;
|
| 50 | private static final int ORANGE = -23296;
|
| 51 | private final Minecraft minecraft;
|
| 52 | private @Nullable UUID lastLookedAtUuid;
|
| 53 |
|
| 54 | public BrainDebugRenderer(final Minecraft minecraft) {
|
| 55 | this.minecraft = minecraft;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public void emitGizmos(
|
| 60 | final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
|
| 61 | ) {
|
| 62 | this.doRender(debugValues);
|
| 63 | if (!this.minecraft.player.isSpectator()) {
|
| 64 | this.updateLastLookedAtUuid();
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | private void doRender(final DebugValueAccess debugValues) {
|
| 69 | debugValues.forEachEntity(DebugSubscriptions.BRAINS, (entity, brainDump) -> {
|
| 70 | if (this.minecraft.player.closerThan(entity, 30.0)) {
|
| 71 | this.renderBrainInfo(entity, brainDump);
|
| 72 | }
|
| 73 | });
|
| 74 | }
|
| 75 |
|
| 76 | private void renderBrainInfo(final Entity entity, final DebugBrainDump brainDump) {
|
| 77 | boolean selected = this.isMobSelected(entity);
|
| 78 | int row = 0;
|
| 79 | Gizmos.billboardTextOverMob(entity, row, brainDump.name(), -1, 0.48F);
|
| 80 | row++;
|
| 81 | if (selected) {
|
| 82 | Gizmos.billboardTextOverMob(entity, row, brainDump.profession() + " " + brainDump.xp() + " xp", -1, 0.32F);
|
| 83 | row++;
|
| 84 | }
|
| 85 |
|
| 86 | if (selected) {
|
| 87 | int color = brainDump.health() < brainDump.maxHealth() ? -23296 : -1;
|
| 88 | Gizmos.billboardTextOverMob(
|
| 89 | entity,
|
| 90 | row,
|
| 91 | "health: " + String.format(Locale.ROOT, "%.1f", brainDump.health()) + " / " + String.format(Locale.ROOT, "%.1f", brainDump.maxHealth()),
|
| 92 | color,
|
| 93 | 0.32F
|
| 94 | );
|
| 95 | row++;
|
| 96 | }
|
| 97 |
|
| 98 | if (selected && !brainDump.inventory().equals("")) {
|
| 99 | Gizmos.billboardTextOverMob(entity, row, brainDump.inventory(), -98404, 0.32F);
|
| 100 | row++;
|
| 101 | }
|
| 102 |
|
| 103 | if (selected) {
|
| 104 | for (String goal : brainDump.behaviors()) {
|
| 105 | Gizmos.billboardTextOverMob(entity, row, goal, -16711681, 0.32F);
|
| 106 | row++;
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | if (selected) {
|
| 111 | for (String activity : brainDump.activities()) {
|
| 112 | Gizmos.billboardTextOverMob(entity, row, activity, -16711936, 0.32F);
|
| 113 | row++;
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | if (brainDump.wantsGolem()) {
|
| 118 | Gizmos.billboardTextOverMob(entity, row, "Wants Golem", -23296, 0.32F);
|
| 119 | row++;
|
| 120 | }
|
| 121 |
|
| 122 | if (selected && brainDump.angerLevel() != -1) {
|
| 123 | Gizmos.billboardTextOverMob(entity, row, "Anger Level: " + brainDump.angerLevel(), -98404, 0.32F);
|
| 124 | row++;
|
| 125 | }
|
| 126 |
|
| 127 | if (selected) {
|
| 128 | for (String gossip : brainDump.gossips()) {
|
| 129 | if (gossip.startsWith(brainDump.name())) {
|
| 130 | Gizmos.billboardTextOverMob(entity, row, gossip, -1, 0.32F);
|
| 131 | } else {
|
| 132 | Gizmos.billboardTextOverMob(entity, row, gossip, -23296, 0.32F);
|
| 133 | }
|
| 134 |
|
| 135 | row++;
|
| 136 | }
|
| 137 | }
|
| 138 |
|
| 139 | if (selected) {
|
| 140 | for (String memory : Lists.reverse(brainDump.memories())) {
|
| 141 | Gizmos.billboardTextOverMob(entity, row, memory, -3355444, 0.32F);
|
| 142 | row++;
|
| 143 | }
|
| 144 | }
|
| 145 | }
|
| 146 |
|
| 147 | private boolean isMobSelected(final Entity entity) {
|
| 148 | return Objects.equals(this.lastLookedAtUuid, entity.getUUID());
|
| 149 | }
|
| 150 |
|
| 151 | public Map<BlockPos, List<String>> getGhostPois(final DebugValueAccess debugValues) {
|
| 152 | Map<BlockPos, List<String>> ghostPois = Maps.newHashMap();
|
| 153 | debugValues.forEachEntity(DebugSubscriptions.BRAINS, (entity, brainDump) -> {
|
| 154 | for (BlockPos poiPos : Iterables.concat(brainDump.pois(), brainDump.potentialPois())) {
|
| 155 | ghostPois.computeIfAbsent(poiPos, k -> Lists.newArrayList()).add(brainDump.name());
|
| 156 | }
|
| 157 | });
|
| 158 | return ghostPois;
|
| 159 | }
|
| 160 |
|
| 161 | private void updateLastLookedAtUuid() {
|
| 162 | DebugRenderer.getTargetedEntity(this.minecraft.getCameraEntity(), 8).ifPresent(entity -> this.lastLookedAtUuid = entity.getUUID());
|
| 163 | }
|
| 164 | }
|
| 165 |
|