| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Licensed under the GNU General Public License v3.0.
|
| 6 | */
|
| 7 |
|
| 8 | package combatant.client.features.module.modules.visuals;
|
| 9 |
|
| 10 | import combatant.client.render.engine.text.BuiltinFontCatalog;
|
| 11 | import combatant.client.config.values.*;
|
| 12 | import combatant.client.features.gui.hud.HudRenderSpace;
|
| 13 | import combatant.client.features.module.*;
|
| 14 | import combatant.client.features.module.Module;
|
| 15 | import combatant.client.render.helpers.*;
|
| 16 | import combatant.client.util.item.EnchantUtil;
|
| 17 | import combatant.client.util.player.PlayerSkinResolver;
|
| 18 | import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
| 19 | import net.minecraft.ChatFormatting;
|
| 20 | import net.minecraft.client.CameraType;
|
| 21 | import net.minecraft.client.Minecraft;
|
| 22 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 23 | import net.minecraft.client.gui.Hud;
|
| 24 | import net.minecraft.client.multiplayer.PlayerInfo;
|
| 25 | import net.minecraft.client.player.AbstractClientPlayer;
|
| 26 | import net.minecraft.client.resources.language.I18n;
|
| 27 | import net.minecraft.client.renderer.texture.TextureAtlas;
|
| 28 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
| 29 | import net.minecraft.core.Holder;
|
| 30 | import net.minecraft.data.AtlasIds;
|
| 31 | import net.minecraft.network.chat.Component;
|
| 32 | import net.minecraft.network.chat.MutableComponent;
|
| 33 | import net.minecraft.resources.Identifier;
|
| 34 | import net.minecraft.resources.ResourceKey;
|
| 35 | import net.minecraft.util.Mth;
|
| 36 | import net.minecraft.world.effect.MobEffectInstance;
|
| 37 | import net.minecraft.world.entity.Entity;
|
| 38 | import net.minecraft.world.entity.EquipmentSlot;
|
| 39 | import net.minecraft.world.entity.player.Player;
|
| 40 | import net.minecraft.world.item.Item;
|
| 41 | import net.minecraft.world.item.ItemStack;
|
| 42 | import net.minecraft.world.item.Items;
|
| 43 | import net.minecraft.world.item.enchantment.Enchantment;
|
| 44 | import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
| 45 | import net.minecraft.world.item.enchantment.ItemEnchantments;
|
| 46 | import net.minecraft.world.level.GameType;
|
| 47 | import net.minecraft.world.phys.AABB;
|
| 48 | import net.minecraft.world.phys.Vec3;
|
| 49 | import combatant.client.config.SettingDef;
|
| 50 | import combatant.client.config.common.CommonSettingSchemas;
|
| 51 | import combatant.client.features.gui.clickgui.settings.TextListSetting;
|
| 52 | import combatant.client.features.module.modules.combat.PvpCooldowns;
|
| 53 | import combatant.client.features.relations.CategoryService;
|
| 54 | import combatant.client.features.relations.PlayerRelations;
|
| 55 | import combatant.client.mixininterface.IEntity;
|
| 56 | import combatant.client.render.engine.animation.AnimationUtility;
|
| 57 | import combatant.client.render.engine.color.RenderColor;
|
| 58 | import combatant.client.render.engine.RenderState;
|
| 59 | import combatant.client.render.engine.core.ViewportContext;
|
| 60 | import combatant.client.render.engine.renderer.Renderer2D;
|
| 61 | import combatant.client.render.engine.renderer.Renderer3D;
|
| 62 | import combatant.client.render.engine.renderer.ui.ItemBatchRenderer;
|
| 63 | import combatant.client.render.engine.text.RuntimeTextLayout;
|
| 64 | import combatant.client.render.engine.text.TextRenderer;
|
| 65 | import combatant.client.render.engine.text.WorldTextRenderer;
|
| 66 | import combatant.client.render.engine.world.WorldBillboardRenderer;
|
| 67 | import combatant.client.render.engine.world.WorldUiPresentationService;
|
| 68 | import combatant.client.util.item.EnchantMeta;
|
| 69 | import combatant.client.util.item.EnchantRegistry;
|
| 70 | import combatant.client.util.item.IllegalItemUtil;
|
| 71 | import combatant.client.util.item.RarityColorUtil;
|
| 72 | import combatant.client.util.item.TopEnchantUtil;
|
| 73 | import combatant.client.util.player.PlayerHealthResolver;
|
| 74 | import combatant.client.util.player.effect.StatusEffectTracker;
|
| 75 | import combatant.client.util.player.effect.StatusEffectView;
|
| 76 | import combatant.client.util.pvp.CooldownRegistry;
|
| 77 | import combatant.client.util.pvp.ItemCooldownSnapshot;
|
| 78 | import combatant.client.util.pvp.PvpTargetState;
|
| 79 | import combatant.client.util.pvp.opponents.OpponentCooldownManager;
|
| 80 | import combatant.client.util.pvp.opponents.TotemPopCounter;
|
| 81 | import combatant.client.util.pvp.opponents.TotemPopSnapshot;
|
| 82 | import combatant.client.util.text.LegacyTextUtil;
|
| 83 | import combatant.client.util.text.TextRenderUtil;
|
| 84 |
|
| 85 | import java.util.*;
|
| 86 |
|
| 87 |
|
| 88 | //todo Description
|
| 89 | @ModuleInfo(id = "nametags", displayName = "NameTags", aliases = {"nametag", "tags", "names"}, category = ModuleCategory.VISUALS)
|
| 90 | public class NameTags extends Module {
|
| 91 |
|
| 92 | // Screen-space geometry is authored directly in UNSCALED_LOGICAL units.
|
| 93 | // No GUI-scale/framebuffer multipliers belong in the feature code.
|
| 94 | // rich_src is used only as a visual reference. Its 2x presentation has already
|
| 95 | // been baked into these direct logical-unit constants; there is no runtime GUI-scale math.
|
| 96 | private static final float RICH_TEXT_LOGICAL_HEIGHT = 20.0f;
|
| 97 | private static final float NAMEPLATE_SCALE = 1.06f;
|
| 98 | private static final float SMALL_TEXT_SCALE = 0.88f;
|
| 99 |
|
| 100 | private static final int ICON_SIZE = 24;
|
| 101 | private static final int ICON_GAP = 5;
|
| 102 | private static final int EQUIP_ICON_SIZE = 28;
|
| 103 | private static final int EQUIP_ICON_GAP = 6;
|
| 104 | private static final int EFFECT_LINE_HEIGHT = 26;
|
| 105 | private static final int EFFECT_X_OFFSET = 6;
|
| 106 | private static final int EFFECT_LEVEL_COLOR = 0xFFBFC6D1;
|
| 107 | private static final int EFFECT_ROW_GAP = 10;
|
| 108 | private static final int EFFECT_ROW_ICON_GAP = 8;
|
| 109 | private static final int EFFECT_ROW_TEXT_GAP = 4;
|
| 110 | private static final int EFFECT_ROW_LEVEL_GAP = 3;
|
| 111 | private static final int EFFECT_ROW_TIME_GAP = 2;
|
| 112 | private static final float EFFECT_ROW_SCALE = 1.15f;
|
| 113 |
|
| 114 | private static final float NAMEPLATE_PAD_X = 4.4f;
|
| 115 | private static final float NAMEPLATE_PAD_Y = 1.65f;
|
| 116 | private static final float MATTE_NAMEPLATE_RADIUS = 4.4f;
|
| 117 | private static final float MATTE_HEAD_MIN_SIZE = 18.0f;
|
| 118 | private static final float MATTE_HEAD_DIVIDER_GAP = 4.4f;
|
| 119 | private static final float MATTE_HEAD_DIVIDER_WIDTH = 1.1f;
|
| 120 | private static final float MATTE_HEAD_TEXT_GAP = 4.4f;
|
| 121 | private static final float TOTEM_BADGE_GAP = 4.4f;
|
| 122 | private static final float TOTEM_BADGE_DIVIDER_WIDTH = 1.1f;
|
| 123 | private static final float TOTEM_BADGE_DIVIDER_GAP = 4.4f;
|
| 124 | private static final float TOTEM_BADGE_MIN_WIDTH = 24.0f;
|
| 125 | private static final float TOTEM_BADGE_PAD_X = 4.0f;
|
| 126 | private static final float TOTEM_BADGE_ICON_SIZE = 18.0f;
|
| 127 | private static final float TOTEM_BADGE_TEXT_GAP = 3.3f;
|
| 128 | private static final float TOTEM_BADGE_TEXT_SCALE = NAMEPLATE_SCALE;
|
| 129 | private static final float TOTEM_BADGE_ANIM_SPEED = 10.0f;
|
| 130 | private static final float ENCHANT_TEXT_MIN_GAP = 2.0f;
|
| 131 | private static final int ENCHANT_NAME_MAX_CODEPOINTS = 2;
|
| 132 | private static final WorldUiPresentationService.Policy WORLD_PRESENTATION_POLICY =
|
| 133 | WorldUiPresentationService.Policy.defaults();
|
| 134 | private static final int DIST_TEXT_GAP = 5;
|
| 135 | private static final int PING_TEXT_GAP = 5;
|
| 136 | private static final int HP_TEXT_GAP = 5;
|
| 137 | private static final int HP_GREEN = 0xFF55FF55;
|
| 138 | private static final int HP_CYAN = 0xFF55FFFF;
|
| 139 | private static final int HP_RED = 0xFFFF5555;
|
| 140 | private static final int INFO_COLOR_DEFAULT = 0xFFFF8A8A;
|
| 141 | private static final int EFFECT_LEVEL_STACK_COLOR = 0xFFFF4444;
|
| 142 | private static final int EFFECT_TIME_COLOR = 0xFFCCCCCC;
|
| 143 | private static final int OPP_TIME_COLOR = 0xFFFFFFFF;
|
| 144 | private static final int OPP_TIME_COLOR_GRACE = 0xFF4DA6FF;
|
| 145 | private static final int OPP_STACK_Y_OFFSET = 10;
|
| 146 | private static final int OPPONENT_DISTANCE = 80;
|
| 147 | private static final int EFFECT_CACHE_TICKS = 4;
|
| 148 | private static final int ENCHANT_CACHE_TICKS = 2;
|
| 149 | private static final ItemStack[] EMPTY_SLOTS = new ItemStack[0];
|
| 150 | private static ItemStack totemBadgeStack;
|
| 151 |
|
| 152 | private static ItemStack totemBadgeStack() {
|
| 153 | if (totemBadgeStack == null || totemBadgeStack.isEmpty()) {
|
| 154 | totemBadgeStack = new ItemStack(Items.TOTEM_OF_UNDYING);
|
| 155 | }
|
| 156 | return totemBadgeStack;
|
| 157 | }
|
| 158 | private static final String SETTING_TOGGLES = "toggles";
|
| 159 | private static final String SETTING_DURABILITY_START = "durability_start_percent";
|
| 160 | private static final String SETTING_LIMIT_DISTANCE = "limit_distance";
|
| 161 | private static final String SETTING_DISTANCE_TOGGLES = "distance_toggles";
|
| 162 | private static final String SETTING_NAMEPLATE_CUTOFF = "nameplate_cutoff";
|
| 163 | private static final String SETTING_SLOTS_CUTOFF = "slots_cutoff";
|
| 164 | private static final String SETTING_EFFECTS_CUTOFF = "effects_cutoff";
|
| 165 | private static final String SETTING_ARMOR_ENCHANTS = "armor_enchants";
|
| 166 | private static final String SETTING_MELEE_ENCHANTS = "melee_enchants";
|
| 167 | private static final String SETTING_TOOLS_ENCHANTS = "tools_enchants";
|
| 168 | private static final String SETTING_BOW_ENCHANTS = "bow_enchants";
|
| 169 | private static final String SETTING_FISHING_ENCHANTS = "fishing_enchants";
|
| 170 | private static final String SETTING_TRIDENT_ENCHANTS = "trident_enchants";
|
| 171 | private static final String SETTING_CROSSBOW_ENCHANTS = "crossbow_enchants";
|
| 172 | private static final String SETTING_MACE_ENCHANTS = "mace_enchants";
|
| 173 | private static final String SETTING_OTHER_ENCHANTS = "other_enchants";
|
| 174 | private static final String SETTING_ILLEGAL_ENCHANT_COLOR = "illegal_enchant_color";
|
| 175 | private static final String SETTING_ILLEGAL_ENCHANTS_ALWAYS = "illegal_enchants_always";
|
| 176 | private static final String SETTING_TOP_ENCHANT_COLOR = "top_enchant_color";
|
| 177 | private static final String SETTING_TOP_ENCHANT_IGNORE_LIST = "top_enchant_ignore_list";
|
| 178 | private static final String SETTING_DEFAULT_NAME_COLOR = "default_name_color";
|
| 179 | private static final String SETTING_FRIEND_NAME_COLOR = "friend_name_color";
|
| 180 | private static final String SETTING_ENEMY_NAME_COLOR = "enemy_name_color";
|
| 181 | private static final String SETTING_STAFF_NAME_COLOR = "staff_name_color";
|
| 182 | private static final String SETTING_HP_DECIMALS = "hp_decimals";
|
| 183 | private static final String SETTING_HP_COLOR_MODE = "hp_color_mode";
|
| 184 | private static final String SETTING_NAMEPLATE_ALPHA = "nameplate_alpha";
|
| 185 | private static final String SETTING_PRESENTATION_MODE = "presentation_mode";
|
| 186 | private static final String SETTING_WORLD_SIZE = "world_size";
|
| 187 | private static final String SETTING_DYNAMIC_WORLD_SCALE = "dynamic_world_scale";
|
| 188 | private static final String SETTING_DYNAMIC_WORLD_SCALE_COEFFICIENT = "dynamic_world_scale_coefficient";
|
| 189 | private static final String SETTING_PLAYER_HEAD = "player_head";
|
| 190 | private static final String SETTING_NAMEPLATE_EXTRAS = "nameplate_extras";
|
| 191 | // Match ESP.java projected player box exactly, then place both external blocks
|
| 192 | // from that same visual reference so top/bottom spacing stays symmetric.
|
| 193 | private static final double ESP_REFERENCE_TOP_OFFSET = 0.18;
|
| 194 | private static final float FRAME_CONTENT_GAP = 3.5f;
|
| 195 | private static final float EQUIPMENT_TO_NAMEPLATE_GAP = 5.0f;
|
| 196 | private static final int REFERENCE_BACKDROP_ALPHA = 148;
|
| 197 | private static final int REFERENCE_BACKDROP_RGB = 0x000000;
|
| 198 | private static final int REFERENCE_DIVIDER_RGB = 0xFFFFFF;
|
| 199 | private static final int REFERENCE_DIVIDER_ALPHA = 72;
|
| 200 | private static final float MAIN_HAND_PAD_X = 4.4f;
|
| 201 | private static final float MAIN_HAND_PAD_Y = 1.65f;
|
| 202 | private static final float MAIN_HAND_ICON_SIZE = 18.0f;
|
| 203 | private static final float MAIN_HAND_ICON_GAP = 4.4f;
|
| 204 | private static final float MAIN_HAND_TEXT_SCALE = NAMEPLATE_SCALE;
|
| 205 | private static final float MAIN_HAND_RADIUS = 4.4f;
|
| 206 | private static final String SETTING_OPPONENT_APPLE_COOLDOWNS = "opponent_apple_cooldowns";
|
| 207 | private static final String SETTING_PVP_PREFIX = "pvp_prefix";
|
| 208 | private static final String SETTING_PVP_PREFIX_COLOR = "pvp_prefix_color";
|
| 209 | private final Minecraft mc = Minecraft.getInstance();
|
| 210 | private final ItemIdSetValue topIgnore = TopEnchantUtil.ignoreValue();
|
| 211 | private final List<RenderEntry> renderQueue = new ArrayList<>();
|
| 212 | private final List<WorldRenderEntry> worldRenderQueue = new ArrayList<>();
|
| 213 | private final List<ItemBatchRenderer.WorldItemRow> worldItemRows = new ArrayList<>();
|
| 214 | private final List<Player> playerBuffer = new ArrayList<>();
|
| 215 | private final Map<UUID, ItemStack[]> slotCache = new HashMap<>();
|
| 216 | private final Map<UUID, EffectCache> effectCache = new HashMap<>();
|
| 217 | private final Map<UUID, EnchantCache> enchantCache = new HashMap<>();
|
| 218 | private final Map<UUID, Float> totemPopAnimations = new HashMap<>();
|
| 219 | private final Map<UUID, Integer> totemPopLastCounts = new HashMap<>();
|
| 220 | private final HashSet<UUID> seenIds = new HashSet<>();
|
| 221 | private final BooleanMapValue toggles = group("nameTagsToggles", SETTING_TOGGLES, Map.of(
|
| 222 | "Show nameplate", true,
|
| 223 | "Show distance", true,
|
| 224 | "Show armor row", true,
|
| 225 | "Show main hand", true,
|
| 226 | "Item durability bar", true,
|
| 227 | "Show effects", true,
|
| 228 | "Show self in 3rd person", false
|
| 229 | ));
|
| 230 | private final NumberValue<Integer> durabilityStartPercent =
|
| 231 | visibleWhen(num("nameTagsDurabilityStartPercent", SETTING_DURABILITY_START, 99, 0, 100),
|
| 232 | () -> toggles.get("Item durability bar"));
|
| 233 | private final BooleanValue limitDistance =
|
| 234 | visibleWhen(bool("nameTagsLimitDistance", SETTING_LIMIT_DISTANCE, false),
|
| 235 | () -> toggles.get("Show nameplate") || toggles.get("Show main hand")
|
| 236 | || toggles.get("Show armor row") || toggles.get("Show effects"));
|
| 237 | private final BooleanMapValue distanceToggles =
|
| 238 | visibleWhen(group("nameTagsDistanceToggles", SETTING_DISTANCE_TOGGLES, Map.of(
|
| 239 | "nameplate", true,
|
| 240 | "slots", true,
|
| 241 | "effects", true
|
| 242 | )), () -> limitDistance.get() && (toggles.get("Show nameplate") || toggles.get("Show main hand")
|
| 243 | || toggles.get("Show armor row") || toggles.get("Show effects")));
|
| 244 | private final NumberValue<Integer> plateDistance =
|
| 245 | visibleWhen(num("nameTagsPlateDistance", SETTING_NAMEPLATE_CUTOFF, 80, 5, 256),
|
| 246 | () -> usesDistanceCutoff("nameplate") && (toggles.get("Show nameplate") || toggles.get("Show main hand")));
|
| 247 | private final NumberValue<Integer> slotsDistance =
|
| 248 | visibleWhen(num("nameTagsSlotsDistance", SETTING_SLOTS_CUTOFF, 70, 5, 256),
|
| 249 | () -> usesDistanceCutoff("slots") && toggles.get("Show armor row"));
|
| 250 | private final NumberValue<Integer> effectsDistance =
|
| 251 | visibleWhen(num("nameTagsEffectsDistance", SETTING_EFFECTS_CUTOFF, 90, 5, 256),
|
| 252 | () -> usesDistanceCutoff("effects") && toggles.get("Show effects"));
|
| 253 | private final NumberValue<Integer> nameplateAlpha =
|
| 254 | visibleWhen(num("nameTagsNameplateAlpha", SETTING_NAMEPLATE_ALPHA, REFERENCE_BACKDROP_ALPHA, 0, 255),
|
| 255 | () -> toggles.get("Show nameplate"));
|
| 256 | private final EnumValue<PresentationMode> presentationMode =
|
| 257 | enumSetting("nameTagsPresentationMode", SETTING_PRESENTATION_MODE, PresentationMode.HYBRID, PresentationMode.values());
|
| 258 | private final NumberValue<Float> worldSize =
|
| 259 | visibleWhen(num("nameTagsWorldSize", SETTING_WORLD_SIZE, 0.72f, 0.35f, 1.50f),
|
| 260 | () -> presentationMode.get() != PresentationMode.TWO_D);
|
| 261 | private final BooleanValue dynamicWorldScale =
|
| 262 | visibleWhen(bool("nameTagsDynamicWorldScale", SETTING_DYNAMIC_WORLD_SCALE, true),
|
| 263 | () -> presentationMode.get() != PresentationMode.TWO_D);
|
| 264 | private final NumberValue<Float> dynamicWorldScaleCoefficient =
|
| 265 | visibleWhen(num("nameTagsDynamicWorldScaleCoefficient", SETTING_DYNAMIC_WORLD_SCALE_COEFFICIENT, 0.25f, 0.0f, 1.0f),
|
| 266 | () -> presentationMode.get() != PresentationMode.TWO_D && dynamicWorldScale.get());
|
| 267 | private final BooleanValue playerHead =
|
| 268 | visibleWhen(bool("nameTagsPlayerHead", SETTING_PLAYER_HEAD, false),
|
| 269 | () -> toggles.get("Show nameplate"));
|
| 270 | private final BooleanMapValue nameplateExtras = visibleWhen(group("nameTagsNameplateExtras", SETTING_NAMEPLATE_EXTRAS, new LinkedHashMap<>() {{
|
| 271 | put("Tab names", false);
|
| 272 | put("Ping", false);
|
| 273 | }}), () -> toggles.get("Show nameplate"));
|
| 274 | private final BooleanMapValue enchantArmor = group("nameTagsEnchantArmor", SETTING_ARMOR_ENCHANTS, Map.ofEntries(
|
| 275 | Map.entry("protection", true),
|
| 276 | Map.entry("fire_protection", false),
|
| 277 | Map.entry("feather_falling", false),
|
| 278 | Map.entry("blast_protection", false),
|
| 279 | Map.entry("projectile_protection", false),
|
| 280 | Map.entry("respiration", false),
|
| 281 | Map.entry("aqua_affinity", false),
|
| 282 | Map.entry("thorns", true),
|
| 283 | Map.entry("depth_strider", false),
|
| 284 | Map.entry("frost_walker", false),
|
| 285 | Map.entry("soul_speed", false),
|
| 286 | Map.entry("swift_sneak", false)
|
| 287 | ));
|
| 288 | private final BooleanMapValue enchantMelee = group("nameTagsEnchantMelee", SETTING_MELEE_ENCHANTS, Map.ofEntries(
|
| 289 | Map.entry("sharpness", true),
|
| 290 | Map.entry("smite", false),
|
| 291 | Map.entry("bane_of_arthropods", false),
|
| 292 | Map.entry("knockback", true),
|
| 293 | Map.entry("fire_aspect", true),
|
| 294 | Map.entry("looting", true),
|
| 295 | Map.entry("sweeping_edge", false)
|
| 296 | ));
|
| 297 | private final BooleanMapValue enchantTools = group("nameTagsEnchantTools", SETTING_TOOLS_ENCHANTS, Map.ofEntries(
|
| 298 | Map.entry("efficiency", true),
|
| 299 | Map.entry("silk_touch", true),
|
| 300 | Map.entry("fortune", true)
|
| 301 | ));
|
| 302 | private final BooleanMapValue enchantBow = group("nameTagsEnchantBow", SETTING_BOW_ENCHANTS, Map.ofEntries(
|
| 303 | Map.entry("power", true),
|
| 304 | Map.entry("punch", true),
|
| 305 | Map.entry("flame", false),
|
| 306 | Map.entry("infinity", false)
|
| 307 | ));
|
| 308 | private final BooleanMapValue enchantFishing = group("nameTagsEnchantFishing", SETTING_FISHING_ENCHANTS, Map.ofEntries(
|
| 309 | Map.entry("luck_of_the_sea", false),
|
| 310 | Map.entry("lure", false)
|
| 311 | ));
|
| 312 | private final BooleanMapValue enchantTrident = group("nameTagsEnchantTrident", SETTING_TRIDENT_ENCHANTS, Map.ofEntries(
|
| 313 | Map.entry("loyalty", false),
|
| 314 | Map.entry("impaling", false),
|
| 315 | Map.entry("riptide", false),
|
| 316 | Map.entry("channeling", false)
|
| 317 | ));
|
| 318 | private final BooleanMapValue enchantCrossbow = group("nameTagsEnchantCrossbow", SETTING_CROSSBOW_ENCHANTS, Map.ofEntries(
|
| 319 | Map.entry("multishot", false),
|
| 320 | Map.entry("quick_charge", false),
|
| 321 | Map.entry("piercing", true)
|
| 322 | ));
|
| 323 | private final BooleanMapValue enchantMace = group("nameTagsEnchantMace", SETTING_MACE_ENCHANTS, Map.ofEntries(
|
| 324 | Map.entry("density", true),
|
| 325 | Map.entry("breach", false),
|
| 326 | Map.entry("wind_burst", true)
|
| 327 | ));
|
| 328 | private final BooleanMapValue enchantOther = group("nameTagsEnchantOther", SETTING_OTHER_ENCHANTS, Map.ofEntries(
|
| 329 | Map.entry("mending", false),
|
| 330 | Map.entry("unbreaking", false),
|
| 331 | Map.entry("vanishing_curse", false),
|
| 332 | Map.entry("lunge", true)
|
| 333 | ));
|
| 334 | private final BooleanValue illegalEnchantsAlways = bool("nameTagsIllegalEnchantsAlways", SETTING_ILLEGAL_ENCHANTS_ALWAYS, true);
|
| 335 | private final BooleanValue opponentAppleCooldowns = bool("nameTagsOpponentAppleCooldowns", SETTING_OPPONENT_APPLE_COOLDOWNS, true);
|
| 336 | private final BooleanValue totemPopCounter = TotemPopCounter.enabledValue();
|
| 337 | private final NumberValue<Integer> totemPopResetSeconds = TotemPopCounter.resetAfterSecondsValue();
|
| 338 | private final BooleanValue pvpPrefix = bool("nameTagsPvpPrefix", SETTING_PVP_PREFIX, false);
|
| 339 | private final RGBColorValue pvpPrefixColor =
|
| 340 | visibleWhen(colorNoAlpha("nameTagsPvpPrefixColor", SETTING_PVP_PREFIX_COLOR, "#FF0000"), pvpPrefix::get);
|
| 341 | private final BooleanValue hpDecimals =
|
| 342 | visibleWhen(bool("nameTagsHpDecimals", SETTING_HP_DECIMALS, false),
|
| 343 | () -> toggles.get("Show nameplate"));
|
| 344 | private final ModeValue hpColorMode =
|
| 345 | visibleWhen(modeSetting("nameTagsHpColorMode", SETTING_HP_COLOR_MODE, "Static", "Static", "Gradient"),
|
| 346 | () -> toggles.get("Show nameplate"));
|
| 347 | private transient TextRenderer cachedNameTr;
|
| 348 | private transient TextRenderer cachedHpTr;
|
| 349 | private transient TextRenderer cachedLevelTr;
|
| 350 | private transient TextRenderer cachedTimeTr;
|
| 351 | private transient float foregroundAlpha = 1.0f;
|
| 352 |
|
| 353 | {
|
| 354 | setting(SettingDef.bool(totemPopCounter)
|
| 355 | .common(CommonSettingSchemas.TOTEM_POP_COUNTER.commonI18nKey()));
|
| 356 | setting(SettingDef.number(totemPopResetSeconds)
|
| 357 | .common(CommonSettingSchemas.TOTEM_POP_RESET_SECONDS.commonI18nKey())
|
| 358 | .visibleWhen(totemPopCounter::get));
|
| 359 | setting(SettingDef.colorNoAlpha(SETTING_ILLEGAL_ENCHANT_COLOR, IllegalItemUtil.illegalColorValue()));
|
| 360 | setting(SettingDef.colorNoAlpha(SETTING_TOP_ENCHANT_COLOR, TopEnchantUtil.topColorValue()));
|
| 361 | setting(SettingDef.textList(SETTING_TOP_ENCHANT_IGNORE_LIST, topIgnore, TextListSetting.PickerMode.ENCHANTMENTS));
|
| 362 | }
|
| 363 |
|
| 364 | private static int withAlpha(int argb, int alpha) {
|
| 365 | return (argb & 0x00FFFFFF) | (alpha << 24);
|
| 366 | }
|
| 367 |
|
| 368 | private static String formatNameplateHp(String hp) {
|
| 369 | return hp == null || hp.isEmpty() ? "" : "[" + hp + "]";
|
| 370 | }
|
| 371 |
|
| 372 | private static int clampAlpha(int a) {
|
| 373 | if (a < 0) return 0;
|
| 374 | if (a > 255) return 255;
|
| 375 | return a;
|
| 376 | }
|
| 377 |
|
| 378 | private static int equipmentSignature(ItemStack[] slots) {
|
| 379 | if (slots == null || slots.length == 0) return 1;
|
| 380 | int hash = 1;
|
| 381 | for (ItemStack stack : slots) {
|
| 382 | hash = 31 * hash + itemSignature(stack);
|
| 383 | }
|
| 384 | return hash;
|
| 385 | }
|
| 386 |
|
| 387 | private static int itemSignature(ItemStack stack) {
|
| 388 | if (stack == null || stack.isEmpty()) return 0;
|
| 389 | int hash = 17;
|
| 390 | hash = 31 * hash + Item.getId(stack.getItem());
|
| 391 | hash = 31 * hash + stack.getCount();
|
| 392 | hash = 31 * hash + stack.getDamageValue();
|
| 393 | hash = 31 * hash + stack.getComponents().hashCode();
|
| 394 | return hash;
|
| 395 | }
|
| 396 |
|
| 397 | private static int scaleRow(int value) {
|
| 398 | return Math.round(value * EFFECT_ROW_SCALE);
|
| 399 | }
|
| 400 |
|
| 401 | private static int equipIconSize() {
|
| 402 | return EQUIP_ICON_SIZE;
|
| 403 | }
|
| 404 |
|
| 405 | private static int equipIconGap() {
|
| 406 | return EQUIP_ICON_GAP;
|
| 407 | }
|
| 408 |
|
| 409 | private static int resolvePingColor(int ping) {
|
| 410 | if (ping < 0) {
|
| 411 | return 0xFFD0D0D0;
|
| 412 | }
|
| 413 | if (ping <= 70) {
|
| 414 | return 0xFF55FF55;
|
| 415 | }
|
| 416 | if (ping >= 200) {
|
| 417 | return 0xFFFF5555;
|
| 418 | }
|
| 419 |
|
| 420 | if (ping <= 135) {
|
| 421 | float t = (ping - 70.0f) / 65.0f;
|
| 422 | return mixColor(0xFF55FF55, 0xFFFFFF55, t);
|
| 423 | }
|
| 424 |
|
| 425 | float t = (ping - 135.0f) / 65.0f;
|
| 426 | return mixColor(0xFFFFFF55, 0xFFFF5555, t);
|
| 427 | }
|
| 428 |
|
| 429 | private static int mixColor(int start, int end, float t) {
|
| 430 | t = Mth.clamp(t, 0.0f, 1.0f);
|
| 431 | int sa = (start >>> 24) & 0xFF;
|
| 432 | int sr = (start >>> 16) & 0xFF;
|
| 433 | int sg = (start >>> 8) & 0xFF;
|
| 434 | int sb = start & 0xFF;
|
| 435 | int ea = (end >>> 24) & 0xFF;
|
| 436 | int er = (end >>> 16) & 0xFF;
|
| 437 | int eg = (end >>> 8) & 0xFF;
|
| 438 | int eb = end & 0xFF;
|
| 439 | int a = (int) (sa + (ea - sa) * t + 0.5f);
|
| 440 | int r = (int) (sr + (er - sr) * t + 0.5f);
|
| 441 | int g = (int) (sg + (eg - sg) * t + 0.5f);
|
| 442 | int b = (int) (sb + (eb - sb) * t + 0.5f);
|
| 443 | return (a << 24) | (r << 16) | (g << 8) | b;
|
| 444 | }
|
| 445 |
|
| 446 | private static boolean beginTextRenderer(TextRenderer textRenderer, double scale) {
|
| 447 | if (textRenderer == null || textRenderer.isBuilding()) return false;
|
| 448 | textRenderer.begin(scale);
|
| 449 | return true;
|
| 450 | }
|
| 451 |
|
| 452 | private static void endTextRenderer(TextRenderer textRenderer, boolean started) {
|
| 453 | if (!started || textRenderer == null || !textRenderer.isBuilding()) return;
|
| 454 | textRenderer.end();
|
| 455 | }
|
| 456 |
|
| 457 | private static int lerpColor(int a, int b, float t) {
|
| 458 | int aA = (a >>> 24) & 0xFF;
|
| 459 | int aR = (a >>> 16) & 0xFF;
|
| 460 | int aG = (a >>> 8) & 0xFF;
|
| 461 | int aB = a & 0xFF;
|
| 462 | int bA = (b >>> 24) & 0xFF;
|
| 463 | int bR = (b >>> 16) & 0xFF;
|
| 464 | int bG = (b >>> 8) & 0xFF;
|
| 465 | int bB = b & 0xFF;
|
| 466 | int oA = Math.round(lerp(aA, bA, t));
|
| 467 | int oR = Math.round(lerp(aR, bR, t));
|
| 468 | int oG = Math.round(lerp(aG, bG, t));
|
| 469 | int oB = Math.round(lerp(aB, bB, t));
|
| 470 | return (oA << 24) | (oR << 16) | (oG << 8) | oB;
|
| 471 | }
|
| 472 |
|
| 473 | private static float lerp(float a, float b, float t) {
|
| 474 | return a + (b - a) * t;
|
| 475 | }
|
| 476 |
|
| 477 | private static boolean hasOpponentCooldowns(UUID playerId) {
|
| 478 | if (playerId == null) return false;
|
| 479 | for (Item item : CooldownRegistry.trackedItems()) {
|
| 480 | if (OpponentCooldownManager.snapshot(playerId, item).visible()) {
|
| 481 | return true;
|
| 482 | }
|
| 483 | }
|
| 484 | return false;
|
| 485 | }
|
| 486 |
|
| 487 | private static String secondsTextInt(float secondsLeft) {
|
| 488 | int sec = Math.max(0, (int) Math.ceil(secondsLeft));
|
| 489 | return String.valueOf(sec);
|
| 490 | }
|
| 491 |
|
| 492 | private static boolean pushNameplateScissor(NameplateLayout layout) {
|
| 493 | if (layout == null) return false;
|
| 494 | Minecraft mc = Minecraft.getInstance();
|
| 495 | if (mc == null || mc.getWindow() == null) return false;
|
| 496 |
|
| 497 | int sw = mc.getWindow().getScreenWidth();
|
| 498 | int sh = mc.getWindow().getScreenHeight();
|
| 499 |
|
| 500 | int x1 = Math.max(0, (int) Math.floor(layout.bgX()));
|
| 501 | int y1 = Math.max(0, (int) Math.floor(layout.bgY()));
|
| 502 | int x2 = Math.min(sw, (int) Math.ceil(layout.bgX() + layout.bgW()));
|
| 503 | int y2 = Math.min(sh, (int) Math.ceil(layout.bgY() + layout.bgH()));
|
| 504 |
|
| 505 | if (x2 <= x1 || y2 <= y1) return false;
|
| 506 | return ScissorFunction.pushRawRect(x1, y1, x2, y2);
|
| 507 | }
|
| 508 |
|
| 509 | private static int computeOpponentStackX(NameplateLayout layout, int centerX) {
|
| 510 | if (layout != null) {
|
| 511 | return (int) Math.ceil(layout.bgX() + layout.bgW()) + EFFECT_X_OFFSET;
|
| 512 | }
|
| 513 | return centerX + (ICON_SIZE + ICON_GAP) * 2 + EFFECT_X_OFFSET;
|
| 514 | }
|
| 515 |
|
| 516 | private static int computeOpponentStackY(int nameY) {
|
| 517 | return nameY + OPP_STACK_Y_OFFSET;
|
| 518 | }
|
| 519 |
|
| 520 | @Override
|
| 521 | public HudRenderSpace getHudRenderSpace() {
|
| 522 | return HudRenderSpace.UNSCALED_LOGICAL;
|
| 523 | }
|
| 524 |
|
| 525 | @Override
|
| 526 | public HudPhase getHudPhase() {
|
| 527 | return HudPhase.AFTER_MISC_OVERLAYS;
|
| 528 | }
|
| 529 |
|
| 530 | @Override
|
| 531 | public WorldPhase getWorldPhase() {
|
| 532 | return WorldPhase.END_MAIN_BILLBOARD;
|
| 533 | }
|
| 534 |
|
| 535 | @Override
|
| 536 | public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
|
| 537 | if (!isEnabled() || renderer == null || mc.level == null || mc.player == null) return;
|
| 538 | if (presentationMode.get() == PresentationMode.TWO_D) return;
|
| 539 |
|
| 540 | ensureFontCache(TextRenderer.get());
|
| 541 | StatusEffectView.sync(mc);
|
| 542 | TotemPopCounter.tick();
|
| 543 | float dt = AnimationUtility.deltaTime();
|
| 544 |
|
| 545 | worldRenderQueue.clear();
|
| 546 | worldItemRows.clear();
|
| 547 | seenIds.clear();
|
| 548 | Vec3 cameraPos = mc.gameRenderer != null && mc.gameRenderer.mainCamera() != null
|
| 549 | ? mc.gameRenderer.mainCamera().position()
|
| 550 | : mc.player.position();
|
| 551 | WorldBillboardRenderer.Basis basis = WorldBillboardRenderer.currentBasis();
|
| 552 |
|
| 553 | for (Player player : mc.level.players()) {
|
| 554 | if (!shouldRender(player)) continue;
|
| 555 | seenIds.add(player.getUUID());
|
| 556 |
|
| 557 | TotemPopSnapshot totemPopSnapshot = TotemPopCounter.snapshot(player.getUUID());
|
| 558 | float totemPopAnimation = updateTotemPopAnimation(player, totemPopSnapshot, dt);
|
| 559 | int totemPopCount = resolveTotemPopCount(player, totemPopSnapshot, totemPopAnimation);
|
| 560 |
|
| 561 | Vec3 pos = obtainEntityLerpedPos(player, tickDelta);
|
| 562 | double dist = cameraPos.distanceTo(pos);
|
| 563 | WorldUiPresentationService.Snapshot presentation = resolvePresentation(dist);
|
| 564 | float alpha = presentation.worldAlpha();
|
| 565 | if (alpha <= 0.001f) continue;
|
| 566 |
|
| 567 | boolean renderNameplate = toggles.get("Show nameplate")
|
| 568 | && (!usesDistanceCutoff("nameplate") || dist <= plateDistance.get());
|
| 569 | boolean renderMainHand = toggles.get("Show main hand")
|
| 570 | && (!usesDistanceCutoff("nameplate") || dist <= plateDistance.get())
|
| 571 | && !player.getMainHandItem().isEmpty();
|
| 572 | boolean renderSlots = toggles.get("Show armor row")
|
| 573 | && (!usesDistanceCutoff("slots") || dist <= slotsDistance.get());
|
| 574 | boolean renderEffects = toggles.get("Show effects")
|
| 575 | && (!usesDistanceCutoff("effects") || dist <= effectsDistance.get());
|
| 576 | if (!renderNameplate && !renderMainHand && !renderSlots && !renderEffects) continue;
|
| 577 |
|
| 578 | double adaptiveScale = presentation.worldUnitsPerPixel();
|
| 579 | AABB projectedBox = player.getBoundingBox().move(pos.subtract(player.position())).inflate(0.1);
|
| 580 | Vec3 anchor = new Vec3(projectedBox.getCenter().x, projectedBox.maxY, projectedBox.getCenter().z);
|
| 581 | Vec3 bottomAnchor = new Vec3(projectedBox.getCenter().x, projectedBox.minY, projectedBox.getCenter().z);
|
| 582 |
|
| 583 | ItemStack[] slots = renderSlots ? getCachedEquipmentSlots(player) : EMPTY_SLOTS;
|
| 584 | List<List<EnchantLine>> enchantLines = List.of();
|
| 585 | int maxEnchantLines = 0;
|
| 586 | if (renderSlots) {
|
| 587 | EnchantCache cache = resolveEnchantCache(player, slots);
|
| 588 | enchantLines = cache.lines;
|
| 589 | maxEnchantLines = cache.maxLines;
|
| 590 | }
|
| 591 |
|
| 592 | List<MobEffectInstance> effects = renderEffects ? resolveEffects(player) : List.of();
|
| 593 | boolean renderTotemBadge = renderNameplate
|
| 594 | && totemPopCounter.get()
|
| 595 | && totemPopCount > 0
|
| 596 | && totemPopAnimation > 0.001f;
|
| 597 | ItemStack mainHand = renderMainHand ? player.getMainHandItem().copy() : ItemStack.EMPTY;
|
| 598 | int extraWorldItems = (renderTotemBadge ? 1 : 0) + (renderMainHand ? 1 : 0);
|
| 599 | ItemStack[] worldItems = extraWorldItems == 0
|
| 600 | ? slots
|
| 601 | : Arrays.copyOf(slots, slots.length + extraWorldItems);
|
| 602 | int worldItemCursor = slots.length;
|
| 603 | if (renderTotemBadge) {
|
| 604 | worldItems[worldItemCursor++] = totemBadgeStack();
|
| 605 | }
|
| 606 | if (renderMainHand) {
|
| 607 | worldItems[worldItemCursor] = mainHand;
|
| 608 | }
|
| 609 |
|
| 610 | worldRenderQueue.add(new WorldRenderEntry(
|
| 611 | player, anchor, bottomAnchor, dist, adaptiveScale, alpha,
|
| 612 | renderNameplate, renderSlots, renderEffects,
|
| 613 | slots, enchantLines, maxEnchantLines, effects,
|
| 614 | totemPopCount, totemPopAnimation, mainHand, renderMainHand, worldItems
|
| 615 | ));
|
| 616 | }
|
| 617 |
|
| 618 | worldRenderQueue.sort(Comparator.comparingDouble(WorldRenderEntry::distance).reversed());
|
| 619 | for (int i = 0; i < worldRenderQueue.size(); i++) {
|
| 620 | WorldRenderEntry entry = worldRenderQueue.get(i);
|
| 621 | worldItemRows.add(new ItemBatchRenderer.WorldItemRow(entry.player(), entry.worldItems(), i * 31));
|
| 622 | }
|
| 623 |
|
| 624 | List<ItemBatchRenderer.WorldItemSprite[]> itemSprites =
|
| 625 | ItemBatchRenderer.resolveWorldItemSprites(worldItemRows);
|
| 626 | for (int i = 0; i < worldRenderQueue.size(); i++) {
|
| 627 | ItemBatchRenderer.WorldItemSprite[] rowSprites = i < itemSprites.size()
|
| 628 | ? itemSprites.get(i)
|
| 629 | : new ItemBatchRenderer.WorldItemSprite[0];
|
| 630 | renderWorldNameTag(renderer, basis, worldRenderQueue.get(i), rowSprites);
|
| 631 | }
|
| 632 |
|
| 633 | if (presentationMode.get() == PresentationMode.THREE_D) pruneCaches();
|
| 634 | }
|
| 635 |
|
| 636 | @Override
|
| 637 | public void onRender2D(GuiGraphicsExtractor ctx, float tickDelta) {
|
| 638 | }
|
| 639 |
|
| 640 | @Override
|
| 641 | public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, GuiGraphicsExtractor ctx, float tickDelta) {
|
| 642 | if (!isEnabled() || mc.level == null || mc.player == null) return;
|
| 643 |
|
| 644 | if (presentationMode.get() == PresentationMode.THREE_D) {
|
| 645 | renderQueue.clear();
|
| 646 | return;
|
| 647 | }
|
| 648 |
|
| 649 | ensureFontCache(textRenderer);
|
| 650 |
|
| 651 | StatusEffectView.sync(mc);
|
| 652 | TotemPopCounter.tick();
|
| 653 | boolean advanceTotemAnimationHere = presentationMode.get() == PresentationMode.TWO_D;
|
| 654 | float dt = advanceTotemAnimationHere ? AnimationUtility.deltaTime() : 0.0f;
|
| 655 |
|
| 656 | renderQueue.clear();
|
| 657 | playerBuffer.clear();
|
| 658 | seenIds.clear();
|
| 659 |
|
| 660 | boolean wantNameplate = toggles.get("Show nameplate");
|
| 661 | boolean wantMainHand = toggles.get("Show main hand");
|
| 662 | boolean wantSlots = toggles.get("Show armor row");
|
| 663 | boolean wantEffects = toggles.get("Show effects");
|
| 664 | boolean wantOpponent = opponentAppleCooldowns.get() && isOpponentAppleTrackingEnabled();
|
| 665 | if (!wantNameplate && !wantMainHand && !wantSlots && !wantEffects && !wantOpponent) return;
|
| 666 |
|
| 667 | boolean hasUnlimited = false;
|
| 668 | double maxCutoff = 0.0;
|
| 669 | if (wantNameplate || wantMainHand) {
|
| 670 | if (usesDistanceCutoff("nameplate")) {
|
| 671 | maxCutoff = Math.max(maxCutoff, plateDistance.get());
|
| 672 | } else {
|
| 673 | hasUnlimited = true;
|
| 674 | }
|
| 675 | }
|
| 676 | if (wantSlots) {
|
| 677 | if (usesDistanceCutoff("slots")) {
|
| 678 | maxCutoff = Math.max(maxCutoff, slotsDistance.get());
|
| 679 | } else {
|
| 680 | hasUnlimited = true;
|
| 681 | }
|
| 682 | }
|
| 683 | if (wantEffects) {
|
| 684 | if (usesDistanceCutoff("effects")) {
|
| 685 | maxCutoff = Math.max(maxCutoff, effectsDistance.get());
|
| 686 | } else {
|
| 687 | hasUnlimited = true;
|
| 688 | }
|
| 689 | }
|
| 690 | if (wantOpponent) {
|
| 691 | double oppCutoff = OPPONENT_DISTANCE;
|
| 692 | if (oppCutoff > 0) {
|
| 693 | maxCutoff = Math.max(maxCutoff, oppCutoff);
|
| 694 | } else {
|
| 695 | hasUnlimited = true;
|
| 696 | }
|
| 697 | }
|
| 698 |
|
| 699 | Vec3 cameraPos = null;
|
| 700 | if (mc.gameRenderer != null && mc.gameRenderer.mainCamera() != null) {
|
| 701 | cameraPos = mc.gameRenderer.mainCamera().position();
|
| 702 | }
|
| 703 | if (cameraPos == null && mc.player != null) {
|
| 704 | cameraPos = mc.player.position();
|
| 705 | }
|
| 706 |
|
| 707 | for (Player player : mc.level.players()) {
|
| 708 | if (!shouldRender(player)) continue;
|
| 709 | playerBuffer.add(player);
|
| 710 | seenIds.add(player.getUUID());
|
| 711 | }
|
| 712 |
|
| 713 | if (cameraPos != null && playerBuffer.size() > 1) {
|
| 714 | double camX = cameraPos.x;
|
| 715 | double camY = cameraPos.y;
|
| 716 | double camZ = cameraPos.z;
|
| 717 | playerBuffer.sort(Comparator.comparingDouble((Player p) -> p.distanceToSqr(camX, camY, camZ)).reversed());
|
| 718 | }
|
| 719 |
|
| 720 | for (Player player : playerBuffer) {
|
| 721 | Vec3 pos = obtainEntityLerpedPos(player, tickDelta);
|
| 722 | double dist = (cameraPos == null) ? 0.0 : cameraPos.distanceTo(pos);
|
| 723 | if (!hasUnlimited && maxCutoff > 0.0 && dist > maxCutoff) continue;
|
| 724 | float presentationAlpha = resolvePresentation(dist).screenAlpha();
|
| 725 | if (presentationAlpha <= 0.001f) continue;
|
| 726 |
|
| 727 | AABB baseBox = player.getBoundingBox().move(pos.subtract(player.position()));
|
| 728 | AABB box = new AABB(
|
| 729 | baseBox.minX, baseBox.minY, baseBox.minZ,
|
| 730 | baseBox.maxX, baseBox.maxY + ESP_REFERENCE_TOP_OFFSET, baseBox.maxZ
|
| 731 | );
|
| 732 | Vec3 anchor = new Vec3(box.getCenter().x, box.maxY + 0.5, box.getCenter().z);
|
| 733 | ScreenRect rect = projectBoxScreen(box, tickDelta);
|
| 734 | int centerX;
|
| 735 | int anchorY;
|
| 736 | if (rect != null) {
|
| 737 | centerX = (int) Math.round((rect.minX + rect.maxX) * 0.5);
|
| 738 | anchorY = (int) Math.round(rect.minY);
|
| 739 | } else {
|
| 740 | Vec3 screen = ScreenProjection.worldToScreen(anchor, tickDelta);
|
| 741 | if (screen == null) continue;
|
| 742 | centerX = (int) screen.x;
|
| 743 | anchorY = (int) screen.y;
|
| 744 | }
|
| 745 | int nameY = computeNameY(rect, anchorY);
|
| 746 |
|
| 747 | boolean renderSlots = wantSlots;
|
| 748 | if (renderSlots && usesDistanceCutoff("slots") && dist > slotsDistance.get()) renderSlots = false;
|
| 749 |
|
| 750 | boolean renderNameplate = wantNameplate;
|
| 751 | if (renderNameplate && usesDistanceCutoff("nameplate") && dist > plateDistance.get())
|
| 752 | renderNameplate = false;
|
| 753 |
|
| 754 | boolean renderEffects = wantEffects;
|
| 755 | if (renderEffects && usesDistanceCutoff("effects") && dist > effectsDistance.get()) renderEffects = false;
|
| 756 |
|
| 757 | TotemPopSnapshot totemPopSnapshot = TotemPopCounter.snapshot(player.getUUID());
|
| 758 | float totemPopAnimation = advanceTotemAnimationHere
|
| 759 | ? updateTotemPopAnimation(player, totemPopSnapshot, dt)
|
| 760 | : totemPopAnimations.getOrDefault(player.getUUID(), totemPopSnapshot.visible() ? 1.0f : 0.0f);
|
| 761 | int totemPopCount = resolveTotemPopCount(player, totemPopSnapshot, totemPopAnimation);
|
| 762 |
|
| 763 | LabelInfo labelInfo = renderNameplate ? buildLabelInfo(player) : null;
|
| 764 | int infoColor = labelInfo != null ? labelInfo.infoColor() : INFO_COLOR_DEFAULT;
|
| 765 | TextRenderer nameRenderer = cachedNameTr != null ? cachedNameTr : textRenderer;
|
| 766 | TextRenderer hpRenderer = cachedHpTr != null ? cachedHpTr : textRenderer;
|
| 767 | NameplateLayout nameplateLayout = null;
|
| 768 | MainHandLayout mainHandLayout = null;
|
| 769 | boolean renderMainHand = wantMainHand
|
| 770 | && (!usesDistanceCutoff("nameplate") || dist <= plateDistance.get())
|
| 771 | && !player.getMainHandItem().isEmpty();
|
| 772 | ItemStack mainHand = renderMainHand ? player.getMainHandItem().copy() : ItemStack.EMPTY;
|
| 773 | if (renderNameplate && labelInfo != null) {
|
| 774 | nameplateLayout = buildNameplateLayout(
|
| 775 | player, nameRenderer, hpRenderer, labelInfo, dist, centerX, nameY,
|
| 776 | totemPopCount, totemPopAnimation, false
|
| 777 | );
|
| 778 | }
|
| 779 | if (renderMainHand && rect != null) {
|
| 780 | mainHandLayout = buildMainHandLayout(
|
| 781 | nameRenderer, mainHand, centerX, (float) rect.maxY + FRAME_CONTENT_GAP, false
|
| 782 | );
|
| 783 | }
|
| 784 |
|
| 785 | ItemStack[] slots = renderSlots ? getCachedEquipmentSlots(player) : EMPTY_SLOTS;
|
| 786 | List<List<EnchantLine>> enchantLines = List.of();
|
| 787 | int maxEnchantLines = 0;
|
| 788 | if (renderSlots) {
|
| 789 | EnchantCache cache = resolveEnchantCache(player, slots);
|
| 790 | enchantLines = cache.lines;
|
| 791 | maxEnchantLines = cache.maxLines;
|
| 792 | }
|
| 793 | List<MobEffectInstance> effects = renderEffects ? resolveEffects(player) : List.of();
|
| 794 |
|
| 795 | int itemsY = computeItemsY(rect, nameplateLayout, nameY);
|
| 796 | renderQueue.add(new RenderEntry(player, dist, centerX, nameY, itemsY,
|
| 797 | renderSlots, renderNameplate, renderEffects, labelInfo, infoColor, nameplateLayout,
|
| 798 | mainHand, mainHandLayout,
|
| 799 | slots, enchantLines, maxEnchantLines, effects, totemPopCount, totemPopAnimation,
|
| 800 | presentationAlpha));
|
| 801 | }
|
| 802 |
|
| 803 | pruneCaches();
|
| 804 | }
|
| 805 |
|
| 806 | @Override
|
| 807 | public void onRenderHudEngineForeground(Renderer2D renderer, TextRenderer textRenderer, GuiGraphicsExtractor ctx, float tickDelta) {
|
| 808 | if (!isEnabled() || mc.level == null || mc.player == null) return;
|
| 809 |
|
| 810 | ensureFontCache(textRenderer);
|
| 811 |
|
| 812 | for (RenderEntry entry : renderQueue) {
|
| 813 | renderNameTagForeground(renderer, ctx, textRenderer, entry);
|
| 814 | }
|
| 815 | }
|
| 816 |
|
| 817 | private boolean usesDistanceCutoff(String section) {
|
| 818 | return limitDistance.get() && distanceToggles.get(section);
|
| 819 | }
|
| 820 |
|
| 821 | private boolean shouldRender(Player player) {
|
| 822 | if (player == null || mc.player == null) return false;
|
| 823 | if (player == mc.player) {
|
| 824 | CameraType p = mc.options.getCameraType();
|
| 825 | if (p == null || p.isFirstPerson()) return false;
|
| 826 | if (!toggles.get("Show self in 3rd person")) return false;
|
| 827 | }
|
| 828 | String name = player.getGameProfile().name();
|
| 829 | return !"FreeCamera".equals(name);
|
| 830 | }
|
| 831 |
|
| 832 | private int computeNameY(ScreenRect rect, int anchorY) {
|
| 833 | float frameTop = rect != null ? (float) rect.minY : anchorY;
|
| 834 | return Math.round(frameTop - FRAME_CONTENT_GAP - RICH_TEXT_LOGICAL_HEIGHT - NAMEPLATE_PAD_Y);
|
| 835 | }
|
| 836 |
|
| 837 | private int computeItemsY(ScreenRect rect, NameplateLayout nameplateLayout, int nameY) {
|
| 838 | float nameplateTop = nameplateLayout != null
|
| 839 | ? nameplateLayout.bgY()
|
| 840 | : nameY - NAMEPLATE_PAD_Y;
|
| 841 | return Math.round(nameplateTop - EQUIPMENT_TO_NAMEPLATE_GAP - equipIconSize());
|
| 842 | }
|
| 843 |
|
| 844 | private WorldUiPresentationService.Snapshot resolvePresentation(double distance) {
|
| 845 | WorldUiPresentationService.Mode mode = switch (presentationMode.get()) {
|
| 846 | case TWO_D -> WorldUiPresentationService.Mode.SCREEN;
|
| 847 | case THREE_D -> WorldUiPresentationService.Mode.WORLD;
|
| 848 | case HYBRID -> WorldUiPresentationService.Mode.HYBRID;
|
| 849 | };
|
| 850 | double projectionYScale = RenderState.worldProjection.m11();
|
| 851 | ViewportContext viewport = ViewportContext.current();
|
| 852 | double logicalHeight = viewport != null ? viewport.height() : 0.0;
|
| 853 | return WorldUiPresentationService.resolve(
|
| 854 | mode, distance, WORLD_PRESENTATION_POLICY, projectionYScale, logicalHeight,
|
| 855 | worldSize.get(), dynamicWorldScale.get(), dynamicWorldScaleCoefficient.get());
|
| 856 | }
|
| 857 |
|
| 858 | private void renderWorldNameTag(Renderer3D renderer,
|
| 859 | WorldBillboardRenderer.Basis basis,
|
| 860 | WorldRenderEntry entry,
|
| 861 | ItemBatchRenderer.WorldItemSprite[] itemSprites) {
|
| 862 | Player player = entry.player();
|
| 863 | TextRenderer nameRenderer = cachedNameTr != null ? cachedNameTr : TextRenderer.get();
|
| 864 | TextRenderer hpRenderer = cachedHpTr != null ? cachedHpTr : nameRenderer;
|
| 865 | double itemY = -58.0;
|
| 866 | NameplateLayout layout = null;
|
| 867 |
|
| 868 | if (entry.renderNameplate()) {
|
| 869 | LabelInfo info = buildLabelInfo(player);
|
| 870 | layout = buildNameplateLayout(
|
| 871 | player,
|
| 872 | nameRenderer,
|
| 873 | hpRenderer,
|
| 874 | info,
|
| 875 | entry.distance(),
|
| 876 | 0,
|
| 877 | Math.round(-FRAME_CONTENT_GAP - RICH_TEXT_LOGICAL_HEIGHT - NAMEPLATE_PAD_Y),
|
| 878 | entry.totemPopCount(),
|
| 879 | entry.totemPopAnimation(),
|
| 880 | true
|
| 881 | );
|
| 882 |
|
| 883 | if (layout != null) {
|
| 884 | float materialAlpha = (clampAlpha(nameplateAlpha.get()) / 255.0f) * entry.alpha();
|
| 885 | WorldBillboardRenderer.roundedRect(
|
| 886 | renderer, basis, entry.anchor(),
|
| 887 | layout.bgX(), layout.bgY(), layout.bgW(), layout.bgH(),
|
| 888 | MATTE_NAMEPLATE_RADIUS, entry.worldScale(),
|
| 889 | withAlpha(REFERENCE_BACKDROP_RGB, Math.round(255.0f * materialAlpha))
|
| 890 | );
|
| 891 |
|
| 892 | drawWorldNameplateHead(renderer, basis, entry, layout);
|
| 893 |
|
| 894 | double cursorX = layout.nameX();
|
| 895 | if (!layout.pingText().isEmpty()) {
|
| 896 | drawWorldText(renderer, basis, nameRenderer, layout.pingText(), entry.anchor(),
|
| 897 | cursorX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 898 | resolvePingColor(info.ping()), entry.alpha());
|
| 899 | cursorX += layout.pingWidth() + layout.pingGap();
|
| 900 | }
|
| 901 |
|
| 902 | String prefix = info.pvpPrefix();
|
| 903 | if (!prefix.isEmpty()) {
|
| 904 | drawWorldText(renderer, basis, nameRenderer, prefix, entry.anchor(),
|
| 905 | cursorX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 906 | pvpPrefixColor.getArgb(), entry.alpha());
|
| 907 | cursorX += worldTextWidth(nameRenderer, prefix, NAMEPLATE_SCALE);
|
| 908 | }
|
| 909 |
|
| 910 | if (info.styledName() != null) {
|
| 911 | drawWorldStyledText(renderer, basis, nameRenderer, info.styledName(), entry.anchor(),
|
| 912 | cursorX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 913 | CategoryService.getColor(player), entry.alpha());
|
| 914 | } else {
|
| 915 | drawWorldText(renderer, basis, nameRenderer, info.name(), entry.anchor(),
|
| 916 | cursorX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 917 | CategoryService.getColor(player), entry.alpha());
|
| 918 | }
|
| 919 |
|
| 920 | String hp = formatNameplateHp(info.hp());
|
| 921 | if (!hp.isEmpty()) {
|
| 922 | double hpX = layout.nameX()
|
| 923 | + layout.pingWidth() + layout.pingGap()
|
| 924 | + layout.nameWidth() + layout.hpGap();
|
| 925 | drawWorldHealthTag(renderer, basis, hpRenderer, info.hp(), entry.anchor(),
|
| 926 | hpX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 927 | info.infoColor(), entry.alpha());
|
| 928 | }
|
| 929 |
|
| 930 | if (!layout.distText().isEmpty()) {
|
| 931 | double distX = layout.nameX()
|
| 932 | + layout.pingWidth() + layout.pingGap()
|
| 933 | + layout.nameWidth() + layout.hpGap() + layout.hpWidth()
|
| 934 | + (layout.hpWidth() > 0 ? DIST_TEXT_GAP : 0);
|
| 935 | drawWorldText(renderer, basis, nameRenderer, layout.distText(), entry.anchor(),
|
| 936 | distX, layout.nameY(), NAMEPLATE_SCALE, entry.worldScale(),
|
| 937 | 0xFFD0D0D0, entry.alpha());
|
| 938 | }
|
| 939 |
|
| 940 | drawWorldTotemBadge(renderer, basis, entry, layout, itemSprites, hpRenderer);
|
| 941 | itemY = -58.0;
|
| 942 | }
|
| 943 | }
|
| 944 |
|
| 945 | if (entry.renderMainHand()) {
|
| 946 | drawWorldMainHand(renderer, basis, entry, layout, itemSprites, nameRenderer);
|
| 947 | }
|
| 948 |
|
| 949 | int iconSize = equipIconSize();
|
| 950 | EquipmentLayout equipment = entry.renderSlots()
|
| 951 | ? computeEquipmentLayout(
|
| 952 | nameRenderer, entry.slots(), entry.enchantLines(),
|
| 953 | 0.0, iconSize, equipIconGap(), SMALL_TEXT_SCALE, true
|
| 954 | )
|
| 955 | : EquipmentLayout.empty();
|
| 956 |
|
| 957 | if (entry.renderSlots()) {
|
| 958 | double enchantHeight = WorldTextRenderer.measure(
|
| 959 | nameRenderer, "Ag", SMALL_TEXT_SCALE, false).height() + 1.0;
|
| 960 |
|
| 961 | for (int i = 0; i < entry.slots().length; i++) {
|
| 962 | ItemStack stack = entry.slots()[i];
|
| 963 | if (stack == null || stack.isEmpty()) continue;
|
| 964 |
|
| 965 | double itemX = equipment.centers()[i] - iconSize * 0.5;
|
| 966 | if (i < itemSprites.length && itemSprites[i] != null) {
|
| 967 | WorldBillboardRenderer.item(
|
| 968 | renderer, basis, entry.anchor(), itemSprites[i],
|
| 969 | itemX, itemY, iconSize, entry.worldScale(), entry.alpha()
|
| 970 | );
|
| 971 | }
|
| 972 |
|
| 973 | List<EnchantLine> lines = i < entry.enchantLines().size()
|
| 974 | ? entry.enchantLines().get(i)
|
| 975 | : List.of();
|
| 976 | for (int lineIndex = 0; lineIndex < lines.size(); lineIndex++) {
|
| 977 | EnchantLine line = lines.get(lineIndex);
|
| 978 | double width = worldTextWidth(nameRenderer, line.text(), SMALL_TEXT_SCALE);
|
| 979 | double lineY = itemY - 3.0 - enchantHeight * (lineIndex + 1);
|
| 980 | drawWorldText(renderer, basis, nameRenderer, line.text(), entry.anchor(),
|
| 981 | equipment.centers()[i] - width * 0.5, lineY,
|
| 982 | SMALL_TEXT_SCALE, entry.worldScale(), line.color(), entry.alpha(), true);
|
| 983 | }
|
| 984 | }
|
| 985 | }
|
| 986 |
|
| 987 | if (entry.renderEffects() && !entry.effects().isEmpty()) {
|
| 988 | drawWorldEffects(renderer, basis, entry, itemY, nameRenderer);
|
| 989 | }
|
| 990 | }
|
| 991 |
|
| 992 | private void drawWorldNameplateHead(Renderer3D renderer,
|
| 993 | WorldBillboardRenderer.Basis basis,
|
| 994 | WorldRenderEntry entry,
|
| 995 | NameplateLayout layout) {
|
| 996 | if (layout == null || !layout.renderHead()) return;
|
| 997 | if (!(entry.player() instanceof AbstractClientPlayer clientPlayer)) return;
|
| 998 |
|
| 999 | Identifier skin = PlayerSkinResolver.resolvePlayerSkin(clientPlayer);
|
| 1000 | if (skin == null) return;
|
| 1001 |
|
| 1002 | float alpha = (clampAlpha(nameplateAlpha.get()) / 255.0f) * entry.alpha();
|
| 1003 | if (alpha <= 0.001f) return;
|
| 1004 |
|
| 1005 | double inset = layout.headSize() * 0.06;
|
| 1006 | double x = layout.headX() + inset;
|
| 1007 | double y = layout.headY() + inset;
|
| 1008 | double size = Math.max(1.0, layout.headSize() - inset * 2.0);
|
| 1009 |
|
| 1010 | WorldBillboardRenderer.texture(
|
| 1011 | renderer, basis, entry.anchor(), skin,
|
| 1012 | x, y, size, size,
|
| 1013 | 8f / 64f, 8f / 64f, 16f / 64f, 16f / 64f,
|
| 1014 | entry.worldScale(), 0xFFFFFFFF, alpha
|
| 1015 | );
|
| 1016 | WorldBillboardRenderer.texture(
|
| 1017 | renderer, basis, entry.anchor(), skin,
|
| 1018 | x, y, size, size,
|
| 1019 | 40f / 64f, 8f / 64f, 48f / 64f, 16f / 64f,
|
| 1020 | entry.worldScale(), 0xFFFFFFFF, alpha
|
| 1021 | );
|
| 1022 |
|
| 1023 | WorldBillboardRenderer.quad(
|
| 1024 | renderer, basis, entry.anchor(),
|
| 1025 | layout.dividerX(), layout.dividerY(), layout.dividerW(), layout.dividerH(),
|
| 1026 | entry.worldScale(),
|
| 1027 | withAlpha(REFERENCE_DIVIDER_RGB, Math.round(REFERENCE_DIVIDER_ALPHA * alpha))
|
| 1028 | );
|
| 1029 | }
|
| 1030 |
|
| 1031 | private void drawWorldTotemBadge(Renderer3D renderer,
|
| 1032 | WorldBillboardRenderer.Basis basis,
|
| 1033 | WorldRenderEntry entry,
|
| 1034 | NameplateLayout layout,
|
| 1035 | ItemBatchRenderer.WorldItemSprite[] itemSprites,
|
| 1036 | TextRenderer fallbackRenderer) {
|
| 1037 | if (layout == null || !layout.renderTotemBadge()) return;
|
| 1038 | if (entry.totemPopCount() <= 0 || entry.totemPopAnimation() <= 0.001f) return;
|
| 1039 |
|
| 1040 | float anim = AnimationUtility.easeInOutCubic(entry.totemPopAnimation());
|
| 1041 | float materialAlpha = (clampAlpha(nameplateAlpha.get()) / 255.0f) * anim * entry.alpha();
|
| 1042 | if (materialAlpha <= 0.001f) return;
|
| 1043 |
|
| 1044 | WorldBillboardRenderer.quad(
|
| 1045 | renderer, basis, entry.anchor(),
|
| 1046 | layout.totemDividerX(), layout.totemDividerY(),
|
| 1047 | layout.totemDividerW(), layout.totemDividerH(), entry.worldScale(),
|
| 1048 | withAlpha(REFERENCE_DIVIDER_RGB, Math.round(REFERENCE_DIVIDER_ALPHA * materialAlpha))
|
| 1049 | );
|
| 1050 |
|
| 1051 | double iconScale = 0.86 + 0.14 * anim;
|
| 1052 | double iconSize = Math.max(1.0, layout.totemIconSize() * iconScale);
|
| 1053 | double iconX = layout.totemBadgeX();
|
| 1054 | double iconY = layout.totemBadgeY() + (layout.totemBadgeH() - iconSize) * 0.5;
|
| 1055 | int spriteIndex = entry.slots().length;
|
| 1056 | if (spriteIndex < itemSprites.length && itemSprites[spriteIndex] != null) {
|
| 1057 | WorldBillboardRenderer.item(
|
| 1058 | renderer, basis, entry.anchor(), itemSprites[spriteIndex],
|
| 1059 | iconX, iconY, iconSize, entry.worldScale(), entry.alpha() * anim
|
| 1060 | );
|
| 1061 | }
|
| 1062 |
|
| 1063 | String text = "x" + entry.totemPopCount();
|
| 1064 | TextRenderer badgeRenderer = BuiltinFontCatalog.INTER_MEDIUM.renderer(fallbackRenderer);
|
| 1065 | double textScale = TOTEM_BADGE_TEXT_SCALE * (0.94 + 0.06 * anim);
|
| 1066 | double textX = iconX + iconSize + TOTEM_BADGE_TEXT_GAP;
|
| 1067 | double textH = WorldTextRenderer.measure(badgeRenderer, "Ag", textScale, false).height();
|
| 1068 | double textY = layout.totemBadgeY() + (layout.totemBadgeH() - textH) * 0.5 - 0.1;
|
| 1069 | int textColor = withAlpha(0xFFFFFF, Math.round(255.0f * materialAlpha));
|
| 1070 | drawWorldText(
|
| 1071 | renderer, basis, badgeRenderer, text, entry.anchor(),
|
| 1072 | textX, textY, textScale, entry.worldScale(), textColor, 1.0f
|
| 1073 | );
|
| 1074 | }
|
| 1075 |
|
| 1076 | private void drawWorldMainHand(Renderer3D renderer,
|
| 1077 | WorldBillboardRenderer.Basis basis,
|
| 1078 | WorldRenderEntry entry,
|
| 1079 | NameplateLayout nameplate,
|
| 1080 | ItemBatchRenderer.WorldItemSprite[] itemSprites,
|
| 1081 | TextRenderer textRenderer) {
|
| 1082 | if (renderer == null || basis == null || entry == null
|
| 1083 | || !entry.renderMainHand() || entry.mainHand() == null || entry.mainHand().isEmpty()) {
|
| 1084 | return;
|
| 1085 | }
|
| 1086 | MainHandLayout layout = buildMainHandLayout(
|
| 1087 | textRenderer, entry.mainHand(), 0, FRAME_CONTENT_GAP, true
|
| 1088 | );
|
| 1089 | if (layout == null) return;
|
| 1090 | float alpha = (clampAlpha(nameplateAlpha.get()) / 255.0f) * entry.alpha();
|
| 1091 | if (alpha <= 0.001f) return;
|
| 1092 |
|
| 1093 | WorldBillboardRenderer.roundedRect(
|
| 1094 | renderer, basis, entry.bottomAnchor(),
|
| 1095 | layout.x(), layout.y(), layout.width(), layout.height(), MAIN_HAND_RADIUS, entry.worldScale(),
|
| 1096 | withAlpha(REFERENCE_BACKDROP_RGB, Math.round(255.0f * alpha))
|
| 1097 | );
|
| 1098 |
|
| 1099 | int spriteIndex = entry.slots().length;
|
| 1100 | if (nameplate != null && nameplate.renderTotemBadge()) spriteIndex++;
|
| 1101 | if (spriteIndex < itemSprites.length && itemSprites[spriteIndex] != null) {
|
| 1102 | WorldBillboardRenderer.item(renderer, basis, entry.bottomAnchor(), itemSprites[spriteIndex],
|
| 1103 | layout.iconX(), layout.iconY(), layout.iconSize(), entry.worldScale(), entry.alpha());
|
| 1104 | }
|
| 1105 | drawWorldStyledText(renderer, basis, textRenderer, layout.text(), entry.bottomAnchor(),
|
| 1106 | layout.textX(), layout.textY(), layout.textScale(), entry.worldScale(),
|
| 1107 | resolveItemRarityColor(entry.mainHand()), entry.alpha());
|
| 1108 | }
|
| 1109 |
|
| 1110 | private void drawWorldEffects(Renderer3D renderer,
|
| 1111 | WorldBillboardRenderer.Basis basis,
|
| 1112 | WorldRenderEntry entry,
|
| 1113 | double itemY,
|
| 1114 | TextRenderer fallbackRenderer) {
|
| 1115 | TextureAtlas atlas = mc.getAtlasManager().getAtlasOrThrow(AtlasIds.GUI);
|
| 1116 | if (atlas == null || atlas.location() == null) return;
|
| 1117 |
|
| 1118 | int count = entry.effects().size();
|
| 1119 | int iconSize = scaleRow(ICON_SIZE);
|
| 1120 | int gap = scaleRow(EFFECT_ROW_ICON_GAP);
|
| 1121 | int rowGap = scaleRow(EFFECT_ROW_GAP);
|
| 1122 | int rowWidth = count * iconSize + Math.max(0, count - 1) * gap;
|
| 1123 | double startX = -rowWidth * 0.5;
|
| 1124 | int enchantLift = entry.renderSlots()
|
| 1125 | ? scaleRow(computeEnchantLift(fallbackRenderer, entry.maxEnchantLines()))
|
| 1126 | : 0;
|
| 1127 | double iconY = itemY - iconSize - rowGap - enchantLift;
|
| 1128 |
|
| 1129 | TextRenderer levelRenderer = cachedLevelTr != null ? cachedLevelTr : fallbackRenderer;
|
| 1130 | TextRenderer timeRenderer = cachedTimeTr != null ? cachedTimeTr : fallbackRenderer;
|
| 1131 | double rowTextScale = SMALL_TEXT_SCALE * EFFECT_ROW_SCALE;
|
| 1132 | double levelHeight = WorldTextRenderer.measure(levelRenderer, "Ag", rowTextScale, false).height();
|
| 1133 | double timeHeight = WorldTextRenderer.measure(timeRenderer, "Ag", rowTextScale, false).height();
|
| 1134 | int levelGap = scaleRow(EFFECT_ROW_LEVEL_GAP);
|
| 1135 | int timeGap = scaleRow(EFFECT_ROW_TIME_GAP);
|
| 1136 |
|
| 1137 | for (int i = 0; i < count; i++) {
|
| 1138 | MobEffectInstance effect = entry.effects().get(i);
|
| 1139 | Identifier spriteId = Hud.getMobEffectSprite(effect.getEffect());
|
| 1140 | TextureAtlasSprite sprite = spriteId != null ? atlas.getSprite(spriteId) : null;
|
| 1141 | double iconX = startX + i * (iconSize + gap);
|
| 1142 |
|
| 1143 | if (sprite != null) {
|
| 1144 | WorldBillboardRenderer.texture(
|
| 1145 | renderer, basis, entry.anchor(), atlas.location(),
|
| 1146 | iconX, iconY, iconSize, iconSize,
|
| 1147 | sprite.getU0(), sprite.getV0(), sprite.getU1(), sprite.getV1(),
|
| 1148 | entry.worldScale(), 0xFFFFFFFF, entry.alpha()
|
| 1149 | );
|
| 1150 | }
|
| 1151 |
|
| 1152 | int level = effect.getAmplifier() + 1;
|
| 1153 | String duration = formatDuration(entry.player().getId(), effect);
|
| 1154 | if (!duration.isEmpty()) {
|
| 1155 | double width = worldTextWidth(timeRenderer, duration, rowTextScale);
|
| 1156 | double y = level > 1
|
| 1157 | ? iconY - levelHeight - levelGap - timeHeight - timeGap
|
| 1158 | : iconY - timeHeight - levelGap;
|
| 1159 | drawWorldText(
|
| 1160 | renderer, basis, timeRenderer, duration, entry.anchor(),
|
| 1161 | iconX + (iconSize - width) * 0.5, y,
|
| 1162 | rowTextScale, entry.worldScale(), EFFECT_TIME_COLOR, entry.alpha()
|
| 1163 | );
|
| 1164 | }
|
| 1165 |
|
| 1166 | if (level > 1) {
|
| 1167 | String levelText = roman(level);
|
| 1168 | double width = worldTextWidth(levelRenderer, levelText, rowTextScale);
|
| 1169 | drawWorldText(
|
| 1170 | renderer, basis, levelRenderer, levelText, entry.anchor(),
|
| 1171 | iconX + (iconSize - width) * 0.5, iconY - levelHeight - levelGap,
|
| 1172 | rowTextScale, entry.worldScale(), EFFECT_LEVEL_STACK_COLOR, entry.alpha()
|
| 1173 | );
|
| 1174 | }
|
| 1175 | }
|
| 1176 | }
|
| 1177 |
|
| 1178 | private static double worldTextWidth(TextRenderer renderer, String text, double scale) {
|
| 1179 | if (text == null || text.isEmpty()) return 0.0;
|
| 1180 | return WorldTextRenderer.measure(renderer, text, scale, false).width();
|
| 1181 | }
|
| 1182 |
|
| 1183 | private static double layoutTextWidth(TextRenderer renderer, String text, double scale, boolean worldText) {
|
| 1184 | return worldText
|
| 1185 | ? worldTextWidth(renderer, RuntimeTextLayout.singleLine(text), scale)
|
| 1186 | : RuntimeTextLayout.width(renderer, text, scale, false);
|
| 1187 | }
|
| 1188 |
|
| 1189 | private static double layoutTextHeight(TextRenderer renderer, double scale, boolean worldText) {
|
| 1190 | return worldText
|
| 1191 | ? WorldTextRenderer.measure(renderer, "Ag", scale, false).height()
|
| 1192 | : RuntimeTextLayout.height(renderer, scale, false);
|
| 1193 | }
|
| 1194 |
|
| 1195 | private static double layoutStyledTextWidth(TextRenderer renderer,
|
| 1196 | Component text,
|
| 1197 | double scale,
|
| 1198 | int defaultColor,
|
| 1199 | boolean worldText) {
|
| 1200 | if (text == null) return 0.0;
|
| 1201 | double width = 0.0;
|
| 1202 | for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(text, defaultColor)) {
|
| 1203 | width += layoutTextWidth(renderer, part.text(), scale, worldText);
|
| 1204 | }
|
| 1205 | return width;
|
| 1206 | }
|
| 1207 |
|
| 1208 | private static void drawWorldText(Renderer3D renderer,
|
| 1209 | WorldBillboardRenderer.Basis basis,
|
| 1210 | TextRenderer textRenderer,
|
| 1211 | String text,
|
| 1212 | Vec3 anchor,
|
| 1213 | double pixelX,
|
| 1214 | double pixelY,
|
| 1215 | double textScale,
|
| 1216 | double worldScale,
|
| 1217 | int argb,
|
| 1218 | float alpha) {
|
| 1219 | drawWorldText(renderer, basis, textRenderer, text, anchor, pixelX, pixelY,
|
| 1220 | textScale, worldScale, argb, alpha, false);
|
| 1221 | }
|
| 1222 |
|
| 1223 | private static void drawWorldText(Renderer3D renderer,
|
| 1224 | WorldBillboardRenderer.Basis basis,
|
| 1225 | TextRenderer textRenderer,
|
| 1226 | String text,
|
| 1227 | Vec3 anchor,
|
| 1228 | double pixelX,
|
| 1229 | double pixelY,
|
| 1230 | double textScale,
|
| 1231 | double worldScale,
|
| 1232 | int argb,
|
| 1233 | float alpha,
|
| 1234 | boolean shadow) {
|
| 1235 | if (text == null || text.isEmpty() || alpha <= 0.001f) return;
|
| 1236 | WorldBillboardRenderer.text(renderer, basis, textRenderer, text, anchor, pixelX, pixelY,
|
| 1237 | textScale, worldScale, argb, alpha, shadow);
|
| 1238 | }
|
| 1239 |
|
| 1240 | private static double drawWorldStyledText(Renderer3D renderer,
|
| 1241 | WorldBillboardRenderer.Basis basis,
|
| 1242 | TextRenderer textRenderer,
|
| 1243 | Component text,
|
| 1244 | Vec3 anchor,
|
| 1245 | double pixelX,
|
| 1246 | double pixelY,
|
| 1247 | double textScale,
|
| 1248 | double worldScale,
|
| 1249 | int defaultColor,
|
| 1250 | float alpha) {
|
| 1251 | double cursor = pixelX;
|
| 1252 | if (text == null) return cursor;
|
| 1253 | for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(text, defaultColor)) {
|
| 1254 | drawWorldText(renderer, basis, textRenderer, part.text(), anchor, cursor, pixelY,
|
| 1255 | textScale, worldScale, part.color(), alpha);
|
| 1256 | cursor += worldTextWidth(textRenderer, part.text(), textScale);
|
| 1257 | }
|
| 1258 | return cursor;
|
| 1259 | }
|
| 1260 |
|
| 1261 | private void drawNameplateBackground(Renderer2D renderer, Player player, NameplateLayout layout) {
|
| 1262 | if (layout == null) return;
|
| 1263 | int alpha = Math.round(clampAlpha(nameplateAlpha.get()) * foregroundAlpha);
|
| 1264 | if (alpha <= 0) return;
|
| 1265 | renderer.roundedRect(
|
| 1266 | layout.bgX(), layout.bgY(), layout.bgW(), layout.bgH(),
|
| 1267 | MATTE_NAMEPLATE_RADIUS, 0.0f, withAlpha(REFERENCE_BACKDROP_RGB, alpha)
|
| 1268 | );
|
| 1269 | }
|
| 1270 |
|
| 1271 | private float nameplateRadius(NameplateLayout layout) {
|
| 1272 | return MATTE_NAMEPLATE_RADIUS;
|
| 1273 | }
|
| 1274 |
|
| 1275 | private boolean shouldRenderPlayerHead(Player player) {
|
| 1276 | return playerHead.get() && player instanceof AbstractClientPlayer;
|
| 1277 | }
|
| 1278 |
|
| 1279 | private NameplateLayout buildNameplateLayout(Player player, TextRenderer nameRenderer, TextRenderer hpRenderer, LabelInfo info,
|
| 1280 | double dist, int centerX, int nameY,
|
| 1281 | int totemPopCount, float totemPopAnimation,
|
| 1282 | boolean worldText) {
|
| 1283 | if (info == null) return null;
|
| 1284 | float labelScale = NAMEPLATE_SCALE;
|
| 1285 | String prefix = info.pvpPrefix();
|
| 1286 | String name = info.name();
|
| 1287 | String hp = formatNameplateHp(info.hp());
|
| 1288 | String pingText = info.pingText();
|
| 1289 | int pingWidth = pingText.isEmpty() ? 0 : (int) Math.ceil(layoutTextWidth(nameRenderer, pingText, labelScale, worldText));
|
| 1290 | int pingGap = pingWidth > 0 ? PING_TEXT_GAP : 0;
|
| 1291 | double prefixWidth = prefix.isEmpty() ? 0.0 : layoutTextWidth(nameRenderer, prefix, labelScale, worldText);
|
| 1292 | double rawNameWidth = info.styledName() != null
|
| 1293 | ? layoutStyledTextWidth(nameRenderer, info.styledName(), labelScale, CategoryService.getColor(player), worldText)
|
| 1294 | : layoutTextWidth(nameRenderer, name, labelScale, worldText);
|
| 1295 | int nameWidth = (int) Math.ceil(prefixWidth + rawNameWidth);
|
| 1296 | int hpWidth = hp == null || hp.isEmpty() ? 0 : (int) Math.ceil(layoutTextWidth(hpRenderer, hp, labelScale, worldText));
|
| 1297 | int hpGap = hpWidth > 0 ? HP_TEXT_GAP : 0;
|
| 1298 | boolean showDist = shouldShowDistanceText(player);
|
| 1299 | String distText = showDist ? (int) Math.round(dist) + "m" : "";
|
| 1300 | int distWidth = showDist ? (int) Math.ceil(layoutTextWidth(nameRenderer, distText, labelScale, worldText)) : 0;
|
| 1301 | int distGap = distWidth > 0 ? DIST_TEXT_GAP : 0;
|
| 1302 | float measuredNameHeight = (float) Math.max(
|
| 1303 | layoutTextHeight(nameRenderer, labelScale, worldText),
|
| 1304 | layoutTextHeight(hpRenderer, labelScale, worldText));
|
| 1305 | float visualTextHeight = Math.max(RICH_TEXT_LOGICAL_HEIGHT, measuredNameHeight);
|
| 1306 | int nameHeight = Math.max(1, Math.round(visualTextHeight));
|
| 1307 | int centeredTextY = Math.round(nameY + (visualTextHeight - measuredNameHeight) * 0.5f);
|
| 1308 | boolean renderHead = shouldRenderPlayerHead(player);
|
| 1309 | float headSize = renderHead ? Math.max(MATTE_HEAD_MIN_SIZE, nameHeight + NAMEPLATE_PAD_Y * 1.5f) : 0.0f;
|
| 1310 | float headBlock = renderHead
|
| 1311 | ? headSize + MATTE_HEAD_DIVIDER_GAP + MATTE_HEAD_DIVIDER_WIDTH + MATTE_HEAD_TEXT_GAP
|
| 1312 | : 0.0f;
|
| 1313 | int textWidth = pingWidth + pingGap + nameWidth + hpGap + hpWidth + distGap + distWidth;
|
| 1314 | int scaledHeight = Math.max(nameHeight, renderHead ? Math.round(headSize) : nameHeight);
|
| 1315 | float visualHeight = Math.max(visualTextHeight, renderHead ? headSize : visualTextHeight);
|
| 1316 | boolean renderTotemBadge = totemPopCounter.get() && totemPopCount > 0 && totemPopAnimation > 0.001f;
|
| 1317 | String totemText = renderTotemBadge ? "x" + totemPopCount : "";
|
| 1318 | float totemIconSize = renderTotemBadge
|
| 1319 | ? Math.min(TOTEM_BADGE_ICON_SIZE, Math.max(8.0f, scaledHeight - 2.0f))
|
| 1320 | : 0.0f;
|
| 1321 | float totemTextWidth = renderTotemBadge
|
| 1322 | ? (float) layoutTextWidth(hpRenderer, totemText, TOTEM_BADGE_TEXT_SCALE, worldText)
|
| 1323 | : 0.0f;
|
| 1324 | float totemBadgeHeight = renderTotemBadge ? scaledHeight : 0.0f;
|
| 1325 | float totemBadgeWidth = renderTotemBadge
|
| 1326 | ? totemIconSize + TOTEM_BADGE_TEXT_GAP + totemTextWidth
|
| 1327 | : 0.0f;
|
| 1328 | float totemBlock = renderTotemBadge
|
| 1329 | ? TOTEM_BADGE_GAP + TOTEM_BADGE_DIVIDER_WIDTH + TOTEM_BADGE_DIVIDER_GAP + totemBadgeWidth
|
| 1330 | : 0.0f;
|
| 1331 | int totalWidth = Math.round(headBlock + textWidth + totemBlock);
|
| 1332 | int scaledWidth = totalWidth;
|
| 1333 | int contentX = centerX - scaledWidth / 2;
|
| 1334 | int nameX = Math.round(contentX + headBlock);
|
| 1335 |
|
| 1336 | float bgX = contentX - NAMEPLATE_PAD_X;
|
| 1337 | float bgY = nameY - NAMEPLATE_PAD_Y;
|
| 1338 | float bgW = scaledWidth + NAMEPLATE_PAD_X * 2f;
|
| 1339 | float bgH = visualHeight + NAMEPLATE_PAD_Y * 2f;
|
| 1340 | float headX = contentX;
|
| 1341 | float headY = nameY + (visualHeight - headSize) * 0.5f;
|
| 1342 | float dividerX = headX + headSize + MATTE_HEAD_DIVIDER_GAP;
|
| 1343 | float dividerH = Math.max(3.0f, bgH * 0.48f);
|
| 1344 | float dividerY = bgY + (bgH - dividerH) * 0.5f;
|
| 1345 | float totemDividerX = renderTotemBadge ? contentX + headBlock + textWidth + TOTEM_BADGE_GAP : 0.0f;
|
| 1346 | float totemDividerH = renderTotemBadge ? Math.max(3.0f, bgH * 0.48f) : 0.0f;
|
| 1347 | float totemDividerY = renderTotemBadge ? bgY + (bgH - totemDividerH) * 0.5f : 0.0f;
|
| 1348 | float totemBadgeX = renderTotemBadge ? totemDividerX + TOTEM_BADGE_DIVIDER_WIDTH + TOTEM_BADGE_DIVIDER_GAP : 0.0f;
|
| 1349 | float totemBadgeY = renderTotemBadge ? nameY : 0.0f;
|
| 1350 |
|
| 1351 | return new NameplateLayout(nameX, centeredTextY, scaledWidth, scaledHeight, labelScale, pingText, distText, bgX, bgY, bgW, bgH,
|
| 1352 | pingWidth, pingGap, nameWidth, hpWidth, hpGap, renderHead, headX, headY, headSize,
|
| 1353 | dividerX, dividerY, MATTE_HEAD_DIVIDER_WIDTH, dividerH,
|
| 1354 | renderTotemBadge, totemDividerX, totemDividerY, TOTEM_BADGE_DIVIDER_WIDTH, totemDividerH,
|
| 1355 | totemBadgeX, totemBadgeY, totemBadgeWidth, totemBadgeHeight, totemIconSize);
|
| 1356 | }
|
| 1357 |
|
| 1358 | private MainHandLayout buildMainHandLayout(TextRenderer renderer, ItemStack stack, int centerX, float topY,
|
| 1359 | boolean worldText) {
|
| 1360 | if (renderer == null || stack == null || stack.isEmpty()) return null;
|
| 1361 | Component text = formatMainHandText(stack);
|
| 1362 | float textWidth = (float) layoutStyledTextWidth(
|
| 1363 | renderer, text, MAIN_HAND_TEXT_SCALE, resolveItemRarityColor(stack), worldText);
|
| 1364 | float measuredTextHeight = (float) layoutTextHeight(renderer, MAIN_HAND_TEXT_SCALE, worldText);
|
| 1365 | float contentHeight = Math.max(RICH_TEXT_LOGICAL_HEIGHT, Math.max(measuredTextHeight, MAIN_HAND_ICON_SIZE));
|
| 1366 | float height = contentHeight + MAIN_HAND_PAD_Y * 2.0f;
|
| 1367 | float width = MAIN_HAND_PAD_X * 2.0f + MAIN_HAND_ICON_SIZE + MAIN_HAND_ICON_GAP + textWidth;
|
| 1368 | float x = centerX - width * 0.5f;
|
| 1369 | float y = topY;
|
| 1370 | float iconX = x + MAIN_HAND_PAD_X;
|
| 1371 | float iconY = y + (height - MAIN_HAND_ICON_SIZE) * 0.5f;
|
| 1372 | float textX = iconX + MAIN_HAND_ICON_SIZE + MAIN_HAND_ICON_GAP;
|
| 1373 | float textY = y + (height - measuredTextHeight) * 0.5f;
|
| 1374 | return new MainHandLayout(x, y, width, height, iconX, iconY, MAIN_HAND_ICON_SIZE,
|
| 1375 | textX, textY, MAIN_HAND_TEXT_SCALE, text);
|
| 1376 | }
|
| 1377 |
|
| 1378 | private static Component formatMainHandText(ItemStack stack) {
|
| 1379 | if (stack == null || stack.isEmpty()) return Component.empty();
|
| 1380 | MutableComponent text = Component.literal(stack.getHoverName().getString());
|
| 1381 | if (stack.getCount() > 1) {
|
| 1382 | text.append(Component.literal(" [").withStyle(ChatFormatting.WHITE));
|
| 1383 | text.append(Component.literal(Integer.toString(stack.getCount())).withStyle(ChatFormatting.RED));
|
| 1384 | text.append(Component.literal("x").withStyle(ChatFormatting.GRAY));
|
| 1385 | text.append(Component.literal("]").withStyle(ChatFormatting.WHITE));
|
| 1386 | }
|
| 1387 | return text;
|
| 1388 | }
|
| 1389 |
|
| 1390 | private static int resolveItemRarityColor(ItemStack stack) {
|
| 1391 | if (stack == null || stack.isEmpty()) return 0xFFFFFFFF;
|
| 1392 | float[] c = RarityColorUtil.INSTANCE.getRarityColor(stack);
|
| 1393 | int r = Math.round(Math.max(0.0f, Math.min(1.0f, c[0])) * 255.0f);
|
| 1394 | int g = Math.round(Math.max(0.0f, Math.min(1.0f, c[1])) * 255.0f);
|
| 1395 | int b = Math.round(Math.max(0.0f, Math.min(1.0f, c[2])) * 255.0f);
|
| 1396 | int a = Math.round(Math.max(0.0f, Math.min(1.0f, c[3])) * 255.0f);
|
| 1397 | return (a << 24) | (r << 16) | (g << 8) | b;
|
| 1398 | }
|
| 1399 |
|
| 1400 | private void drawMainHandChip(Renderer2D renderer, TextRenderer fallbackRenderer, ItemStack stack, MainHandLayout layout) {
|
| 1401 | if (renderer == null || layout == null || stack == null || stack.isEmpty()) return;
|
| 1402 | int alpha = Math.round(clampAlpha(nameplateAlpha.get()) * foregroundAlpha);
|
| 1403 | if (alpha <= 0) return;
|
| 1404 | renderer.roundedRect(layout.x(), layout.y(), layout.width(), layout.height(),
|
| 1405 | MAIN_HAND_RADIUS, 0.0f, withAlpha(REFERENCE_BACKDROP_RGB, alpha));
|
| 1406 | renderer.item(stack, layout.iconX(), layout.iconY(), layout.iconSize() / 16.0f,
|
| 1407 | 917, Renderer2D.ITEM_OVERLAY_NONE, null);
|
| 1408 | TextRenderer tr = cachedNameTr != null ? cachedNameTr : fallbackRenderer;
|
| 1409 | boolean started = beginTextRenderer(tr, layout.textScale());
|
| 1410 | try {
|
| 1411 | double cursor = layout.textX();
|
| 1412 | for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(layout.text(), resolveItemRarityColor(stack))) {
|
| 1413 | cursor = tr.render(part.text(), cursor, layout.textY(),
|
| 1414 | new RenderColor(foregroundColor(part.color())), false);
|
| 1415 | }
|
| 1416 | } finally {
|
| 1417 | endTextRenderer(tr, started);
|
| 1418 | }
|
| 1419 | }
|
| 1420 |
|
| 1421 | private void renderNameTagForeground(Renderer2D renderer, GuiGraphicsExtractor ctx, TextRenderer textRenderer, RenderEntry entry) {
|
| 1422 | float alpha = Math.max(0.0f, Math.min(1.0f, entry.presentationAlpha()));
|
| 1423 | if (alpha <= 0.001f) return;
|
| 1424 | double previousRendererAlpha = renderer.getAlpha();
|
| 1425 | float previousForegroundAlpha = foregroundAlpha;
|
| 1426 | foregroundAlpha = alpha;
|
| 1427 | renderer.setAlpha(previousRendererAlpha * alpha);
|
| 1428 | try {
|
| 1429 | renderNameTagForegroundContent(renderer, ctx, textRenderer, entry);
|
| 1430 | } finally {
|
| 1431 | renderer.setAlpha(previousRendererAlpha);
|
| 1432 | foregroundAlpha = previousForegroundAlpha;
|
| 1433 | }
|
| 1434 | }
|
| 1435 |
|
| 1436 | private void renderNameTagForegroundContent(Renderer2D renderer, GuiGraphicsExtractor ctx, TextRenderer textRenderer, RenderEntry entry) {
|
| 1437 | Player player = entry.player();
|
| 1438 | int centerX = entry.centerX();
|
| 1439 | int nameY = entry.nameY();
|
| 1440 | int itemsY = entry.itemsY();
|
| 1441 | if (entry.renderNameplate() && entry.nameplateLayout() != null) {
|
| 1442 | drawNameplateBackground(renderer, player, entry.nameplateLayout());
|
| 1443 | drawNameplateHead(renderer, ctx, player, entry.nameplateLayout());
|
| 1444 | }
|
| 1445 | if (entry.mainHandLayout() != null && entry.mainHand() != null && !entry.mainHand().isEmpty()) {
|
| 1446 | drawMainHandChip(renderer, textRenderer, entry.mainHand(), entry.mainHandLayout());
|
| 1447 | }
|
| 1448 |
|
| 1449 | final int effectsLift = scaleRow(computeEnchantLift(textRenderer, entry.maxEnchantLines()));
|
| 1450 | EquipmentLayout equipmentLayout = entry.renderSlots()
|
| 1451 | ? computeEquipmentLayout(textRenderer, entry.slots(), entry.enchantLines(), centerX,
|
| 1452 | equipIconSize(), equipIconGap(), SMALL_TEXT_SCALE, false)
|
| 1453 | : EquipmentLayout.empty();
|
| 1454 |
|
| 1455 | if (entry.renderSlots()) {
|
| 1456 | drawEquipmentRow(ctx, entry.player(), entry.slots(), equipmentLayout, itemsY);
|
| 1457 | }
|
| 1458 |
|
| 1459 | if (entry.renderEffects()) {
|
| 1460 | EffectIconRenderer.beginBatch();
|
| 1461 | drawEffectsRowIcons(ctx, entry.effects(), centerX, itemsY, effectsLift);
|
| 1462 | EffectIconRenderer.endBatch();
|
| 1463 | }
|
| 1464 |
|
| 1465 | drawOpponentCooldownsStackedIcons(ctx, player, entry.nameplateLayout(), centerX, nameY);
|
| 1466 |
|
| 1467 | boolean startedBaseText = beginTextRenderer(textRenderer, SMALL_TEXT_SCALE);
|
| 1468 | try {
|
| 1469 | if (entry.renderSlots()) {
|
| 1470 | drawEquipmentRowText(textRenderer, entry.slots(), entry.enchantLines(), equipmentLayout, itemsY);
|
| 1471 | }
|
| 1472 |
|
| 1473 | if (entry.renderEffects()) {
|
| 1474 | TextRenderer levelTr = cachedLevelTr != null ? cachedLevelTr : textRenderer;
|
| 1475 | TextRenderer timeTr = cachedTimeTr != null ? cachedTimeTr : textRenderer;
|
| 1476 | drawEffectsRowIconOverlays(textRenderer, levelTr, timeTr, entry.effects(), entry.player().getId(), centerX, itemsY, effectsLift);
|
| 1477 | }
|
| 1478 |
|
| 1479 | drawOpponentCooldownsStackedText(textRenderer, player, entry.nameplateLayout(), centerX, nameY);
|
| 1480 | } finally {
|
| 1481 | endTextRenderer(textRenderer, startedBaseText);
|
| 1482 | }
|
| 1483 |
|
| 1484 | if (entry.renderNameplate() && entry.labelInfo() != null) {
|
| 1485 | LabelInfo info = entry.labelInfo();
|
| 1486 | NameplateLayout layout = entry.nameplateLayout();
|
| 1487 | if (layout != null) {
|
| 1488 | TextRenderer nameTr = cachedNameTr != null ? cachedNameTr : textRenderer;
|
| 1489 | TextRenderer hpTr = cachedHpTr != null ? cachedHpTr : nameTr;
|
| 1490 | boolean clipped = pushNameplateScissor(layout);
|
| 1491 | float scale = layout.labelScale();
|
| 1492 | double nameX = layout.nameX();
|
| 1493 | double nameTextY = layout.nameY();
|
| 1494 | boolean startedName = beginTextRenderer(nameTr, scale);
|
| 1495 | double cursorX = nameX;
|
| 1496 | try {
|
| 1497 | if (!layout.pingText().isEmpty()) {
|
| 1498 | renderNameplateText(nameTr, layout.pingText(), cursorX, nameTextY, resolvePingColor(info.ping()));
|
| 1499 | cursorX += layout.pingWidth() + layout.pingGap();
|
| 1500 | }
|
| 1501 | String prefix = info.pvpPrefix();
|
| 1502 | if (!prefix.isEmpty()) {
|
| 1503 | renderNameplateText(nameTr, prefix, cursorX, nameTextY, pvpPrefixColor.getArgb());
|
| 1504 | cursorX += nameTr.getWidth(prefix);
|
| 1505 | }
|
| 1506 | if (info.styledName() != null) {
|
| 1507 | renderStyledNameplateText(nameTr, info.styledName(), cursorX, nameTextY, CategoryService.getColor(player));
|
| 1508 | } else {
|
| 1509 | renderNameplateText(nameTr, info.name(), cursorX, nameTextY, CategoryService.getColor(player));
|
| 1510 | }
|
| 1511 | } finally {
|
| 1512 | endTextRenderer(nameTr, startedName);
|
| 1513 | }
|
| 1514 |
|
| 1515 | if (!info.hp().isEmpty()) {
|
| 1516 | double hpX = nameX + layout.pingWidth() + layout.pingGap() + layout.nameWidth() + layout.hpGap();
|
| 1517 | boolean startedHp = beginTextRenderer(hpTr, scale);
|
| 1518 | try {
|
| 1519 | renderHealthTag(hpTr, info.hp(), hpX, nameTextY, entry.infoColor());
|
| 1520 | } finally {
|
| 1521 | endTextRenderer(hpTr, startedHp);
|
| 1522 | }
|
| 1523 | }
|
| 1524 |
|
| 1525 | if (!layout.distText().isEmpty()) {
|
| 1526 | double distX = nameX + layout.pingWidth() + layout.pingGap() + layout.nameWidth() + layout.hpGap() + layout.hpWidth()
|
| 1527 | + (layout.hpWidth() > 0 ? DIST_TEXT_GAP : 0);
|
| 1528 | boolean startedDist = beginTextRenderer(nameTr, scale);
|
| 1529 | try {
|
| 1530 | renderNameplateText(nameTr, layout.distText(), distX, nameTextY, 0xFFD0D0D0);
|
| 1531 | } finally {
|
| 1532 | endTextRenderer(nameTr, startedDist);
|
| 1533 | }
|
| 1534 | }
|
| 1535 | if (clipped) ScissorFunction.pop();
|
| 1536 | drawNameplateTotemBadge(renderer, textRenderer, layout, entry.totemPopCount(), entry.totemPopAnimation());
|
| 1537 | }
|
| 1538 | }
|
| 1539 | }
|
| 1540 |
|
| 1541 | private void drawNameplateTotemBadge(Renderer2D renderer,
|
| 1542 | TextRenderer fallbackRenderer,
|
| 1543 | NameplateLayout layout,
|
| 1544 | int count,
|
| 1545 | float animation) {
|
| 1546 | if (renderer == null || layout == null || !layout.renderTotemBadge()) return;
|
| 1547 | if (count <= 0 || animation <= 0.001f) return;
|
| 1548 |
|
| 1549 | float anim = AnimationUtility.easeInOutCubic(animation);
|
| 1550 | float globalAlpha = (clampAlpha(nameplateAlpha.get()) / 255.0f) * anim * foregroundAlpha;
|
| 1551 | if (globalAlpha <= 0.001f) return;
|
| 1552 |
|
| 1553 | drawNameplateDivider(
|
| 1554 | renderer,
|
| 1555 | layout.totemDividerX(),
|
| 1556 | layout.totemDividerY(),
|
| 1557 | layout.totemDividerW(),
|
| 1558 | layout.totemDividerH(),
|
| 1559 | globalAlpha
|
| 1560 | );
|
| 1561 |
|
| 1562 | float blockX = layout.totemBadgeX();
|
| 1563 | float blockY = layout.totemBadgeY();
|
| 1564 | float blockH = layout.totemBadgeH();
|
| 1565 | float iconScale = 0.86f + 0.14f * anim;
|
| 1566 | float iconSize = Math.max(1.0f, layout.totemIconSize() * iconScale);
|
| 1567 | float iconX = blockX;
|
| 1568 | float iconY = blockY + (blockH - iconSize) * 0.5f;
|
| 1569 | renderer.item(totemBadgeStack(), iconX, iconY, Math.max(0.1f, iconSize / 16.0f), 911, Renderer2D.ITEM_OVERLAY_NONE, null);
|
| 1570 |
|
| 1571 | String text = "x" + count;
|
| 1572 | TextRenderer badgeRenderer = BuiltinFontCatalog.INTER_MEDIUM.renderer(fallbackRenderer);
|
| 1573 | float textScale = TOTEM_BADGE_TEXT_SCALE * (0.94f + 0.06f * anim);
|
| 1574 | float textX = iconX + iconSize + TOTEM_BADGE_TEXT_GAP;
|
| 1575 | float textH = (float) badgeRenderer.getHeight(false) * textScale;
|
| 1576 | float textY = blockY + (blockH - textH) * 0.5f - 0.1f;
|
| 1577 | int textColor = withAlpha(0xFFFFFF, Math.round(255.0f * globalAlpha));
|
| 1578 |
|
| 1579 | badgeRenderer.begin(textScale, false, false);
|
| 1580 | try {
|
| 1581 | badgeRenderer.render(text, textX, textY, new RenderColor(textColor), false);
|
| 1582 | } finally {
|
| 1583 | badgeRenderer.end();
|
| 1584 | }
|
| 1585 | }
|
| 1586 |
|
| 1587 | private void drawNameplateHead(Renderer2D renderer, GuiGraphicsExtractor ctx, Player player, NameplateLayout layout) {
|
| 1588 | if (ctx == null || layout == null || !layout.renderHead()) return;
|
| 1589 | if (!(player instanceof AbstractClientPlayer clientPlayer)) return;
|
| 1590 |
|
| 1591 | int alpha = Math.round(clampAlpha(nameplateAlpha.get()) * foregroundAlpha);
|
| 1592 | if (alpha <= 0) return;
|
| 1593 | float globalAlpha = alpha / 255.0f;
|
| 1594 |
|
| 1595 | PlayerHeadRenderer.drawRounded(
|
| 1596 | ctx,
|
| 1597 | layout.headX(),
|
| 1598 | layout.headY(),
|
| 1599 | layout.headSize(),
|
| 1600 | Math.min(6.0f, layout.headSize() * 0.48f),
|
| 1601 | clientPlayer,
|
| 1602 | new RenderColor(withAlpha(0xFFFFFF, alpha)),
|
| 1603 | true,
|
| 1604 | null,
|
| 1605 | 0.0f,
|
| 1606 | false
|
| 1607 | );
|
| 1608 |
|
| 1609 | drawNameplateDivider(
|
| 1610 | renderer,
|
| 1611 | layout.dividerX(),
|
| 1612 | layout.dividerY(),
|
| 1613 | layout.dividerW(),
|
| 1614 | layout.dividerH(),
|
| 1615 | globalAlpha
|
| 1616 | );
|
| 1617 | }
|
| 1618 |
|
| 1619 | private void drawNameplateDivider(Renderer2D renderer,
|
| 1620 | float x,
|
| 1621 | float y,
|
| 1622 | float width,
|
| 1623 | float height,
|
| 1624 | float globalAlpha) {
|
| 1625 | if (renderer == null || width <= 0.0f || height <= 0.0f || globalAlpha <= 0.001f) return;
|
| 1626 | float drawWidth = Math.max(0.5f, width);
|
| 1627 | renderer.quad(
|
| 1628 | x + (width - drawWidth) * 0.5f, y, drawWidth, height,
|
| 1629 | withAlpha(REFERENCE_DIVIDER_RGB, Math.round(REFERENCE_DIVIDER_ALPHA * globalAlpha))
|
| 1630 | );
|
| 1631 | }
|
| 1632 |
|
| 1633 | private void ensureFontCache(TextRenderer fallback) {
|
| 1634 | cachedNameTr = BuiltinFontCatalog.INTER_MEDIUM.renderer(fallback);
|
| 1635 | cachedHpTr = BuiltinFontCatalog.INTER_MEDIUM.renderer(cachedNameTr);
|
| 1636 | cachedLevelTr = BuiltinFontCatalog.INTER_MEDIUM.renderer(fallback);
|
| 1637 | cachedTimeTr = BuiltinFontCatalog.INTER_MEDIUM.renderer(fallback);
|
| 1638 | }
|
| 1639 |
|
| 1640 | public void onResourceReload() {
|
| 1641 | cachedNameTr = null;
|
| 1642 | cachedHpTr = null;
|
| 1643 | cachedLevelTr = null;
|
| 1644 | cachedTimeTr = null;
|
| 1645 | enchantCache.clear();
|
| 1646 | }
|
| 1647 |
|
| 1648 | private boolean shouldShowDistanceText(Player player) {
|
| 1649 | if (!toggles.get("Show distance")) return false;
|
| 1650 | if (player == null || mc.player == null) return false;
|
| 1651 | if (player != mc.player) return true;
|
| 1652 | Freecam freecam = Modules.get(Freecam.class);
|
| 1653 | return freecam != null && freecam.isEnabled();
|
| 1654 | }
|
| 1655 |
|
| 1656 | private ItemStack[] getCachedEquipmentSlots(Player player) {
|
| 1657 | UUID id = player.getUUID();
|
| 1658 | ItemStack[] slots = slotCache.get(id);
|
| 1659 | if (slots == null || slots.length != 5) {
|
| 1660 | slots = new ItemStack[5];
|
| 1661 | slotCache.put(id, slots);
|
| 1662 | }
|
| 1663 | slots[0] = player.getItemBySlot(EquipmentSlot.FEET);
|
| 1664 | slots[1] = player.getItemBySlot(EquipmentSlot.LEGS);
|
| 1665 | slots[2] = player.getItemBySlot(EquipmentSlot.CHEST);
|
| 1666 | slots[3] = player.getItemBySlot(EquipmentSlot.HEAD);
|
| 1667 | slots[4] = player.getOffhandItem();
|
| 1668 | return slots;
|
| 1669 | }
|
| 1670 |
|
| 1671 | private List<MobEffectInstance> resolveEffects(Player player) {
|
| 1672 | UUID id = player.getUUID();
|
| 1673 | EffectCache cache = effectCache.computeIfAbsent(id, key -> new EffectCache());
|
| 1674 | int tick = player.tickCount;
|
| 1675 | if (tick - cache.lastTick >= EFFECT_CACHE_TICKS || cache.effects.isEmpty()) {
|
| 1676 | cache.effects = collectEffects(player);
|
| 1677 | cache.lastTick = tick;
|
| 1678 | }
|
| 1679 | return cache.effects;
|
| 1680 | }
|
| 1681 |
|
| 1682 | private EnchantCache resolveEnchantCache(Player player, ItemStack[] slots) {
|
| 1683 | UUID id = player.getUUID();
|
| 1684 | EnchantCache cache = enchantCache.computeIfAbsent(id, key -> new EnchantCache());
|
| 1685 | int tick = player.tickCount;
|
| 1686 | int signature = equipmentSignature(slots);
|
| 1687 | if (signature != cache.signature
|
| 1688 | || tick - cache.lastTick >= ENCHANT_CACHE_TICKS
|
| 1689 | || cache.lines.isEmpty()) {
|
| 1690 | List<List<EnchantLine>> lines = buildEnchantLines(slots);
|
| 1691 | cache.lines = lines;
|
| 1692 | cache.maxLines = maxEnchantLines(lines);
|
| 1693 | cache.lastTick = tick;
|
| 1694 | cache.signature = signature;
|
| 1695 | }
|
| 1696 | return cache;
|
| 1697 | }
|
| 1698 |
|
| 1699 | private float updateTotemPopAnimation(Player player, TotemPopSnapshot snapshot, float dt) {
|
| 1700 | if (player == null) return 0.0f;
|
| 1701 | UUID id = player.getUUID();
|
| 1702 | boolean visible = snapshot != null && snapshot.visible();
|
| 1703 | if (visible) {
|
| 1704 | totemPopLastCounts.put(id, snapshot.count());
|
| 1705 | }
|
| 1706 |
|
| 1707 | float current = totemPopAnimations.getOrDefault(id, 0.0f);
|
| 1708 | float target = visible ? 1.0f : 0.0f;
|
| 1709 | float next = AnimationUtility.approach(current, target, dt, TOTEM_BADGE_ANIM_SPEED);
|
| 1710 | next = AnimationUtility.snap(next, target, 0.001f);
|
| 1711 |
|
| 1712 | if (next <= 0.001f && !visible) {
|
| 1713 | totemPopAnimations.remove(id);
|
| 1714 | totemPopLastCounts.remove(id);
|
| 1715 | return 0.0f;
|
| 1716 | }
|
| 1717 |
|
| 1718 | totemPopAnimations.put(id, next);
|
| 1719 | return next;
|
| 1720 | }
|
| 1721 |
|
| 1722 | private int resolveTotemPopCount(Player player, TotemPopSnapshot snapshot, float animation) {
|
| 1723 | if (player == null) return 0;
|
| 1724 | if (snapshot != null && snapshot.visible()) {
|
| 1725 | return snapshot.count();
|
| 1726 | }
|
| 1727 | if (animation > 0.001f) {
|
| 1728 | return Math.max(0, totemPopLastCounts.getOrDefault(player.getUUID(), 0));
|
| 1729 | }
|
| 1730 | return 0;
|
| 1731 | }
|
| 1732 |
|
| 1733 | private void pruneCaches() {
|
| 1734 | if (seenIds.isEmpty()) {
|
| 1735 | slotCache.clear();
|
| 1736 | effectCache.clear();
|
| 1737 | enchantCache.clear();
|
| 1738 | totemPopAnimations.clear();
|
| 1739 | totemPopLastCounts.clear();
|
| 1740 | return;
|
| 1741 | }
|
| 1742 | slotCache.keySet().removeIf(id -> !seenIds.contains(id));
|
| 1743 | effectCache.keySet().removeIf(id -> !seenIds.contains(id));
|
| 1744 | enchantCache.keySet().removeIf(id -> !seenIds.contains(id));
|
| 1745 | totemPopAnimations.keySet().removeIf(id -> !seenIds.contains(id));
|
| 1746 | totemPopLastCounts.keySet().removeIf(id -> !seenIds.contains(id));
|
| 1747 | }
|
| 1748 |
|
| 1749 | private void drawEquipmentRow(GuiGraphicsExtractor ctx,
|
| 1750 | Player player,
|
| 1751 | ItemStack[] slots,
|
| 1752 | EquipmentLayout layout,
|
| 1753 | int y) {
|
| 1754 | int iconSize = equipIconSize();
|
| 1755 | int seed = 0;
|
| 1756 |
|
| 1757 | for (int i = 0; i < slots.length; i++) {
|
| 1758 | ItemStack stack = slots[i];
|
| 1759 | float x = (float) (layout.centers()[i] - iconSize * 0.5);
|
| 1760 | if (stack.isEmpty()) continue;
|
| 1761 |
|
| 1762 | float scale = iconSize / 16f;
|
| 1763 | int overlayFlags = Renderer2D.ITEM_OVERLAY_COUNT;
|
| 1764 | if (toggles.get("Item durability bar")) {
|
| 1765 | overlayFlags |= Renderer2D.ITEM_OVERLAY_DURABILITY;
|
| 1766 | }
|
| 1767 | Renderer2D.COLOR.item(stack, x, y, scale, seed++, overlayFlags, null,
|
| 1768 | durabilityStartPercent.get(), 70);
|
| 1769 | drawOpponentItemCooldown(player, stack, x, y, scale);
|
| 1770 | }
|
| 1771 | }
|
| 1772 |
|
| 1773 | private void drawOpponentItemCooldown(Player player, ItemStack stack, float x, float y, float scale) {
|
| 1774 | if (!shouldRenderOpponentStuff(player)) return;
|
| 1775 | if (stack == null || stack.isEmpty()) return;
|
| 1776 |
|
| 1777 | Item item = stack.getItem();
|
| 1778 | if (!CooldownRegistry.isTracked(item)) return;
|
| 1779 |
|
| 1780 | ItemCooldownSnapshot snapshot = OpponentCooldownManager.snapshot(player.getUUID(), item);
|
| 1781 | if (!snapshot.visible()) return;
|
| 1782 | float progress = snapshot.cooling() ? snapshot.cooldownProgress() : snapshot.usesProgress();
|
| 1783 | if (progress <= 0f) return;
|
| 1784 |
|
| 1785 | int top = Mth.floor(16.0F * (1.0F - progress));
|
| 1786 | int bottom = top + Mth.ceil(16.0F * progress);
|
| 1787 | Renderer2D.COLOR.quad(
|
| 1788 | x,
|
| 1789 | y + top * scale,
|
| 1790 | 16.0f * scale,
|
| 1791 | (bottom - top) * scale,
|
| 1792 | snapshot.cooling() ? 0x80FFA500 : 0x706D9DFF
|
| 1793 | );
|
| 1794 |
|
| 1795 | // no text inside slot
|
| 1796 | }
|
| 1797 |
|
| 1798 | private void drawEquipmentRowText(TextRenderer textRenderer, ItemStack[] slots, List<List<EnchantLine>> enchantLines,
|
| 1799 | EquipmentLayout layout, int y) {
|
| 1800 | int iconSize = equipIconSize();
|
| 1801 |
|
| 1802 | for (int i = 0; i < slots.length; i++) {
|
| 1803 | ItemStack stack = slots[i];
|
| 1804 | double center = layout.centers()[i];
|
| 1805 | if (stack.isEmpty()) continue;
|
| 1806 |
|
| 1807 | List<EnchantLine> ench = enchantLines.get(i);
|
| 1808 | if (!ench.isEmpty()) {
|
| 1809 | int lineHeight = (int) textRenderer.getHeight(true) + 1;
|
| 1810 | int startY = y - 14;
|
| 1811 | for (int idx = 0; idx < ench.size(); idx++) {
|
| 1812 | EnchantLine line = ench.get(idx);
|
| 1813 | int lineY = startY - idx * lineHeight;
|
| 1814 | int textX = (int) Math.round(center - textRenderer.getWidth(line.text(), true) * 0.5);
|
| 1815 | renderEquipmentText(textRenderer, line.text(), textX, lineY, line.color());
|
| 1816 | }
|
| 1817 | }
|
| 1818 |
|
| 1819 | }
|
| 1820 | }
|
| 1821 |
|
| 1822 | private EquipmentLayout computeEquipmentLayout(TextRenderer textRenderer,
|
| 1823 | ItemStack[] slots,
|
| 1824 | List<List<EnchantLine>> enchantLines,
|
| 1825 | double centerX,
|
| 1826 | int iconSize,
|
| 1827 | int requestedGap,
|
| 1828 | double enchantTextScale,
|
| 1829 | boolean worldText) {
|
| 1830 | if (slots == null || slots.length == 0) return EquipmentLayout.empty();
|
| 1831 | double[] widths = new double[slots.length];
|
| 1832 | double totalWidth = 0.0;
|
| 1833 | double gap = Math.max(ENCHANT_TEXT_MIN_GAP, requestedGap);
|
| 1834 | for (int i = 0; i < slots.length; i++) {
|
| 1835 | double columnWidth = iconSize;
|
| 1836 | List<EnchantLine> lines = enchantLines != null && i < enchantLines.size()
|
| 1837 | ? enchantLines.get(i)
|
| 1838 | : List.of();
|
| 1839 | for (EnchantLine line : lines) {
|
| 1840 | double textWidth = worldText
|
| 1841 | ? worldTextWidth(textRenderer, RuntimeTextLayout.singleLine(line.text()), enchantTextScale) + 1.0
|
| 1842 | : RuntimeTextLayout.width(textRenderer, line.text(), enchantTextScale, true);
|
| 1843 | columnWidth = Math.max(columnWidth,
|
| 1844 | textWidth);
|
| 1845 | }
|
| 1846 | widths[i] = columnWidth;
|
| 1847 | totalWidth += columnWidth;
|
| 1848 | }
|
| 1849 | totalWidth += Math.max(0, slots.length - 1) * gap;
|
| 1850 |
|
| 1851 | double[] centers = new double[slots.length];
|
| 1852 | double cursor = centerX - totalWidth * 0.5;
|
| 1853 | for (int i = 0; i < widths.length; i++) {
|
| 1854 | centers[i] = cursor + widths[i] * 0.5;
|
| 1855 | cursor += widths[i] + gap;
|
| 1856 | }
|
| 1857 | return new EquipmentLayout(centers, totalWidth);
|
| 1858 | }
|
| 1859 |
|
| 1860 | private int foregroundColor(int argb) {
|
| 1861 | return withAlpha(argb, Math.round(((argb >>> 24) & 0xFF) * foregroundAlpha));
|
| 1862 | }
|
| 1863 |
|
| 1864 | private void renderEquipmentText(TextRenderer textRenderer, String text, double x, double y, int color) {
|
| 1865 | textRenderer.render(text, x, y, new RenderColor(foregroundColor(color)), true);
|
| 1866 | }
|
| 1867 |
|
| 1868 | private void renderHealthTag(TextRenderer textRenderer, String value, double x, double y, int valueColor) {
|
| 1869 | if (value == null || value.isEmpty()) return;
|
| 1870 | renderNameplateText(textRenderer, "[", x, y, 0xFFFFFFFF);
|
| 1871 | double cursor = x + textRenderer.getWidth("[");
|
| 1872 | renderNameplateText(textRenderer, value, cursor, y, valueColor);
|
| 1873 | cursor += textRenderer.getWidth(value);
|
| 1874 | renderNameplateText(textRenderer, "]", cursor, y, 0xFFFFFFFF);
|
| 1875 | }
|
| 1876 |
|
| 1877 | private static void drawWorldHealthTag(Renderer3D renderer,
|
| 1878 | WorldBillboardRenderer.Basis basis,
|
| 1879 | TextRenderer textRenderer,
|
| 1880 | String value,
|
| 1881 | Vec3 anchor,
|
| 1882 | double x,
|
| 1883 | double y,
|
| 1884 | double textScale,
|
| 1885 | double worldScale,
|
| 1886 | int valueColor,
|
| 1887 | float alpha) {
|
| 1888 | if (value == null || value.isEmpty()) return;
|
| 1889 | drawWorldText(renderer, basis, textRenderer, "[", anchor, x, y, textScale, worldScale, 0xFFFFFFFF, alpha);
|
| 1890 | double cursor = x + worldTextWidth(textRenderer, "[", textScale);
|
| 1891 | drawWorldText(renderer, basis, textRenderer, value, anchor, cursor, y, textScale, worldScale, valueColor, alpha);
|
| 1892 | cursor += worldTextWidth(textRenderer, value, textScale);
|
| 1893 | drawWorldText(renderer, basis, textRenderer, "]", anchor, cursor, y, textScale, worldScale, 0xFFFFFFFF, alpha);
|
| 1894 | }
|
| 1895 |
|
| 1896 | private void renderNameplateText(TextRenderer textRenderer, String text, double x, double y, int color) {
|
| 1897 | if (text == null || text.isEmpty()) return;
|
| 1898 | textRenderer.render(text, x, y, new RenderColor(foregroundColor(color)), false);
|
| 1899 | }
|
| 1900 |
|
| 1901 | private void renderStyledNameplateText(TextRenderer textRenderer, Component text, double x, double y, int defaultColor) {
|
| 1902 | if (text == null) return;
|
| 1903 | List<TextRenderUtil.Part> parts = TextRenderUtil.flattenStyled(text, defaultColor);
|
| 1904 | double cursorX = x;
|
| 1905 | for (TextRenderUtil.Part part : parts) {
|
| 1906 | renderNameplateText(textRenderer, part.text(), cursorX, y, part.color());
|
| 1907 | cursorX += textRenderer.getWidth(part.text());
|
| 1908 | }
|
| 1909 | }
|
| 1910 |
|
| 1911 | private boolean shouldUseTabNames() {
|
| 1912 | return nameplateExtras.get("Tab names");
|
| 1913 | }
|
| 1914 |
|
| 1915 | private boolean shouldShowPingText() {
|
| 1916 | return nameplateExtras.get("Ping");
|
| 1917 | }
|
| 1918 |
|
| 1919 | private int getPlayerPing(Player player) {
|
| 1920 | if (player == null || mc == null || mc.getConnection() == null) return -1;
|
| 1921 | PlayerInfo entry = mc.getConnection().getPlayerInfo(player.getUUID());
|
| 1922 | return entry != null ? entry.getLatency() : -1;
|
| 1923 | }
|
| 1924 |
|
| 1925 | private void drawEffectsIcons(GuiGraphicsExtractor ctx, List<MobEffectInstance> effects, int x, int y) {
|
| 1926 | if (effects.isEmpty()) return;
|
| 1927 |
|
| 1928 | int cursorY = y;
|
| 1929 | EffectIconRenderer.beginBatch();
|
| 1930 | for (MobEffectInstance inst : effects) {
|
| 1931 | EffectIconRenderer.draw(ctx, inst, x, cursorY, ICON_SIZE, foregroundColor(0xFFFFFFFF));
|
| 1932 | cursorY += EFFECT_LINE_HEIGHT;
|
| 1933 | }
|
| 1934 | EffectIconRenderer.endBatch();
|
| 1935 | }
|
| 1936 |
|
| 1937 | private void drawEffectsText(TextRenderer textRenderer, List<MobEffectInstance> effects, int entityId, int x, int y) {
|
| 1938 | if (effects.isEmpty()) return;
|
| 1939 |
|
| 1940 | int cursorY = y;
|
| 1941 | for (MobEffectInstance inst : effects) {
|
| 1942 | int textX = x + ICON_SIZE + 6;
|
| 1943 | int textY = cursorY + 4;
|
| 1944 | String dur = formatDuration(entityId, inst);
|
| 1945 | String name = I18n.get(inst.getEffect().value().getDescriptionId());
|
| 1946 | int level = inst.getAmplifier() + 1;
|
| 1947 |
|
| 1948 | if (!dur.isEmpty()) {
|
| 1949 | String seg = dur + " ";
|
| 1950 | textRenderer.render(seg, textX, textY, new RenderColor(foregroundColor(0xFFFFFFFF)), false);
|
| 1951 | textX += (int) textRenderer.getWidth(seg, false);
|
| 1952 | }
|
| 1953 | textRenderer.render(name, textX, textY, new RenderColor(foregroundColor(0xFFFFFFFF)), false);
|
| 1954 | textX += (int) textRenderer.getWidth(name, false);
|
| 1955 | if (level > 1) {
|
| 1956 | String lvl = " " + level;
|
| 1957 | textRenderer.render(lvl, textX, textY, new RenderColor(foregroundColor(EFFECT_LEVEL_COLOR)), false);
|
| 1958 | }
|
| 1959 | cursorY += EFFECT_LINE_HEIGHT;
|
| 1960 | }
|
| 1961 | }
|
| 1962 |
|
| 1963 | private void drawEffectIconOverlays(TextRenderer baseRenderer, TextRenderer levelRenderer, TextRenderer timeRenderer,
|
| 1964 | List<MobEffectInstance> effects, int entityId, int x, int y) {
|
| 1965 | if (effects.isEmpty()) return;
|
| 1966 |
|
| 1967 | TextRenderer levelTr = levelRenderer == null ? baseRenderer : levelRenderer;
|
| 1968 | TextRenderer timeTr = timeRenderer == null ? baseRenderer : timeRenderer;
|
| 1969 |
|
| 1970 | boolean startedLevel = beginTextRenderer(levelTr, SMALL_TEXT_SCALE);
|
| 1971 | boolean startedTime = timeTr != levelTr && beginTextRenderer(timeTr, SMALL_TEXT_SCALE);
|
| 1972 |
|
| 1973 | int levelHeight = (int) levelTr.getHeight(false);
|
| 1974 | int timeHeight = (int) timeTr.getHeight(false);
|
| 1975 | int levelGap = scaleRow(EFFECT_ROW_LEVEL_GAP);
|
| 1976 | int timeGap = scaleRow(EFFECT_ROW_TIME_GAP);
|
| 1977 |
|
| 1978 | int cursorY = y;
|
| 1979 | for (MobEffectInstance inst : effects) {
|
| 1980 | int level = inst.getAmplifier() + 1;
|
| 1981 | String dur = formatDuration(entityId, inst);
|
| 1982 |
|
| 1983 | int iconX = x;
|
| 1984 | int iconY = cursorY;
|
| 1985 |
|
| 1986 | if (!dur.isEmpty()) {
|
| 1987 | int timeW = (int) timeTr.getWidth(dur, false);
|
| 1988 | int timeX = iconX + (ICON_SIZE - timeW) / 2;
|
| 1989 | int timeY = iconY - timeHeight - 1;
|
| 1990 | timeTr.render(dur, timeX, timeY, new RenderColor(foregroundColor(EFFECT_TIME_COLOR)), false);
|
| 1991 | }
|
| 1992 |
|
| 1993 | if (level > 1) {
|
| 1994 | String lvl = String.valueOf(level);
|
| 1995 | int levelW = (int) levelTr.getWidth(lvl, false);
|
| 1996 | int levelX = iconX + (ICON_SIZE - levelW) / 2;
|
| 1997 | int levelY = !dur.isEmpty()
|
| 1998 | ? (iconY - timeHeight - 1 - levelHeight - 1)
|
| 1999 | : (iconY - levelHeight - 1);
|
| 2000 | levelTr.render(lvl, levelX, levelY, new RenderColor(foregroundColor(EFFECT_LEVEL_STACK_COLOR)), false);
|
| 2001 | }
|
| 2002 | cursorY += EFFECT_LINE_HEIGHT;
|
| 2003 | }
|
| 2004 |
|
| 2005 | endTextRenderer(levelTr, startedLevel);
|
| 2006 | endTextRenderer(timeTr, startedTime);
|
| 2007 | }
|
| 2008 |
|
| 2009 | private void drawEffectsRowIconOverlays(TextRenderer baseRenderer, TextRenderer levelRenderer, TextRenderer timeRenderer,
|
| 2010 | List<MobEffectInstance> effects, int entityId, int centerX, int itemsY, int lift) {
|
| 2011 | if (effects.isEmpty()) return;
|
| 2012 |
|
| 2013 | TextRenderer levelTr = levelRenderer == null ? baseRenderer : levelRenderer;
|
| 2014 | TextRenderer timeTr = timeRenderer == null ? baseRenderer : timeRenderer;
|
| 2015 |
|
| 2016 | float rowTextScale = SMALL_TEXT_SCALE * EFFECT_ROW_SCALE;
|
| 2017 | boolean startedLevel = beginTextRenderer(levelTr, rowTextScale);
|
| 2018 | boolean startedTime = timeTr != levelTr && beginTextRenderer(timeTr, rowTextScale);
|
| 2019 |
|
| 2020 | int levelHeight = (int) levelTr.getHeight(false);
|
| 2021 | int timeHeight = (int) timeTr.getHeight(false);
|
| 2022 | int levelGap = scaleRow(EFFECT_ROW_LEVEL_GAP);
|
| 2023 | int timeGap = scaleRow(EFFECT_ROW_TIME_GAP);
|
| 2024 |
|
| 2025 | int count = effects.size();
|
| 2026 | int iconSize = scaleRow(ICON_SIZE);
|
| 2027 | int gap = scaleRow(EFFECT_ROW_ICON_GAP);
|
| 2028 | int rowGap = scaleRow(EFFECT_ROW_GAP);
|
| 2029 | int rowW = count * iconSize + Math.max(0, count - 1) * gap;
|
| 2030 | int startX = centerX - rowW / 2;
|
| 2031 | int iconY = itemsY - iconSize - rowGap - lift;
|
| 2032 |
|
| 2033 | for (int i = 0; i < effects.size(); i++) {
|
| 2034 | MobEffectInstance inst = effects.get(i);
|
| 2035 | int level = inst.getAmplifier() + 1;
|
| 2036 | String dur = formatDuration(entityId, inst);
|
| 2037 |
|
| 2038 | int iconX = startX + i * (iconSize + gap);
|
| 2039 |
|
| 2040 | if (!dur.isEmpty()) {
|
| 2041 | int timeW = (int) timeTr.getWidth(dur, false);
|
| 2042 | int timeX = iconX + (iconSize - timeW) / 2;
|
| 2043 | int timeY = (level > 1)
|
| 2044 | ? (iconY - levelHeight - levelGap - timeHeight - timeGap)
|
| 2045 | : (iconY - timeHeight - levelGap);
|
| 2046 | timeTr.render(dur, timeX, timeY, new RenderColor(foregroundColor(EFFECT_TIME_COLOR)), false);
|
| 2047 | }
|
| 2048 |
|
| 2049 | if (level > 1) {
|
| 2050 | String lvl = roman(level);
|
| 2051 | int levelW = (int) levelTr.getWidth(lvl, false);
|
| 2052 | int levelX = iconX + (iconSize - levelW) / 2;
|
| 2053 | int levelY = iconY - levelHeight - levelGap;
|
| 2054 | levelTr.render(lvl, levelX, levelY, new RenderColor(foregroundColor(EFFECT_LEVEL_STACK_COLOR)), false);
|
| 2055 | }
|
| 2056 | }
|
| 2057 |
|
| 2058 | endTextRenderer(levelTr, startedLevel);
|
| 2059 | endTextRenderer(timeTr, startedTime);
|
| 2060 | }
|
| 2061 |
|
| 2062 | private void drawEffectsRowIcons(GuiGraphicsExtractor ctx, List<MobEffectInstance> effects, int centerX, int itemsY, int lift) {
|
| 2063 | if (effects.isEmpty()) return;
|
| 2064 | int count = effects.size();
|
| 2065 | int iconSize = scaleRow(ICON_SIZE);
|
| 2066 | int gap = scaleRow(EFFECT_ROW_ICON_GAP);
|
| 2067 | int rowGap = scaleRow(EFFECT_ROW_GAP);
|
| 2068 | int rowW = count * iconSize + Math.max(0, count - 1) * gap;
|
| 2069 | int startX = centerX - rowW / 2;
|
| 2070 | int y = itemsY - iconSize - rowGap - lift;
|
| 2071 |
|
| 2072 | for (int i = 0; i < effects.size(); i++) {
|
| 2073 | int x = startX + i * (iconSize + gap);
|
| 2074 | EffectIconRenderer.draw(ctx, effects.get(i), x, y, iconSize, foregroundColor(0xFFFFFFFF));
|
| 2075 | }
|
| 2076 | }
|
| 2077 |
|
| 2078 | private int computeEnchantLift(TextRenderer textRenderer, int maxLines) {
|
| 2079 | if (!toggles.get("Show armor row")) return 0;
|
| 2080 | if (maxLines <= 0) return 6;
|
| 2081 | int lineHeight = (int) Math.round(textRenderer.getHeight(true) * SMALL_TEXT_SCALE) + 1;
|
| 2082 | return 6 + maxLines * lineHeight;
|
| 2083 | }
|
| 2084 |
|
| 2085 | private LabelInfo buildLabelInfo(Player player) {
|
| 2086 | Component styledName = resolveNameplateText(player);
|
| 2087 | String name = styledName == null ? "" : styledName.getString();
|
| 2088 | String prefix = "";
|
| 2089 | if (pvpPrefix.get() && PvpTargetState.isTargetInPvp(player.getUUID())) {
|
| 2090 | prefix = "[PVP] ";
|
| 2091 | }
|
| 2092 | int ping = getPlayerPing(player);
|
| 2093 | String pingText = shouldShowPingText() && ping >= 0 ? ping + "ms" : "";
|
| 2094 | if (isCreative(player)) {
|
| 2095 | return new LabelInfo(prefix, styledName, name, ping, pingText, "GM", PlayerRelations.get().colorStaff());
|
| 2096 | }
|
| 2097 | PlayerHealthResolver.HealthSnapshot health = PlayerHealthResolver.resolve(player);
|
| 2098 | String hp = formatHealth(health.totalHealth());
|
| 2099 | int color = HP_RED;
|
| 2100 | return new LabelInfo(prefix, styledName, name, ping, pingText, hp, color);
|
| 2101 | }
|
| 2102 |
|
| 2103 | private Component resolveNameplateText(Player player) {
|
| 2104 | if (player == null) return Component.empty();
|
| 2105 | String fallback = player.getGameProfile().name();
|
| 2106 | if (!shouldUseTabNames()) {
|
| 2107 | Component display = player.getDisplayName();
|
| 2108 | Component resolved = display != null ? display : Component.literal(fallback);
|
| 2109 | Component sanitized = normalizeNameplateComponent(resolved);
|
| 2110 | return sanitized.getString().isBlank() ? Component.literal(fallback) : sanitized;
|
| 2111 | }
|
| 2112 |
|
| 2113 | var handler = mc.getConnection();
|
| 2114 | if (handler == null) return Component.literal(fallback);
|
| 2115 | PlayerInfo entry = handler.getPlayerInfo(player.getUUID());
|
| 2116 | if (entry == null) return Component.literal(fallback);
|
| 2117 |
|
| 2118 | Component displayName = entry.getTabListDisplayName();
|
| 2119 | if (displayName == null) return Component.literal(fallback);
|
| 2120 |
|
| 2121 | Component parsed = normalizeNameplateComponent(displayName);
|
| 2122 | if (parsed == null || parsed.getString().isBlank()) return Component.literal(fallback);
|
| 2123 | return parsed;
|
| 2124 | }
|
| 2125 |
|
| 2126 | private static Component normalizeNameplateComponent(Component value) {
|
| 2127 | if (value == null) return Component.empty();
|
| 2128 | return RuntimeTextLayout.singleLine(LegacyTextUtil.convertLegacyCodesRobust(value));
|
| 2129 | }
|
| 2130 |
|
| 2131 | private String formatHealth(float hp) {
|
| 2132 | if (hpDecimals.get()) {
|
| 2133 | return formatTenths(hp);
|
| 2134 | }
|
| 2135 | int value = (int) Math.ceil(hp);
|
| 2136 | return String.valueOf(value);
|
| 2137 | }
|
| 2138 |
|
| 2139 | private float totalHealth(Player player) {
|
| 2140 | return PlayerHealthResolver.resolve(player).totalHealth();
|
| 2141 | }
|
| 2142 |
|
| 2143 | private float maxTotalHealth(Player player) {
|
| 2144 | return PlayerHealthResolver.resolve(player).maxHealth();
|
| 2145 | }
|
| 2146 |
|
| 2147 | private String formatTenths(float value) {
|
| 2148 | int tenth = Math.round(value * 10f);
|
| 2149 | int whole = tenth / 10;
|
| 2150 | int frac = Math.abs(tenth % 10);
|
| 2151 | return whole + "." + frac;
|
| 2152 | }
|
| 2153 |
|
| 2154 | private int resolveHealthColor(float current, float max) {
|
| 2155 | if (current > max) return HP_CYAN;
|
| 2156 | if ("Static".equalsIgnoreCase(hpColorMode.get())) {
|
| 2157 | return HP_GREEN;
|
| 2158 | }
|
| 2159 | return gradientHealthColor(current, max);
|
| 2160 | }
|
| 2161 |
|
| 2162 | private int gradientHealthColor(float current, float max) {
|
| 2163 | if (max <= 0f) return HP_RED;
|
| 2164 | float clamped = Mth.clamp(current, 0f, max);
|
| 2165 | if (max <= 20f) {
|
| 2166 | float t = clamped / max;
|
| 2167 | return lerpColor(HP_RED, HP_GREEN, t);
|
| 2168 | }
|
| 2169 | if (clamped <= 20f) {
|
| 2170 | float t = clamped / 20f;
|
| 2171 | return lerpColor(HP_RED, HP_GREEN, t);
|
| 2172 | }
|
| 2173 | float t = (clamped - 20f) / (max - 20f);
|
| 2174 | return lerpColor(HP_GREEN, HP_CYAN, Mth.clamp(t, 0f, 1f));
|
| 2175 | }
|
| 2176 |
|
| 2177 | private boolean isCreative(Player player) {
|
| 2178 | if (player.isCreative()) return true;
|
| 2179 | var handler = mc.getConnection();
|
| 2180 | if (handler == null) return false;
|
| 2181 | PlayerInfo entry = handler.getPlayerInfo(player.getUUID());
|
| 2182 | if (entry == null) return false;
|
| 2183 | GameType mode = entry.getGameMode();
|
| 2184 | return mode == GameType.CREATIVE;
|
| 2185 | }
|
| 2186 |
|
| 2187 | private String formatEffectText(int entityId, MobEffectInstance inst) {
|
| 2188 | String name = I18n.get(inst.getEffect().value().getDescriptionId());
|
| 2189 | int level = inst.getAmplifier() + 1;
|
| 2190 | if (level > 1) name = name + " " + level;
|
| 2191 | String dur = formatDuration(entityId, inst);
|
| 2192 | return dur.isEmpty() ? name : dur + " " + name;
|
| 2193 | }
|
| 2194 |
|
| 2195 | private String formatDuration(int entityId, MobEffectInstance inst) {
|
| 2196 | if (StatusEffectTracker.shouldHideDuration(entityId, inst.getEffect())) return "";
|
| 2197 | int ticks = inst.getDuration();
|
| 2198 | if (ticks < 0 || ticks >= 32767) return "";
|
| 2199 | int totalSeconds = Math.max(0, ticks / 20);
|
| 2200 | int minutes = totalSeconds / 60;
|
| 2201 | int seconds = totalSeconds % 60;
|
| 2202 | if (seconds < 10) return minutes + ":0" + seconds;
|
| 2203 | return minutes + ":" + seconds;
|
| 2204 | }
|
| 2205 |
|
| 2206 | private List<MobEffectInstance> collectEffects(Player player) {
|
| 2207 | return StatusEffectView.collectHudEffects(player);
|
| 2208 | }
|
| 2209 |
|
| 2210 | private String roman(int n) {
|
| 2211 | if (n <= 0) return String.valueOf(n);
|
| 2212 | int value = n;
|
| 2213 | StringBuilder sb = new StringBuilder();
|
| 2214 | int[] vals = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
|
| 2215 | String[] syms = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
|
| 2216 | for (int i = 0; i < vals.length; i++) {
|
| 2217 | while (value >= vals[i]) {
|
| 2218 | value -= vals[i];
|
| 2219 | sb.append(syms[i]);
|
| 2220 | }
|
| 2221 | }
|
| 2222 | return sb.toString();
|
| 2223 | }
|
| 2224 |
|
| 2225 | private List<EnchantLine> formatEnchantments(ItemStack stack) {
|
| 2226 | List<EnchantLine> parts = new ArrayList<>();
|
| 2227 |
|
| 2228 | ItemEnchantments enchComp = EnchantmentHelper.getEnchantmentsForCrafting(stack);
|
| 2229 | for (Object2IntMap.Entry<Holder<Enchantment>> entry : enchComp.entrySet()) {
|
| 2230 | Holder<Enchantment> ref = entry.getKey();
|
| 2231 | int level = entry.getIntValue();
|
| 2232 | if (level <= 0) continue;
|
| 2233 |
|
| 2234 | ResourceKey<Enchantment> key = ref.unwrapKey().orElse(null);
|
| 2235 | if (key == null) continue;
|
| 2236 |
|
| 2237 | EnchantMeta meta = EnchantRegistry.REGISTRY.get(key);
|
| 2238 | if (meta == null) continue;
|
| 2239 |
|
| 2240 | Enchantment value = ref.value();
|
| 2241 | boolean singleLevel = value.getMaxLevel() == 1;
|
| 2242 | boolean overMax = EnchantUtil.isInvalidLevel(ref, level);
|
| 2243 | if (!isEnchantEnabled(meta.category(), meta.key())
|
| 2244 | && !(illegalEnchantsAlways.get() && overMax)) {
|
| 2245 | continue;
|
| 2246 | }
|
| 2247 |
|
| 2248 | String shortName = limitCodePoints(meta.shortName(), ENCHANT_NAME_MAX_CODEPOINTS);
|
| 2249 | String text = singleLevel && level == 1
|
| 2250 | ? shortName
|
| 2251 | : shortName + level;
|
| 2252 |
|
| 2253 | int color = overMax
|
| 2254 | ? IllegalItemUtil.illegalColor()
|
| 2255 | : (level == value.getMaxLevel() ? TopEnchantUtil.topColor() : 0xFFFFFFFF);
|
| 2256 |
|
| 2257 | parts.add(new EnchantLine(text, color));
|
| 2258 | }
|
| 2259 |
|
| 2260 | return parts;
|
| 2261 | }
|
| 2262 |
|
| 2263 | private static String limitCodePoints(String value, int maxCodePoints) {
|
| 2264 | if (value == null || value.isEmpty() || maxCodePoints <= 0) return "";
|
| 2265 | int count = value.codePointCount(0, value.length());
|
| 2266 | if (count <= maxCodePoints) return value;
|
| 2267 | return value.substring(0, value.offsetByCodePoints(0, maxCodePoints));
|
| 2268 | }
|
| 2269 |
|
| 2270 | private boolean isEnchantEnabled(String category, String path) {
|
| 2271 | Map<String, Boolean> map = switch (category) {
|
| 2272 | case "armor" -> enchantArmor.get();
|
| 2273 | case "melee" -> enchantMelee.get();
|
| 2274 | case "tools" -> enchantTools.get();
|
| 2275 | case "bow" -> enchantBow.get();
|
| 2276 | case "fishing" -> enchantFishing.get();
|
| 2277 | case "trident" -> enchantTrident.get();
|
| 2278 | case "crossbow" -> enchantCrossbow.get();
|
| 2279 | case "mace" -> enchantMace.get();
|
| 2280 | default -> enchantOther.get();
|
| 2281 | };
|
| 2282 | return map.getOrDefault(path, false);
|
| 2283 | }
|
| 2284 |
|
| 2285 | private boolean shouldRenderOpponentStuff(Player p) {
|
| 2286 | if (p == null || mc.player == null) return false;
|
| 2287 | if (p == mc.player) return false;
|
| 2288 | if (!opponentAppleCooldowns.get()) return false;
|
| 2289 | if (!isOpponentAppleTrackingEnabled()) return false;
|
| 2290 | if (!PvpTargetState.isTargetInPvp(p.getUUID()) && !hasOpponentCooldowns(p.getUUID())) return false;
|
| 2291 | double maxDist = OPPONENT_DISTANCE;
|
| 2292 | return !(maxDist > 0) || !(mc.player.distanceToSqr(p) > maxDist * maxDist);
|
| 2293 | }
|
| 2294 |
|
| 2295 | private boolean isOpponentAppleTrackingEnabled() {
|
| 2296 | PvpCooldowns mod = Modules.get(PvpCooldowns.class);
|
| 2297 | return mod != null && mod.isSystemEnabled();
|
| 2298 | }
|
| 2299 |
|
| 2300 | private void drawOpponentCooldownsStackedIcons(GuiGraphicsExtractor ctx, Player player, NameplateLayout layout, int centerX, int nameY) {
|
| 2301 | if (!shouldRenderOpponentStuff(player)) return;
|
| 2302 |
|
| 2303 | int startX = computeOpponentStackX(layout, centerX);
|
| 2304 | int startY = computeOpponentStackY(nameY);
|
| 2305 |
|
| 2306 | int y = startY;
|
| 2307 | int seed = 0;
|
| 2308 | for (Item item : CooldownRegistry.trackedItems()) {
|
| 2309 | ItemCooldownSnapshot snapshot = OpponentCooldownManager.snapshot(player.getUUID(), item);
|
| 2310 | if (!snapshot.visible()) continue;
|
| 2311 |
|
| 2312 | ItemStack icon = new ItemStack(item);
|
| 2313 | float scale = ICON_SIZE / 16f;
|
| 2314 | Renderer2D.COLOR.item(icon, startX, y, scale, seed++, Renderer2D.ITEM_OVERLAY_NONE, null);
|
| 2315 |
|
| 2316 | y += EFFECT_LINE_HEIGHT;
|
| 2317 | }
|
| 2318 | }
|
| 2319 |
|
| 2320 | private void drawOpponentCooldownsStackedText(TextRenderer textRenderer, Player player, NameplateLayout layout, int centerX, int nameY) {
|
| 2321 | if (!shouldRenderOpponentStuff(player)) return;
|
| 2322 |
|
| 2323 | int startX = computeOpponentStackX(layout, centerX);
|
| 2324 | int startY = computeOpponentStackY(nameY);
|
| 2325 |
|
| 2326 | int timeColor = PvpTargetState.isTargetInPvp(player.getUUID())
|
| 2327 | ? OPP_TIME_COLOR
|
| 2328 | : OPP_TIME_COLOR_GRACE;
|
| 2329 | int y = startY;
|
| 2330 | for (Item item : CooldownRegistry.trackedItems()) {
|
| 2331 | ItemCooldownSnapshot snapshot = OpponentCooldownManager.snapshot(player.getUUID(), item);
|
| 2332 | if (!snapshot.visible()) continue;
|
| 2333 |
|
| 2334 | String prefix = snapshot.compactText();
|
| 2335 | if (!prefix.isEmpty()) {
|
| 2336 | int textX = startX + ICON_SIZE + 6;
|
| 2337 | int textY = y + 4;
|
| 2338 | textRenderer.render(prefix + " ", textX, textY,
|
| 2339 | new RenderColor(foregroundColor(snapshot.cooling() ? timeColor : OPP_TIME_COLOR_GRACE)), false);
|
| 2340 | }
|
| 2341 |
|
| 2342 | y += EFFECT_LINE_HEIGHT;
|
| 2343 | }
|
| 2344 | }
|
| 2345 |
|
| 2346 | private Vec3 obtainEntityLerpedPos(Entity e, float tickDelta) {
|
| 2347 | try {
|
| 2348 | return e.getPosition(tickDelta);
|
| 2349 | } catch (NoSuchMethodError ex) {
|
| 2350 | if (e instanceof IEntity access) {
|
| 2351 | return access.get$InstantRenderPos().lerp(e.position(), tickDelta);
|
| 2352 | }
|
| 2353 | return e.position();
|
| 2354 | }
|
| 2355 | }
|
| 2356 |
|
| 2357 | private ScreenRect projectBoxScreen(AABB box, float tickDelta) {
|
| 2358 | double minX = Double.POSITIVE_INFINITY, minY = Double.POSITIVE_INFINITY;
|
| 2359 | double maxX = Double.NEGATIVE_INFINITY, maxY = Double.NEGATIVE_INFINITY;
|
| 2360 | boolean any = false;
|
| 2361 | double[] xs = {box.minX, box.maxX};
|
| 2362 | double[] ys = {box.minY, box.maxY};
|
| 2363 | double[] zs = {box.minZ, box.maxZ};
|
| 2364 | for (double x : xs) {
|
| 2365 | for (double y : ys) {
|
| 2366 | for (double z : zs) {
|
| 2367 | Vec3 screen = ScreenProjection.worldToScreen(new Vec3(x, y, z), tickDelta);
|
| 2368 | if (screen == null) continue;
|
| 2369 | any = true;
|
| 2370 | minX = Math.min(minX, screen.x);
|
| 2371 | minY = Math.min(minY, screen.y);
|
| 2372 | maxX = Math.max(maxX, screen.x);
|
| 2373 | maxY = Math.max(maxY, screen.y);
|
| 2374 | }
|
| 2375 | }
|
| 2376 | }
|
| 2377 | if (!any || maxX <= minX || maxY <= minY) return null;
|
| 2378 | minX = Math.floor(minX);
|
| 2379 | minY = Math.floor(minY);
|
| 2380 | maxX = Math.ceil(maxX);
|
| 2381 | maxY = Math.ceil(maxY);
|
| 2382 | return new ScreenRect(minX, minY, maxX, maxY);
|
| 2383 | }
|
| 2384 |
|
| 2385 | private ItemStack[] getEquipmentSlots(Player player) {
|
| 2386 | ItemStack off = player.getOffhandItem();
|
| 2387 | ItemStack boots = player.getItemBySlot(EquipmentSlot.FEET);
|
| 2388 | ItemStack legs = player.getItemBySlot(EquipmentSlot.LEGS);
|
| 2389 | ItemStack chest = player.getItemBySlot(EquipmentSlot.CHEST);
|
| 2390 | ItemStack head = player.getItemBySlot(EquipmentSlot.HEAD);
|
| 2391 | return new ItemStack[]{boots, legs, chest, head, off};
|
| 2392 | }
|
| 2393 |
|
| 2394 | private List<List<EnchantLine>> buildEnchantLines(ItemStack[] slots) {
|
| 2395 | List<List<EnchantLine>> result = new ArrayList<>(slots.length);
|
| 2396 | for (ItemStack stack : slots) {
|
| 2397 | if (stack.isEmpty()) {
|
| 2398 | result.add(List.of());
|
| 2399 | continue;
|
| 2400 | }
|
| 2401 | List<EnchantLine> lines = formatEnchantments(stack);
|
| 2402 | result.add(lines.isEmpty() ? List.of() : lines);
|
| 2403 | }
|
| 2404 | return result;
|
| 2405 | }
|
| 2406 |
|
| 2407 | private int maxEnchantLines(List<List<EnchantLine>> lines) {
|
| 2408 | int max = 0;
|
| 2409 | for (List<EnchantLine> entry : lines) {
|
| 2410 | int size = entry.size();
|
| 2411 | if (size > max) max = size;
|
| 2412 | }
|
| 2413 | return max;
|
| 2414 | }
|
| 2415 |
|
| 2416 | private enum PresentationMode implements EnumValue.IdProvider {
|
| 2417 | TWO_D("2d"),
|
| 2418 | THREE_D("3d"),
|
| 2419 | HYBRID("hybrid");
|
| 2420 |
|
| 2421 | private final String id;
|
| 2422 |
|
| 2423 | PresentationMode(String id) {
|
| 2424 | this.id = id;
|
| 2425 | }
|
| 2426 |
|
| 2427 | @Override
|
| 2428 | public String id() {
|
| 2429 | return id;
|
| 2430 | }
|
| 2431 | }
|
| 2432 |
|
| 2433 | private static final class EffectCache {
|
| 2434 | int lastTick = -1;
|
| 2435 | List<MobEffectInstance> effects = List.of();
|
| 2436 | }
|
| 2437 |
|
| 2438 | private static final class EnchantCache {
|
| 2439 | int lastTick = -1;
|
| 2440 | int signature = 0;
|
| 2441 | List<List<EnchantLine>> lines = List.of();
|
| 2442 | int maxLines = 0;
|
| 2443 | }
|
| 2444 |
|
| 2445 | private record ScreenRect(double minX, double minY, double maxX, double maxY) {
|
| 2446 | }
|
| 2447 |
|
| 2448 | private record NameplateLayout(int nameX, int nameY, int width, int height, float labelScale,
|
| 2449 | String pingText, String distText, float bgX, float bgY, float bgW, float bgH,
|
| 2450 | int pingWidth, int pingGap, int nameWidth, int hpWidth, int hpGap,
|
| 2451 | boolean renderHead, float headX, float headY, float headSize,
|
| 2452 | float dividerX, float dividerY, float dividerW, float dividerH,
|
| 2453 | boolean renderTotemBadge, float totemDividerX, float totemDividerY,
|
| 2454 | float totemDividerW, float totemDividerH, float totemBadgeX, float totemBadgeY,
|
| 2455 | float totemBadgeW, float totemBadgeH, float totemIconSize) {
|
| 2456 | }
|
| 2457 |
|
| 2458 | private record EnchantLine(String text, int color) {
|
| 2459 | }
|
| 2460 |
|
| 2461 | private record EquipmentLayout(double[] centers, double rowWidth) {
|
| 2462 | private static EquipmentLayout empty() {
|
| 2463 | return new EquipmentLayout(new double[0], 0.0);
|
| 2464 | }
|
| 2465 | }
|
| 2466 |
|
| 2467 | private record WorldRenderEntry(Player player,
|
| 2468 | Vec3 anchor,
|
| 2469 | Vec3 bottomAnchor,
|
| 2470 | double distance,
|
| 2471 | double worldScale,
|
| 2472 | float alpha,
|
| 2473 | boolean renderNameplate,
|
| 2474 | boolean renderSlots,
|
| 2475 | boolean renderEffects,
|
| 2476 | ItemStack[] slots,
|
| 2477 | List<List<EnchantLine>> enchantLines,
|
| 2478 | int maxEnchantLines,
|
| 2479 | List<MobEffectInstance> effects,
|
| 2480 | int totemPopCount,
|
| 2481 | float totemPopAnimation,
|
| 2482 | ItemStack mainHand,
|
| 2483 | boolean renderMainHand,
|
| 2484 | ItemStack[] worldItems) {
|
| 2485 | }
|
| 2486 |
|
| 2487 | private record MainHandLayout(float x, float y, float width, float height,
|
| 2488 | float iconX, float iconY, float iconSize,
|
| 2489 | float textX, float textY, float textScale, Component text) {
|
| 2490 | }
|
| 2491 |
|
| 2492 | private record RenderEntry(Player player, double dist, int centerX, int nameY, int itemsY,
|
| 2493 | boolean renderSlots, boolean renderNameplate,
|
| 2494 | boolean renderEffects, LabelInfo labelInfo, int infoColor,
|
| 2495 | NameplateLayout nameplateLayout, ItemStack mainHand, MainHandLayout mainHandLayout,
|
| 2496 | ItemStack[] slots, List<List<EnchantLine>> enchantLines, int maxEnchantLines,
|
| 2497 | List<MobEffectInstance> effects, int totemPopCount, float totemPopAnimation,
|
| 2498 | float presentationAlpha) {
|
| 2499 | }
|
| 2500 |
|
| 2501 | private record LabelInfo(String pvpPrefix, Component styledName, String name, int ping, String pingText, String hp,
|
| 2502 | int infoColor) {
|
| 2503 | }
|
| 2504 | }
|
| 2505 |
|