Hud .java

net.minecraft.client.gui.Hud (class, 1469 lines): members: NUM_AIR_BUBBLE_POPPED_BEFORE_SOUND_VOLUME_INCREASE, CROSSHAIR_ATTACK_INDICATOR_PROGRESS_SPRITE.

net.minecraft.client.guiclass1,469 linesclient59.3 KB

API Surface (27)

void registerReloadListeners(final ReloadableResourceManager resourceManager)
void toggle()
boolean isHidden()
void resetTitleTimes()
void extractRenderState(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker)
void extractDebugOverlay(final GuiGraphicsExtractor graphics)
void extractDeferredSubtitles()
Identifier getMobEffectSprite(final Holder<MobEffect> effect)
void tick(final boolean pause)
void setNowPlaying(final Component string)
void setOverlayMessage(final Component string, final boolean animate)
void setTimes(final int fadeInTime, final int stayTime, final int fadeOutTime)
void setSubtitle(final Component subtitle)
void setTitle(final Component title)
void clearTitles()
ChatComponent getChat()
WaypointStyleManager getWaypointStyles()
int getGuiTicks()
Font getFont()
SpectatorGui getSpectatorGui()
PlayerTabOverlay getTabList()
void onDisconnected()
BossHealthOverlay getBossOverlay()
DebugScreenOverlay getDebugOverlay()
void clearCache()
void extractSavingIndicator(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker)
Identifier getSprite(final boolean isHardcore, final boolean isHalf, final boolean isBlink)

Fields & Constants (105)

CROSSHAIR_SPRITE
CROSSHAIR_ATTACK_INDICATOR_FULL_SPRITE
CROSSHAIR_ATTACK_INDICATOR_BACKGROUND_SPRITE
CROSSHAIR_ATTACK_INDICATOR_PROGRESS_SPRITE
EFFECT_BACKGROUND_AMBIENT_SPRITE
EFFECT_BACKGROUND_SPRITE
HOTBAR_SPRITE
HOTBAR_SELECTION_SPRITE
HOTBAR_OFFHAND_LEFT_SPRITE
HOTBAR_OFFHAND_RIGHT_SPRITE
HOTBAR_ATTACK_INDICATOR_BACKGROUND_SPRITE
HOTBAR_ATTACK_INDICATOR_PROGRESS_SPRITE
ARMOR_EMPTY_SPRITE
ARMOR_HALF_SPRITE
ARMOR_FULL_SPRITE
FOOD_EMPTY_HUNGER_SPRITE
FOOD_HALF_HUNGER_SPRITE
FOOD_FULL_HUNGER_SPRITE
FOOD_EMPTY_SPRITE
FOOD_HALF_SPRITE
FOOD_FULL_SPRITE
AIR_SPRITE
AIR_POPPING_SPRITE
AIR_EMPTY_SPRITE
HEART_VEHICLE_CONTAINER_SPRITE
HEART_VEHICLE_FULL_SPRITE
HEART_VEHICLE_HALF_SPRITE
VIGNETTE_LOCATION
NAUSEA_LOCATION
SPYGLASS_SCOPE_LOCATION
POWDER_SNOW_OUTLINE_LOCATION
SCORE_DISPLAY_ORDER
DEMO_EXPIRED_TEXT
SAVING_TEXT
MIN_CROSSHAIR_ATTACK_SPEED
EXPERIENCE_BAR_DISPLAY_TICKS
NUM_HEARTS_PER_ROW
LINE_HEIGHT
SPACER
PORTAL_OVERLAY_ALPHA_MIN
HEART_SIZE
HEART_SEPARATION
NUM_AIR_BUBBLES
AIR_BUBBLE_SIZE
AIR_BUBBLE_SEPERATION
AIR_BUBBLE_POPPING_DURATION
EMPTY_AIR_BUBBLE_DELAY_DURATION
AIR_BUBBLE_POP_SOUND_VOLUME_BASE
AIR_BUBBLE_POP_SOUND_VOLUME_INCREMENT
AIR_BUBBLE_POP_SOUND_PITCH_BASE
AIR_BUBBLE_POP_SOUND_PITCH_INCREMENT
NUM_AIR_BUBBLE_POPPED_BEFORE_SOUND_VOLUME_INCREASE
NUM_AIR_BUBBLE_POPPED_BEFORE_SOUND_PITCH_INCREASE
AUTOSAVE_FADE_SPEED_FACTOR
SAVING_INDICATOR_WIDTH_PADDING_RIGHT
SAVING_INDICATOR_HEIGHT_PADDING_BOTTOM
random
minecraft
chat
waypointStyles
isHidden
tickCount
overlayMessageString
overlayMessageTime
animateOverlayMessageColor
vignetteBrightness
toolHighlightTimer
lastToolHighlight
debugOverlay
subtitleOverlay
spectatorGui
tabList
bossOverlay
titleTime
title
subtitle
titleFadeInTime
titleStayTime
titleFadeOutTime
lastHealth

…and 25 more (see full source).

String literals (90)

"hud/crosshair"
"hud/crosshair_attack_indicator_full"
"hud/crosshair_attack_indicator_background"
"hud/crosshair_attack_indicator_progress"
"hud/effect_background_ambient"
"hud/effect_background"
"hud/hotbar"
"hud/hotbar_selection"
"hud/hotbar_offhand_left"
"hud/hotbar_offhand_right"
"hud/hotbar_attack_indicator_background"
"hud/hotbar_attack_indicator_progress"
"hud/armor_empty"
"hud/armor_half"
"hud/armor_full"
"hud/food_empty_hunger"
"hud/food_half_hunger"
"hud/food_full_hunger"
"hud/food_empty"
"hud/food_half"
"hud/food_full"
"hud/air"
"hud/air_bursting"
"hud/air_empty"

Code Graph: Dependencies (75)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Hud.java1469 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.ImmutableMap;
4
import com.google.common.collect.Ordering;
5
import com.mojang.blaze3d.platform.Window;
6
import com.mojang.datafixers.util.Pair;
7
import java.util.Collection;
8
import java.util.Comparator;
9
import java.util.Map;
10
import java.util.Optional;
11
import java.util.function.Supplier;
12
import net.fabricmc.api.EnvType;
13
import net.fabricmc.api.Environment;
14
import net.minecraft.ChatFormatting;
15
import net.minecraft.Optionull;
16
import net.minecraft.client.AttackIndicatorStatus;
17
import net.minecraft.client.DeltaTracker;
18
import net.minecraft.client.Minecraft;
19
import net.minecraft.client.Options;
20
import net.minecraft.client.gui.components.BossHealthOverlay;
21
import net.minecraft.client.gui.components.ChatComponent;
22
import net.minecraft.client.gui.components.DebugScreenOverlay;
23
import net.minecraft.client.gui.components.PlayerTabOverlay;
24
import net.minecraft.client.gui.components.SubtitleOverlay;
25
import net.minecraft.client.gui.components.debug.DebugScreenEntries;
26
import net.minecraft.client.gui.components.spectator.SpectatorGui;
27
import net.minecraft.client.gui.contextualbar.ContextualBar;
28
import net.minecraft.client.gui.contextualbar.ExperienceBar;
29
import net.minecraft.client.gui.contextualbar.JumpableVehicleBar;
30
import net.minecraft.client.gui.contextualbar.LocatorBar;
31
import net.minecraft.client.gui.screens.LevelLoadingScreen;
32
import net.minecraft.client.player.LocalPlayer;
33
import net.minecraft.client.renderer.Lightmap;
34
import net.minecraft.client.renderer.RenderPipelines;
35
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
36
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
37
import net.minecraft.client.resources.WaypointStyleManager;
38
import net.minecraft.core.BlockPos;
39
import net.minecraft.core.Holder;
40
import net.minecraft.core.component.DataComponents;
41
import net.minecraft.network.chat.Component;
42
import net.minecraft.network.chat.MutableComponent;
43
import net.minecraft.network.chat.numbers.NumberFormat;
44
import net.minecraft.network.chat.numbers.StyledFormat;
45
import net.minecraft.resources.Identifier;
46
import net.minecraft.resources.ResourceKey;
47
import net.minecraft.server.MinecraftServer;
48
import net.minecraft.server.packs.resources.ReloadableResourceManager;
49
import net.minecraft.sounds.SoundEvents;
50
import net.minecraft.tags.FluidTags;
51
import net.minecraft.util.ARGB;
52
import net.minecraft.util.Mth;
53
import net.minecraft.util.RandomSource;
54
import net.minecraft.util.StringUtil;
55
import net.minecraft.util.Util;
56
import net.minecraft.util.profiling.Profiler;
57
import net.minecraft.world.MenuProvider;
58
import net.minecraft.world.effect.MobEffect;
59
import net.minecraft.world.effect.MobEffectInstance;
60
import net.minecraft.world.effect.MobEffects;
61
import net.minecraft.world.entity.Entity;
62
import net.minecraft.world.entity.EquipmentSlot;
63
import net.minecraft.world.entity.HumanoidArm;
64
import net.minecraft.world.entity.LivingEntity;
65
import net.minecraft.world.entity.PlayerRideableJumping;
66
import net.minecraft.world.entity.ai.attributes.Attributes;
67
import net.minecraft.world.entity.player.Player;
68
import net.minecraft.world.food.FoodData;
69
import net.minecraft.world.item.ItemStack;
70
import net.minecraft.world.item.component.AttackRange;
71
import net.minecraft.world.item.equipment.Equippable;
72
import net.minecraft.world.level.GameType;
73
import net.minecraft.world.level.Level;
74
import net.minecraft.world.level.block.Blocks;
75
import net.minecraft.world.level.block.state.BlockState;
76
import net.minecraft.world.level.border.WorldBorder;
77
import net.minecraft.world.phys.BlockHitResult;
78
import net.minecraft.world.phys.EntityHitResult;
79
import net.minecraft.world.phys.HitResult;
80
import net.minecraft.world.phys.HitResult.Type;
81
import net.minecraft.world.scores.DisplaySlot;
82
import net.minecraft.world.scores.Objective;
83
import net.minecraft.world.scores.PlayerScoreEntry;
84
import net.minecraft.world.scores.PlayerTeam;
85
import net.minecraft.world.scores.Scoreboard;
86
import net.minecraft.world.scores.TeamColor;
87
import org.jspecify.annotations.Nullable;
88
89
@Environment(EnvType.CLIENT)
90
public class Hud {
91
	private static final Identifier CROSSHAIR_SPRITE = Identifier.withDefaultNamespace("hud/crosshair");
92
	private static final Identifier CROSSHAIR_ATTACK_INDICATOR_FULL_SPRITE = Identifier.withDefaultNamespace("hud/crosshair_attack_indicator_full");
93
	private static final Identifier CROSSHAIR_ATTACK_INDICATOR_BACKGROUND_SPRITE = Identifier.withDefaultNamespace("hud/crosshair_attack_indicator_background");
94
	private static final Identifier CROSSHAIR_ATTACK_INDICATOR_PROGRESS_SPRITE = Identifier.withDefaultNamespace("hud/crosshair_attack_indicator_progress");
95
	private static final Identifier EFFECT_BACKGROUND_AMBIENT_SPRITE = Identifier.withDefaultNamespace("hud/effect_background_ambient");
96
	private static final Identifier EFFECT_BACKGROUND_SPRITE = Identifier.withDefaultNamespace("hud/effect_background");
97
	private static final Identifier HOTBAR_SPRITE = Identifier.withDefaultNamespace("hud/hotbar");
98
	private static final Identifier HOTBAR_SELECTION_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_selection");
99
	private static final Identifier HOTBAR_OFFHAND_LEFT_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_offhand_left");
100
	private static final Identifier HOTBAR_OFFHAND_RIGHT_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_offhand_right");
101
	private static final Identifier HOTBAR_ATTACK_INDICATOR_BACKGROUND_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_attack_indicator_background");
102
	private static final Identifier HOTBAR_ATTACK_INDICATOR_PROGRESS_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_attack_indicator_progress");
103
	private static final Identifier ARMOR_EMPTY_SPRITE = Identifier.withDefaultNamespace("hud/armor_empty");
104
	private static final Identifier ARMOR_HALF_SPRITE = Identifier.withDefaultNamespace("hud/armor_half");
105
	private static final Identifier ARMOR_FULL_SPRITE = Identifier.withDefaultNamespace("hud/armor_full");
106
	private static final Identifier FOOD_EMPTY_HUNGER_SPRITE = Identifier.withDefaultNamespace("hud/food_empty_hunger");
107
	private static final Identifier FOOD_HALF_HUNGER_SPRITE = Identifier.withDefaultNamespace("hud/food_half_hunger");
108
	private static final Identifier FOOD_FULL_HUNGER_SPRITE = Identifier.withDefaultNamespace("hud/food_full_hunger");
109
	private static final Identifier FOOD_EMPTY_SPRITE = Identifier.withDefaultNamespace("hud/food_empty");
110
	private static final Identifier FOOD_HALF_SPRITE = Identifier.withDefaultNamespace("hud/food_half");
111
	private static final Identifier FOOD_FULL_SPRITE = Identifier.withDefaultNamespace("hud/food_full");
112
	private static final Identifier AIR_SPRITE = Identifier.withDefaultNamespace("hud/air");
113
	private static final Identifier AIR_POPPING_SPRITE = Identifier.withDefaultNamespace("hud/air_bursting");
114
	private static final Identifier AIR_EMPTY_SPRITE = Identifier.withDefaultNamespace("hud/air_empty");
115
	private static final Identifier HEART_VEHICLE_CONTAINER_SPRITE = Identifier.withDefaultNamespace("hud/heart/vehicle_container");
116
	private static final Identifier HEART_VEHICLE_FULL_SPRITE = Identifier.withDefaultNamespace("hud/heart/vehicle_full");
117
	private static final Identifier HEART_VEHICLE_HALF_SPRITE = Identifier.withDefaultNamespace("hud/heart/vehicle_half");
118
	private static final Identifier VIGNETTE_LOCATION = Identifier.withDefaultNamespace("textures/misc/vignette.png");
119
	public static final Identifier NAUSEA_LOCATION = Identifier.withDefaultNamespace("textures/misc/nausea.png");
120
	private static final Identifier SPYGLASS_SCOPE_LOCATION = Identifier.withDefaultNamespace("textures/misc/spyglass_scope.png");
121
	private static final Identifier POWDER_SNOW_OUTLINE_LOCATION = Identifier.withDefaultNamespace("textures/misc/powder_snow_outline.png");
122
	private static final Comparator<PlayerScoreEntry> SCORE_DISPLAY_ORDER = Comparator.comparing(PlayerScoreEntry::value)
123
		.reversed()
124
		.thenComparing(PlayerScoreEntry::owner, String.CASE_INSENSITIVE_ORDER);
125
	private static final Component DEMO_EXPIRED_TEXT = Component.translatable("demo.demoExpired");
126
	private static final Component SAVING_TEXT = Component.translatable("menu.savingLevel");
127
	private static final float MIN_CROSSHAIR_ATTACK_SPEED = 5.0F;
128
	private static final int EXPERIENCE_BAR_DISPLAY_TICKS = 100;
129
	private static final int NUM_HEARTS_PER_ROW = 10;
130
	private static final int LINE_HEIGHT = 10;
131
	private static final String SPACER = ": ";
132
	private static final float PORTAL_OVERLAY_ALPHA_MIN = 0.2F;
133
	private static final int HEART_SIZE = 9;
134
	private static final int HEART_SEPARATION = 8;
135
	private static final int NUM_AIR_BUBBLES = 10;
136
	private static final int AIR_BUBBLE_SIZE = 9;
137
	private static final int AIR_BUBBLE_SEPERATION = 8;
138
	private static final int AIR_BUBBLE_POPPING_DURATION = 2;
139
	private static final int EMPTY_AIR_BUBBLE_DELAY_DURATION = 1;
140
	private static final float AIR_BUBBLE_POP_SOUND_VOLUME_BASE = 0.5F;
141
	private static final float AIR_BUBBLE_POP_SOUND_VOLUME_INCREMENT = 0.1F;
142
	private static final float AIR_BUBBLE_POP_SOUND_PITCH_BASE = 1.0F;
143
	private static final float AIR_BUBBLE_POP_SOUND_PITCH_INCREMENT = 0.1F;
144
	private static final int NUM_AIR_BUBBLE_POPPED_BEFORE_SOUND_VOLUME_INCREASE = 3;
145
	private static final int NUM_AIR_BUBBLE_POPPED_BEFORE_SOUND_PITCH_INCREASE = 5;
146
	private static final float AUTOSAVE_FADE_SPEED_FACTOR = 0.2F;
147
	private static final int SAVING_INDICATOR_WIDTH_PADDING_RIGHT = 5;
148
	private static final int SAVING_INDICATOR_HEIGHT_PADDING_BOTTOM = 5;
149
	private final RandomSource random = RandomSource.create();
150
	private final Minecraft minecraft;
151
	private final ChatComponent chat;
152
	private final WaypointStyleManager waypointStyles = new WaypointStyleManager();
153
	private boolean isHidden;
154
	private int tickCount;
155
	private @Nullable Component overlayMessageString;
156
	private int overlayMessageTime;
157
	private boolean animateOverlayMessageColor;
158
	public float vignetteBrightness = 1.0F;
159
	private int toolHighlightTimer;
160
	private ItemStack lastToolHighlight = ItemStack.EMPTY;
161
	private final DebugScreenOverlay debugOverlay;
162
	private final SubtitleOverlay subtitleOverlay;
163
	private final SpectatorGui spectatorGui;
164
	private final PlayerTabOverlay tabList;
165
	private final BossHealthOverlay bossOverlay;
166
	private int titleTime;
167
	private @Nullable Component title;
168
	private @Nullable Component subtitle;
169
	private int titleFadeInTime;
170
	private int titleStayTime;
171
	private int titleFadeOutTime;
172
	private int lastHealth;
173
	private int displayHealth;
174
	private long lastHealthTime;
175
	private long healthBlinkTime;
176
	private int lastBubblePopSoundPlayed;
177
	private @Nullable Runnable deferredSubtitles;
178
	private float autosaveIndicatorValue;
179
	private float lastAutosaveIndicatorValue;
180
	private Pair<Hud.ContextualInfo, ContextualBar> contextualInfoBar = Pair.of(Hud.ContextualInfo.EMPTY, ContextualBar.EMPTY);
181
	private final Map<Hud.ContextualInfo, Supplier<ContextualBar>> contextualInfoBars;
182
	private float scopeScale;
183
184
	public Hud(final Minecraft minecraft) {
185
		this.minecraft = minecraft;
186
		this.debugOverlay = new DebugScreenOverlay(minecraft);
187
		this.spectatorGui = new SpectatorGui(minecraft);
188
		this.chat = new ChatComponent(minecraft);
189
		this.tabList = new PlayerTabOverlay(minecraft, this);
190
		this.bossOverlay = new BossHealthOverlay(minecraft);
191
		this.subtitleOverlay = new SubtitleOverlay(minecraft);
192
		this.contextualInfoBars = ImmutableMap.of(
193
			Hud.ContextualInfo.EMPTY,
194
			() -> ContextualBar.EMPTY,
195
			Hud.ContextualInfo.EXPERIENCE,
196
			() -> new ExperienceBar(minecraft),
197
			Hud.ContextualInfo.LOCATOR,
198
			() -> new LocatorBar(minecraft),
199
			Hud.ContextualInfo.JUMPABLE_VEHICLE,
200
			() -> new JumpableVehicleBar(minecraft)
201
		);
202
		this.resetTitleTimes();
203
	}
204
205
	public void registerReloadListeners(final ReloadableResourceManager resourceManager) {
206
		resourceManager.registerReloadListener(this.waypointStyles);
207
	}
208
209
	public void toggle() {
210
		this.isHidden = !this.isHidden;
211
	}
212
213
	public boolean isHidden() {
214
		return this.isHidden;
215
	}
216
217
	public void resetTitleTimes() {
218
		this.titleFadeInTime = 10;
219
		this.titleStayTime = 70;
220
		this.titleFadeOutTime = 20;
221
	}
222
223
	public void extractRenderState(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
224
		this.minecraft.gameRenderer.gameRenderState().guiRenderState.isHudHidden = this.isHidden;
225
		if (!(this.minecraft.gui.screen() instanceof LevelLoadingScreen)) {
226
			if (!this.isHidden) {
227
				this.extractCameraOverlays(graphics, deltaTracker);
228
				this.extractCrosshair(graphics, deltaTracker);
229
				graphics.nextStratum();
230
				this.extractHotbarAndDecorations(graphics, deltaTracker);
231
				this.extractEffects(graphics, deltaTracker);
232
				this.extractBossOverlay(graphics, deltaTracker);
233
			}
234
235
			this.extractSleepOverlay(graphics, deltaTracker);
236
			if (!this.isHidden) {
237
				this.extractDemoOverlay(graphics, deltaTracker);
238
				this.extractScoreboardSidebar(graphics, deltaTracker);
239
				this.extractOverlayMessage(graphics, deltaTracker);
240
				this.extractTitle(graphics, deltaTracker);
241
				this.extractChat(graphics, deltaTracker);
242
				this.extractTabList(graphics, deltaTracker);
243
				this.extractSubtitleOverlay(graphics, this.minecraft.gui.screen() == null || this.minecraft.gui.screen().isInGameUi());
244
			} else if (this.minecraft.gui.screen() != null && this.minecraft.gui.screen().isInGameUi()) {
245
				this.extractSubtitleOverlay(graphics, true);
246
			}
247
		}
248
	}
249
250
	private void extractBossOverlay(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
251
		this.bossOverlay.extractRenderState(graphics);
252
	}
253
254
	public void extractDebugOverlay(final GuiGraphicsExtractor graphics) {
255
		this.debugOverlay.extractRenderState(graphics);
256
	}
257
258
	private void extractSubtitleOverlay(final GuiGraphicsExtractor graphics, final boolean deferRendering) {
259
		if (deferRendering) {
260
			this.deferredSubtitles = () -> this.subtitleOverlay.extractRenderState(graphics);
261
		} else {
262
			this.deferredSubtitles = null;
263
			this.subtitleOverlay.extractRenderState(graphics);
264
		}
265
	}
266
267
	public void extractDeferredSubtitles() {
268
		if (this.deferredSubtitles != null) {
269
			this.deferredSubtitles.run();
270
			this.deferredSubtitles = null;
271
		}
272
	}
273
274
	private void extractCameraOverlays(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
275
		if (this.minecraft.options.vignette().get()) {
276
			this.extractVignette(graphics, this.minecraft.getCameraEntity());
277
		}
278
279
		LocalPlayer player = this.minecraft.player;
280
		float gameTimeDeltaTicks = deltaTracker.getGameTimeDeltaTicks();
281
		this.scopeScale = Mth.lerp(0.5F * gameTimeDeltaTicks, this.scopeScale, 1.125F);
282
		if (this.minecraft.options.getCameraType().isFirstPerson()) {
283
			if (player.isScoping()) {
284
				this.extractSpyglassOverlay(graphics, this.scopeScale);
285
			} else {
286
				this.scopeScale = 0.5F;
287
288
				for (EquipmentSlot slot : EquipmentSlot.values()) {
289
					ItemStack item = player.getItemBySlot(slot);
290
					Equippable equippable = item.get(DataComponents.EQUIPPABLE);
291
					if (equippable != null && equippable.slot() == slot && equippable.cameraOverlay().isPresent()) {
292
						this.extractTextureOverlay(graphics, equippable.cameraOverlay().get().withPath(p -> "textures/" + p + ".png"), 1.0F);
293
					}
294
				}
295
			}
296
		}
297
298
		if (player.getTicksFrozen() > 0) {
299
			this.extractTextureOverlay(graphics, POWDER_SNOW_OUTLINE_LOCATION, player.getPercentFrozen());
300
		}
301
302
		float partialTicks = deltaTracker.getGameTimeDeltaPartialTick(false);
303
		float portalIntensity = Mth.lerp(partialTicks, player.oPortalEffectIntensity, player.portalEffectIntensity);
304
		float nauseaIntensity = player.getEffectBlendFactor(MobEffects.NAUSEA, partialTicks);
305
		if (portalIntensity > 0.0F) {
306
			this.extractPortalOverlay(graphics, portalIntensity);
307
		} else if (nauseaIntensity > 0.0F) {
308
			float screenEffectScale = this.minecraft.options.screenEffectScale().get().floatValue();
309
			if (screenEffectScale < 1.0F) {
310
				float overlayStrength = nauseaIntensity * (1.0F - screenEffectScale);
311
				this.extractConfusionOverlay(graphics, overlayStrength);
312
			}
313
		}
314
	}
315
316
	private void extractSleepOverlay(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
317
		if (this.minecraft.player.getSleepTimer() > 0) {
318
			Profiler.get().push("sleep");
319
			graphics.nextStratum();
320
			float sleepTimer = this.minecraft.player.getSleepTimer();
321
			float amount = sleepTimer / 100.0F;
322
			if (amount > 1.0F) {
323
				amount = 1.0F - (sleepTimer - 100.0F) / 10.0F;
324
			}
325
326
			int color = (int)(220.0F * amount) << 24 | 1052704;
327
			graphics.fill(0, 0, graphics.guiWidth(), graphics.guiHeight(), color);
328
			Profiler.get().pop();
329
		}
330
	}
331
332
	private void extractOverlayMessage(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
333
		Font font = this.getFont();
334
		if (this.overlayMessageString != null && this.overlayMessageTime > 0) {
335
			Profiler.get().push("overlayMessage");
336
			float t = this.overlayMessageTime - deltaTracker.getGameTimeDeltaPartialTick(false);
337
			int alpha = (int)(t * 255.0F / 20.0F);
338
			if (alpha > 255) {
339
				alpha = 255;
340
			}
341
342
			if (alpha > 0) {
343
				graphics.nextStratum();
344
				graphics.pose().pushMatrix();
345
				graphics.pose().translate(graphics.guiWidth() / 2, graphics.guiHeight() - 68);
346
				int color;
347
				if (this.animateOverlayMessageColor) {
348
					color = Mth.hsvToArgb(t / 50.0F, 0.7F, 0.6F, alpha);
349
				} else {
350
					color = ARGB.white(alpha);
351
				}
352
353
				int width = font.width(this.overlayMessageString);
354
				graphics.textWithBackdrop(font, this.overlayMessageString, -width / 2, -4, width, color);
355
				graphics.pose().popMatrix();
356
			}
357
358
			Profiler.get().pop();
359
		}
360
	}
361
362
	private void extractTitle(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
363
		if (this.title != null && this.titleTime > 0) {
364
			Font font = this.getFont();
365
			Profiler.get().push("titleAndSubtitle");
366
			float t = this.titleTime - deltaTracker.getGameTimeDeltaPartialTick(false);
367
			int alpha = 255;
368
			if (this.titleTime > this.titleFadeOutTime + this.titleStayTime) {
369
				float time = this.titleFadeInTime + this.titleStayTime + this.titleFadeOutTime - t;
370
				alpha = (int)(time * 255.0F / this.titleFadeInTime);
371
			}
372
373
			if (this.titleTime <= this.titleFadeOutTime) {
374
				alpha = (int)(t * 255.0F / this.titleFadeOutTime);
375
			}
376
377
			alpha = Mth.clamp(alpha, 0, 255);
378
			if (alpha > 0) {
379
				graphics.nextStratum();
380
				graphics.pose().pushMatrix();
381
				graphics.pose().translate(graphics.guiWidth() / 2, graphics.guiHeight() / 2);
382
				graphics.pose().pushMatrix();
383
				graphics.pose().scale(4.0F, 4.0F);
384
				int titleWidth = font.width(this.title);
385
				int textColor = ARGB.white(alpha);
386
				graphics.textWithBackdrop(font, this.title, -titleWidth / 2, -10, titleWidth, textColor);
387
				graphics.pose().popMatrix();
388
				if (this.subtitle != null) {
389
					graphics.pose().pushMatrix();
390
					graphics.pose().scale(2.0F, 2.0F);
391
					int subtitleWidth = font.width(this.subtitle);
392
					graphics.textWithBackdrop(font, this.subtitle, -subtitleWidth / 2, 5, subtitleWidth, textColor);
393
					graphics.pose().popMatrix();
394
				}
395
396
				graphics.pose().popMatrix();
397
			}
398
399
			Profiler.get().pop();
400
		}
401
	}
402
403
	private void extractChat(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
404
		if (this.minecraft.player != null && !this.chat.isChatFocused()) {
405
			Window window = this.minecraft.getWindow();
406
			int mouseX = Mth.floor(this.minecraft.mouseHandler.getScaledXPos(window));
407
			int mouseY = Mth.floor(this.minecraft.mouseHandler.getScaledYPos(window));
408
			graphics.nextStratum();
409
			this.chat.extractRenderState(graphics, this.getFont(), this.tickCount, mouseX, mouseY, ChatComponent.DisplayMode.BACKGROUND, false);
410
		}
411
	}
412
413
	private void extractScoreboardSidebar(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
414
		Scoreboard scoreboard = this.minecraft.level.getScoreboard();
415
		Objective teamObjective = null;
416
		PlayerTeam playerTeam = scoreboard.getPlayersTeam(this.minecraft.player.getScoreboardName());
417
		if (playerTeam != null) {
418
			Optional<TeamColor> teamColor = playerTeam.getColor();
419
			if (teamColor.isPresent()) {
420
				teamObjective = scoreboard.getDisplayObjective(teamColor.get().displaySlot());
421
			}
422
		}
423
424
		Objective displayObjective = teamObjective != null ? teamObjective : scoreboard.getDisplayObjective(DisplaySlot.SIDEBAR);
425
		if (displayObjective != null) {
426
			graphics.nextStratum();
427
			this.displayScoreboardSidebar(graphics, displayObjective);
428
		}
429
	}
430
431
	private void extractTabList(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
432
		Scoreboard scoreboard = this.minecraft.level.getScoreboard();
433
		Objective displayObjective = scoreboard.getDisplayObjective(DisplaySlot.LIST);
434
		if (!this.minecraft.options.keyPlayerList.isDown()
435
			|| this.minecraft.isLocalServer() && this.minecraft.player.connection.getListedOnlinePlayers().size() <= 1 && displayObjective == null) {
436
			this.tabList.setVisible(false);
437
		} else {
438
			this.tabList.setVisible(true);
439
			graphics.nextStratum();
440
			this.tabList.extractRenderState(graphics, graphics.guiWidth(), scoreboard, displayObjective);
441
		}
442
	}
443
444
	private void extractCrosshair(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
445
		Options options = this.minecraft.options;
446
		if (options.getCameraType().isFirstPerson()) {
447
			if (this.minecraft.gameMode.getPlayerMode() != GameType.SPECTATOR || this.canRenderCrosshairForSpectator(this.minecraft.hitResult)) {
448
				if (!this.minecraft.debugEntries.isCurrentlyEnabled(DebugScreenEntries.THREE_DIMENSIONAL_CROSSHAIR)) {
449
					graphics.nextStratum();
450
					int size = 15;
451
					graphics.blitSprite(RenderPipelines.CROSSHAIR, CROSSHAIR_SPRITE, (graphics.guiWidth() - 15) / 2, (graphics.guiHeight() - 15) / 2, 15, 15);
452
					if (this.minecraft.options.attackIndicator().get() == AttackIndicatorStatus.CROSSHAIR) {
453
						float attackStrengthScale = this.minecraft.player.getAttackStrengthScale(0.0F);
454
						boolean renderMaxAttackIndicator = false;
455
						if (this.minecraft.crosshairPickEntity != null && this.minecraft.crosshairPickEntity instanceof LivingEntity && attackStrengthScale >= 1.0F) {
456
							renderMaxAttackIndicator = this.minecraft.player.getCurrentItemAttackStrengthDelay() > 5.0F;
457
							renderMaxAttackIndicator &= this.minecraft.crosshairPickEntity.isAlive();
458
							AttackRange attackRange = this.minecraft.player.getActiveItem().get(DataComponents.ATTACK_RANGE);
459
							renderMaxAttackIndicator &= attackRange == null || attackRange.isInRange(this.minecraft.player, this.minecraft.hitResult.getLocation());
460
						}
461
462
						int y = graphics.guiHeight() / 2 - 7 + 16;
463
						int x = graphics.guiWidth() / 2 - 8;
464
						if (renderMaxAttackIndicator) {
465
							graphics.blitSprite(RenderPipelines.CROSSHAIR, CROSSHAIR_ATTACK_INDICATOR_FULL_SPRITE, x, y, 16, 16);
466
						} else if (attackStrengthScale < 1.0F) {
467
							int progress = (int)(attackStrengthScale * 17.0F);
468
							graphics.blitSprite(RenderPipelines.CROSSHAIR, CROSSHAIR_ATTACK_INDICATOR_BACKGROUND_SPRITE, x, y, 16, 4);
469
							graphics.blitSprite(RenderPipelines.CROSSHAIR, CROSSHAIR_ATTACK_INDICATOR_PROGRESS_SPRITE, 16, 4, 0, 0, x, y, progress, 4);
470
						}
471
					}
472
				}
473
			}
474
		}
475
	}
476
477
	private boolean canRenderCrosshairForSpectator(final @Nullable HitResult hitResult) {
478
		if (hitResult == null) {
479
			return false;
480
		} else if (hitResult.getType() == Type.ENTITY) {
481
			return ((EntityHitResult)hitResult).getEntity() instanceof MenuProvider;
482
		} else if (hitResult.getType() == Type.BLOCK) {
483
			BlockHitResult blockHitResult = (BlockHitResult)hitResult;
484
			BlockPos pos = blockHitResult.getBlockPos();
485
			Level level = this.minecraft.level;
486
			BlockState state = level.getBlockState(pos);
487
			return state.showAsInteractableInSpectatorMode(level, pos, blockHitResult);
488
		} else {
489
			return false;
490
		}
491
	}
492
493
	private void extractEffects(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
494
		Collection<MobEffectInstance> activeEffects = this.minecraft.player.getActiveEffects();
495
		if (!activeEffects.isEmpty() && (this.minecraft.gui.screen() == null || !this.minecraft.gui.screen().showsActiveEffects())) {
496
			int beneficialCount = 0;
497
			int harmfulCount = 0;
498
499
			for (MobEffectInstance instance : Ordering.natural().reverse().sortedCopy(activeEffects)) {
500
				Holder<MobEffect> effect = instance.getEffect();
501
				if (instance.showIcon()) {
502
					int x = graphics.guiWidth();
503
					int y = 1;
504
					if (this.minecraft.isDemo()) {
505
						y += 15;
506
					}
507
508
					if (effect.value().isBeneficial()) {
509
						beneficialCount++;
510
						x -= 25 * beneficialCount;
511
					} else {
512
						harmfulCount++;
513
						x -= 25 * harmfulCount;
514
						y += 26;
515
					}
516
517
					float alpha = 1.0F;
518
					if (instance.isAmbient()) {
519
						graphics.blitSprite(RenderPipelines.GUI_TEXTURED, EFFECT_BACKGROUND_AMBIENT_SPRITE, x, y, 24, 24);
520
					} else {
521
						graphics.blitSprite(RenderPipelines.GUI_TEXTURED, EFFECT_BACKGROUND_SPRITE, x, y, 24, 24);
522
						if (instance.endsWithin(200)) {
523
							int remainingDuration = instance.getDuration();
524
							int usedSeconds = 10 - remainingDuration / 20;
525
							alpha = Mth.clamp(remainingDuration / 10.0F / 5.0F * 0.5F, 0.0F, 0.5F)
526
								+ Mth.cos(remainingDuration * (float) Math.PI / 5.0F) * Mth.clamp(usedSeconds / 10.0F * 0.25F, 0.0F, 0.25F);
527
							alpha = Mth.clamp(alpha, 0.0F, 1.0F);
528
						}
529
					}
530
531
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, getMobEffectSprite(effect), x + 3, y + 3, 18, 18, ARGB.white(alpha));
532
				}
533
			}
534
		}
535
	}
536
537
	public static Identifier getMobEffectSprite(final Holder<MobEffect> effect) {
538
		return effect.unwrapKey().map(ResourceKey::identifier).map(id -> id.withPrefix("mob_effect/")).orElseGet(MissingTextureAtlasSprite::getLocation);
539
	}
540
541
	private void extractHotbarAndDecorations(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
542
		if (this.minecraft.gameMode.getPlayerMode() == GameType.SPECTATOR) {
543
			this.spectatorGui.extractHotbar(graphics);
544
		} else {
545
			this.extractItemHotbar(graphics, deltaTracker);
546
		}
547
548
		if (this.minecraft.gameMode.canHurtPlayer()) {
549
			this.extractPlayerHealth(graphics);
550
		}
551
552
		this.extractVehicleHealth(graphics);
553
		Hud.ContextualInfo nextContextualInfo = this.nextContextualInfoState();
554
		if (nextContextualInfo != this.contextualInfoBar.getFirst()) {
555
			this.contextualInfoBar = Pair.of(nextContextualInfo, this.contextualInfoBars.get(nextContextualInfo).get());
556
		}
557
558
		this.contextualInfoBar.getSecond().extractBackground(graphics, deltaTracker);
559
		if (this.minecraft.gameMode.hasExperience() && this.minecraft.player.experienceLevel > 0) {
560
			ContextualBar.extractExperienceLevel(graphics, this.minecraft.font, this.minecraft.player.experienceLevel);
561
		}
562
563
		this.contextualInfoBar.getSecond().extractRenderState(graphics, deltaTracker);
564
		if (this.minecraft.gameMode.getPlayerMode() != GameType.SPECTATOR) {
565
			this.extractSelectedItemName(graphics);
566
		} else if (this.minecraft.player.isSpectator()) {
567
			this.spectatorGui.extractAction(graphics);
568
		}
569
	}
570
571
	private void extractItemHotbar(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
572
		Player player = this.getCameraPlayer();
573
		if (player != null) {
574
			ItemStack offhand = player.getOffhandItem();
575
			HumanoidArm offhandArm = player.getMainArm().getOpposite();
576
			int screenCenter = graphics.guiWidth() / 2;
577
			int hotbarWidth = 182;
578
			int halfHotbar = 91;
579
			graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SPRITE, screenCenter - 91, graphics.guiHeight() - 22, 182, 22);
580
			graphics.blitSprite(
581
				RenderPipelines.GUI_TEXTURED,
582
				HOTBAR_SELECTION_SPRITE,
583
				screenCenter - 91 - 1 + player.getInventory().getSelectedSlot() * 20,
584
				graphics.guiHeight() - 22 - 1,
585
				24,
586
				23
587
			);
588
			if (!offhand.isEmpty()) {
589
				if (offhandArm == HumanoidArm.LEFT) {
590
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_OFFHAND_LEFT_SPRITE, screenCenter - 91 - 29, graphics.guiHeight() - 23, 29, 24);
591
				} else {
592
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_OFFHAND_RIGHT_SPRITE, screenCenter + 91, graphics.guiHeight() - 23, 29, 24);
593
				}
594
			}
595
596
			int seed = 1;
597
598
			for (int i = 0; i < 9; i++) {
599
				int x = screenCenter - 90 + i * 20 + 2;
600
				int y = graphics.guiHeight() - 16 - 3;
601
				this.extractSlot(graphics, x, y, deltaTracker, player, player.getInventory().getItem(i), seed++);
602
			}
603
604
			if (!offhand.isEmpty()) {
605
				int y = graphics.guiHeight() - 16 - 3;
606
				if (offhandArm == HumanoidArm.LEFT) {
607
					this.extractSlot(graphics, screenCenter - 91 - 26, y, deltaTracker, player, offhand, seed++);
608
				} else {
609
					this.extractSlot(graphics, screenCenter + 91 + 10, y, deltaTracker, player, offhand, seed++);
610
				}
611
			}
612
613
			if (this.minecraft.options.attackIndicator().get() == AttackIndicatorStatus.HOTBAR) {
614
				float attackStrengthScale = this.minecraft.player.getAttackStrengthScale(0.0F);
615
				if (attackStrengthScale < 1.0F) {
616
					int y = graphics.guiHeight() - 20;
617
					int x = screenCenter + 91 + 6;
618
					if (offhandArm == HumanoidArm.RIGHT) {
619
						x = screenCenter - 91 - 22;
620
					}
621
622
					int progress = (int)(attackStrengthScale * 19.0F);
623
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_ATTACK_INDICATOR_BACKGROUND_SPRITE, x, y, 18, 18);
624
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_ATTACK_INDICATOR_PROGRESS_SPRITE, 18, 18, 0, 18 - progress, x, y + 18 - progress, 18, progress);
625
				}
626
			}
627
		}
628
	}
629
630
	private void extractSelectedItemName(final GuiGraphicsExtractor graphics) {
631
		if (this.toolHighlightTimer > 0 && !this.lastToolHighlight.isEmpty()) {
632
			MutableComponent str = Component.empty().append(this.lastToolHighlight.getHoverName()).withStyle(this.lastToolHighlight.getRarity().color());
633
			if (this.lastToolHighlight.has(DataComponents.CUSTOM_NAME)) {
634
				str.withStyle(ChatFormatting.ITALIC);
635
			}
636
637
			int strWidth = this.getFont().width(str);
638
			int x = (graphics.guiWidth() - strWidth) / 2;
639
			int y = graphics.guiHeight() - 59;
640
			if (!this.minecraft.gameMode.canHurtPlayer()) {
641
				y += 14;
642
			}
643
644
			int alpha = (int)(this.toolHighlightTimer * 256.0F / 10.0F);
645
			if (alpha > 255) {
646
				alpha = 255;
647
			}
648
649
			if (alpha > 0) {
650
				graphics.textWithBackdrop(this.getFont(), str, x, y, strWidth, ARGB.white(alpha));
651
			}
652
		}
653
	}
654
655
	private void extractDemoOverlay(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
656
		if (this.minecraft.isDemo()) {
657
			Profiler.get().push("demo");
658
			graphics.nextStratum();
659
			Component msg;
660
			if (this.minecraft.level.getGameTime() >= 120500L) {
661
				msg = DEMO_EXPIRED_TEXT;
662
			} else {
663
				msg = Component.translatable(
664
					"demo.remainingTime",
665
					StringUtil.formatTickDuration((int)(120500L - this.minecraft.level.getGameTime()), this.minecraft.level.tickRateManager().tickrate())
666
				);
667
			}
668
669
			int width = this.getFont().width(msg);
670
			int textX = graphics.guiWidth() - width - 10;
671
			int textY = 5;
672
			graphics.textWithBackdrop(this.getFont(), msg, textX, 5, width, -1);
673
			Profiler.get().pop();
674
		}
675
	}
676
677
	private void displayScoreboardSidebar(final GuiGraphicsExtractor graphics, final Objective objective) {
678
		Scoreboard scoreboard = objective.getScoreboard();
679
		NumberFormat objectiveScoreFormat = objective.numberFormatOrDefault(StyledFormat.SIDEBAR_DEFAULT);
680
681
		@Environment(EnvType.CLIENT)
682
		record DisplayEntry(Component name, Component score, int scoreWidth) {
683
		}
684
685
		DisplayEntry[] entriesToDisplay = scoreboard.listPlayerScores(objective)
686
			.stream()
687
			.filter(input -> !input.isHidden())
688
			.sorted(SCORE_DISPLAY_ORDER)
689
			.limit(15L)
690
			.map(score -> {
691
				PlayerTeam team = scoreboard.getPlayersTeam(score.owner());
692
				Component ownerName = score.ownerName();
693
				Component name = PlayerTeam.formatNameForTeam(team, ownerName);
694
				Component scoreString = score.formatValue(objectiveScoreFormat);
695
				int scoreWidth = this.getFont().width(scoreString);
696
				return new DisplayEntry(name, scoreString, scoreWidth);
697
			})
698
			.toArray(DisplayEntry[]::new);
699
		Component objectiveDisplayName = objective.getDisplayName();
700
		int objectiveDisplayNameWidth = this.getFont().width(objectiveDisplayName);
701
		int biggestWidth = objectiveDisplayNameWidth;
702
		int spacerWidth = this.getFont().width(": ");
703
704
		for (DisplayEntry entry : entriesToDisplay) {
705
			biggestWidth = Math.max(biggestWidth, this.getFont().width(entry.name) + (entry.scoreWidth > 0 ? spacerWidth + entry.scoreWidth : 0));
706
		}
707
708
		int width = biggestWidth;
709
		int entriesCount = entriesToDisplay.length;
710
		int height = entriesCount * 9;
711
		int bottom = graphics.guiHeight() / 2 + height / 3;
712
		int rightPadding = 3;
713
		int left = graphics.guiWidth() - width - 3;
714
		int right = graphics.guiWidth() - 3 + 2;
715
		int backgroundColor = this.minecraft.options.getBackgroundColor(0.3F);
716
		int headerBackgroundColor = this.minecraft.options.getBackgroundColor(0.4F);
717
		int headerY = bottom - entriesCount * 9;
718
		graphics.fill(left - 2, headerY - 9 - 1, right, headerY - 1, headerBackgroundColor);
719
		graphics.fill(left - 2, headerY - 1, right, bottom, backgroundColor);
720
		graphics.text(this.getFont(), objectiveDisplayName, left + width / 2 - objectiveDisplayNameWidth / 2, headerY - 9, -1, false);
721
722
		for (int i = 0; i < entriesCount; i++) {
723
			DisplayEntry e = entriesToDisplay[i];
724
			int y = bottom - (entriesCount - i) * 9;
725
			graphics.text(this.getFont(), e.name, left, y, -1, false);
726
			graphics.text(this.getFont(), e.score, right - e.scoreWidth, y, -1, false);
727
		}
728
	}
729
730
	private @Nullable Player getCameraPlayer() {
731
		return this.minecraft.getCameraEntity() instanceof Player player ? player : null;
732
	}
733
734
	private @Nullable LivingEntity getPlayerVehicleWithHealth() {
735
		Player player = this.getCameraPlayer();
736
		if (player != null) {
737
			Entity vehicle = player.getVehicle();
738
			if (vehicle == null) {
739
				return null;
740
			}
741
742
			if (vehicle instanceof LivingEntity livingEntity) {
743
				return livingEntity;
744
			}
745
		}
746
747
		return null;
748
	}
749
750
	private int getVehicleMaxHearts(final @Nullable LivingEntity vehicle) {
751
		if (vehicle != null && vehicle.showVehicleHealth()) {
752
			float maxVehicleHealth = vehicle.getMaxHealth();
753
			int hearts = (int)(maxVehicleHealth + 0.5F) / 2;
754
			if (hearts > 30) {
755
				hearts = 30;
756
			}
757
758
			return hearts;
759
		} else {
760
			return 0;
761
		}
762
	}
763
764
	private int getVisibleVehicleHeartRows(final int hearts) {
765
		return (int)Math.ceil(hearts / 10.0);
766
	}
767
768
	private void extractPlayerHealth(final GuiGraphicsExtractor graphics) {
769
		Player player = this.getCameraPlayer();
770
		if (player != null) {
771
			int currentHealth = Mth.ceil(player.getHealth());
772
			boolean blink = this.healthBlinkTime > this.tickCount && (this.healthBlinkTime - this.tickCount) / 3L % 2L == 1L;
773
			long timeMillis = Util.getMillis();
774
			if (currentHealth < this.lastHealth && player.damageCooldownTime > 0) {
775
				this.lastHealthTime = timeMillis;
776
				this.healthBlinkTime = this.tickCount + 20;
777
			} else if (currentHealth > this.lastHealth && player.damageCooldownTime > 0) {
778
				this.lastHealthTime = timeMillis;
779
				this.healthBlinkTime = this.tickCount + 10;
780
			}
781
782
			if (timeMillis - this.lastHealthTime > 1000L) {
783
				this.displayHealth = currentHealth;
784
				this.lastHealthTime = timeMillis;
785
			}
786
787
			this.lastHealth = currentHealth;
788
			int oldHealth = this.displayHealth;
789
			this.random.setSeed(this.tickCount * 312871);
790
			int xLeft = graphics.guiWidth() / 2 - 91;
791
			int xRight = graphics.guiWidth() / 2 + 91;
792
			int yLineBase = graphics.guiHeight() - 39;
793
			float maxHealth = Math.max((float)player.getAttributeValue(Attributes.MAX_HEALTH), Math.max(oldHealth, currentHealth));
794
			int totalAbsorption = Mth.ceil(player.getAbsorptionAmount());
795
			int numHealthRows = Mth.ceil((maxHealth + totalAbsorption) / 2.0F / 10.0F);
796
			int healthRowHeight = Math.max(10 - (numHealthRows - 2), 3);
797
			int yLineAir = yLineBase - 10;
798
			int heartOffsetIndex = -1;
799
			if (player.hasEffect(MobEffects.REGENERATION)) {
800
				heartOffsetIndex = this.tickCount % Mth.ceil(maxHealth + 5.0F);
801
			}
802
803
			Profiler.get().push("armor");
804
			extractArmor(graphics, player, yLineBase, numHealthRows, healthRowHeight, xLeft);
805
			Profiler.get().popPush("health");
806
			this.extractHearts(graphics, player, xLeft, yLineBase, healthRowHeight, heartOffsetIndex, maxHealth, currentHealth, oldHealth, totalAbsorption, blink);
807
			LivingEntity vehicleWithHearts = this.getPlayerVehicleWithHealth();
808
			int vehicleHearts = this.getVehicleMaxHearts(vehicleWithHearts);
809
			if (vehicleHearts == 0) {
810
				Profiler.get().popPush("food");
811
				this.extractFood(graphics, player, yLineBase, xRight);
812
				yLineAir -= 10;
813
			}
814
815
			Profiler.get().popPush("air");
816
			this.extractAirBubbles(graphics, player, vehicleHearts, yLineAir, xRight);
817
			Profiler.get().pop();
818
		}
819
	}
820
821
	private static void extractArmor(
822
		final GuiGraphicsExtractor graphics, final Player player, final int yLineBase, final int numHealthRows, final int healthRowHeight, final int xLeft
823
	) {
824
		int armor = player.getArmorValue();
825
		if (armor > 0) {
826
			int yLineArmor = yLineBase - (numHealthRows - 1) * healthRowHeight - 10;
827
828
			for (int i = 0; i < 10; i++) {
829
				int xo = xLeft + i * 8;
830
				if (i * 2 + 1 < armor) {
831
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, ARMOR_FULL_SPRITE, xo, yLineArmor, 9, 9);
832
				}
833
834
				if (i * 2 + 1 == armor) {
835
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, ARMOR_HALF_SPRITE, xo, yLineArmor, 9, 9);
836
				}
837
838
				if (i * 2 + 1 > armor) {
839
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, ARMOR_EMPTY_SPRITE, xo, yLineArmor, 9, 9);
840
				}
841
			}
842
		}
843
	}
844
845
	private void extractHearts(
846
		final GuiGraphicsExtractor graphics,
847
		final Player player,
848
		final int xLeft,
849
		final int yLineBase,
850
		final int healthRowHeight,
851
		final int heartOffsetIndex,
852
		final float maxHealth,
853
		final int currentHealth,
854
		final int oldHealth,
855
		final int absorption,
856
		final boolean blink
857
	) {
858
		Hud.HeartType type = Hud.HeartType.forPlayer(player);
859
		boolean isHardcore = player.level().getLevelData().isHardcore();
860
		int healthContainerCount = Mth.ceil(maxHealth / 2.0);
861
		int absorptionContainerCount = Mth.ceil(absorption / 2.0);
862
		int maxHealthHalvesCount = healthContainerCount * 2;
863
864
		for (int containerIndex = healthContainerCount + absorptionContainerCount - 1; containerIndex >= 0; containerIndex--) {
865
			int row = containerIndex / 10;
866
			int column = containerIndex % 10;
867
			int xo = xLeft + column * 8;
868
			int yo = yLineBase - row * healthRowHeight;
869
			if (currentHealth + absorption <= 4) {
870
				yo += this.random.nextInt(2);
871
			}
872
873
			if (containerIndex < healthContainerCount && containerIndex == heartOffsetIndex) {
874
				yo -= 2;
875
			}
876
877
			this.extractHeart(graphics, Hud.HeartType.CONTAINER, xo, yo, isHardcore, blink, false);
878
			int halves = containerIndex * 2;
879
			boolean isAbsorptionHeart = containerIndex >= healthContainerCount;
880
			if (isAbsorptionHeart) {
881
				int absorptionHalves = halves - maxHealthHalvesCount;
882
				if (absorptionHalves < absorption) {
883
					boolean halfHeart = absorptionHalves + 1 == absorption;
884
					this.extractHeart(graphics, type == Hud.HeartType.WITHERED ? type : Hud.HeartType.ABSORBING, xo, yo, isHardcore, false, halfHeart);
885
				}
886
			}
887
888
			if (blink && halves < oldHealth) {
889
				boolean halfHeart = halves + 1 == oldHealth;
890
				this.extractHeart(graphics, type, xo, yo, isHardcore, true, halfHeart);
891
			}
892
893
			if (halves < currentHealth) {
894
				boolean halfHeart = halves + 1 == currentHealth;
895
				this.extractHeart(graphics, type, xo, yo, isHardcore, false, halfHeart);
896
			}
897
		}
898
	}
899
900
	private void extractHeart(
901
		final GuiGraphicsExtractor graphics, final Hud.HeartType type, final int xo, final int yo, final boolean isHardcore, final boolean blinks, final boolean half
902
	) {
903
		graphics.blitSprite(RenderPipelines.GUI_TEXTURED, type.getSprite(isHardcore, half, blinks), xo, yo, 9, 9);
904
	}
905
906
	private void extractAirBubbles(final GuiGraphicsExtractor graphics, final Player player, final int vehicleHearts, int yLineAir, final int xRight) {
907
		int maxAirSupplyTicks = player.getMaxAirSupply();
908
		int currentAirSupplyTicks = Math.clamp(player.getAirSupply(), 0, maxAirSupplyTicks);
909
		boolean isUnderWater = player.isEyeInFluid(FluidTags.WATER);
910
		if (isUnderWater || currentAirSupplyTicks < maxAirSupplyTicks) {
911
			yLineAir = this.getAirBubbleYLine(vehicleHearts, yLineAir);
912
			int fullAirBubbles = getCurrentAirSupplyBubble(currentAirSupplyTicks, maxAirSupplyTicks, -2);
913
			int poppingAirBubblePosition = getCurrentAirSupplyBubble(currentAirSupplyTicks, maxAirSupplyTicks, 0);
914
			int emptyAirBubbles = 10
915
				- getCurrentAirSupplyBubble(currentAirSupplyTicks, maxAirSupplyTicks, getEmptyBubbleDelayDuration(currentAirSupplyTicks, isUnderWater));
916
			boolean isPoppingBubble = fullAirBubbles != poppingAirBubblePosition;
917
			if (!isUnderWater) {
918
				this.lastBubblePopSoundPlayed = 0;
919
			}
920
921
			for (int airBubble = 1; airBubble <= 10; airBubble++) {
922
				int airBubbleXPos = xRight - (airBubble - 1) * 8 - 9;
923
				if (airBubble <= fullAirBubbles) {
924
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, AIR_SPRITE, airBubbleXPos, yLineAir, 9, 9);
925
				} else if (isPoppingBubble && airBubble == poppingAirBubblePosition && isUnderWater) {
926
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, AIR_POPPING_SPRITE, airBubbleXPos, yLineAir, 9, 9);
927
					this.playAirBubblePoppedSound(airBubble, player, emptyAirBubbles);
928
				} else if (airBubble > 10 - emptyAirBubbles) {
929
					int wobbleYOffset = emptyAirBubbles == 10 && this.tickCount % 2 == 0 ? this.random.nextInt(2) : 0;
930
					graphics.blitSprite(RenderPipelines.GUI_TEXTURED, AIR_EMPTY_SPRITE, airBubbleXPos, yLineAir + wobbleYOffset, 9, 9);
931
				}
932
			}
933
		}
934
	}
935
936
	private int getAirBubbleYLine(final int vehicleHearts, int yLineAir) {
937
		int rowOffset = this.getVisibleVehicleHeartRows(vehicleHearts) - 1;
938
		return yLineAir - rowOffset * 10;
939
	}
940
941
	private static int getCurrentAirSupplyBubble(final int currentAirSupplyTicks, final int maxAirSupplyTicks, final int tickOffset) {
942
		return Mth.ceil((float)((currentAirSupplyTicks + tickOffset) * 10) / maxAirSupplyTicks);
943
	}
944
945
	private static int getEmptyBubbleDelayDuration(final int currentAirSupplyTicks, final boolean isUnderWater) {
946
		return currentAirSupplyTicks != 0 && isUnderWater ? 1 : 0;
947
	}
948
949
	private void playAirBubblePoppedSound(final int bubble, final Player player, final int emptyAirBubbles) {
950
		if (this.lastBubblePopSoundPlayed != bubble) {
951
			float soundVolume = 0.5F + 0.1F * Math.max(0, emptyAirBubbles - 3 + 1);
952
			float soundPitch = 1.0F + 0.1F * Math.max(0, emptyAirBubbles - 5 + 1);
953
			player.playSound(SoundEvents.BUBBLE_POP, soundVolume, soundPitch);
954
			this.lastBubblePopSoundPlayed = bubble;
955
		}
956
	}
957
958
	private void extractFood(final GuiGraphicsExtractor graphics, final Player player, final int yLineBase, final int xRight) {
959
		FoodData foodData = player.getFoodData();
960
		int food = foodData.getFoodLevel();
961
962
		for (int i = 0; i < 10; i++) {
963
			int yo = yLineBase;
964
			Identifier empty;
965
			Identifier half;
966
			Identifier full;
967
			if (player.hasEffect(MobEffects.HUNGER)) {
968
				empty = FOOD_EMPTY_HUNGER_SPRITE;
969
				half = FOOD_HALF_HUNGER_SPRITE;
970
				full = FOOD_FULL_HUNGER_SPRITE;
971
			} else {
972
				empty = FOOD_EMPTY_SPRITE;
973
				half = FOOD_HALF_SPRITE;
974
				full = FOOD_FULL_SPRITE;
975
			}
976
977
			if (player.getFoodData().getSaturationLevel() <= 0.0F && this.tickCount % (food * 3 + 1) == 0) {
978
				yo += this.random.nextInt(3) - 1;
979
			}
980
981
			int xo = xRight - i * 8 - 9;
982
			graphics.blitSprite(RenderPipelines.GUI_TEXTURED, empty, xo, yo, 9, 9);
983
			if (i * 2 + 1 < food) {
984
				graphics.blitSprite(RenderPipelines.GUI_TEXTURED, full, xo, yo, 9, 9);
985
			}
986
987
			if (i * 2 + 1 == food) {
988
				graphics.blitSprite(RenderPipelines.GUI_TEXTURED, half, xo, yo, 9, 9);
989
			}
990
		}
991
	}
992
993
	private void extractVehicleHealth(final GuiGraphicsExtractor graphics) {
994
		LivingEntity vehicleWithHearts = this.getPlayerVehicleWithHealth();
995
		if (vehicleWithHearts != null) {
996
			int hearts = this.getVehicleMaxHearts(vehicleWithHearts);
997
			if (hearts != 0) {
998
				int currentHealth = (int)Math.ceil(vehicleWithHearts.getHealth());
999
				Profiler.get().popPush("mountHealth");
1000
				int yLine1 = graphics.guiHeight() - 39;
1001
				int xRight = graphics.guiWidth() / 2 + 91;
1002
				int yo = yLine1;
1003
1004
				for (int baseHealth = 0; hearts > 0; baseHealth += 20) {
1005
					int rowHearts = Math.min(hearts, 10);
1006
					hearts -= rowHearts;
1007
1008
					for (int i = 0; i < rowHearts; i++) {
1009
						int xo = xRight - i * 8 - 9;
1010
						graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HEART_VEHICLE_CONTAINER_SPRITE, xo, yo, 9, 9);
1011
						if (i * 2 + 1 + baseHealth < currentHealth) {
1012
							graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HEART_VEHICLE_FULL_SPRITE, xo, yo, 9, 9);
1013
						}
1014
1015
						if (i * 2 + 1 + baseHealth == currentHealth) {
1016
							graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HEART_VEHICLE_HALF_SPRITE, xo, yo, 9, 9);
1017
						}
1018
					}
1019
1020
					yo -= 10;
1021
				}
1022
			}
1023
		}
1024
	}
1025
1026
	private void extractTextureOverlay(final GuiGraphicsExtractor graphics, final Identifier texture, final float alpha) {
1027
		int color = ARGB.white(alpha);
1028
		graphics.blit(
1029
			RenderPipelines.GUI_TEXTURED, texture, 0, 0, 0.0F, 0.0F, graphics.guiWidth(), graphics.guiHeight(), graphics.guiWidth(), graphics.guiHeight(), color
1030
		);
1031
	}
1032
1033
	private void extractSpyglassOverlay(final GuiGraphicsExtractor graphics, final float scale) {
1034
		float srcWidth = Math.min(graphics.guiWidth(), graphics.guiHeight());
1035
		float srcHeight = srcWidth;
1036
		float ratio = Math.min(graphics.guiWidth() / srcWidth, graphics.guiHeight() / srcHeight) * scale;
1037
		int width = Mth.floor(srcWidth * ratio);
1038
		int height = Mth.floor(srcHeight * ratio);
1039
		int left = (graphics.guiWidth() - width) / 2;
1040
		int top = (graphics.guiHeight() - height) / 2;
1041
		int right = left + width;
1042
		int bottom = top + height;
1043
		graphics.blit(RenderPipelines.GUI_TEXTURED, SPYGLASS_SCOPE_LOCATION, left, top, 0.0F, 0.0F, width, height, width, height);
1044
		graphics.fill(RenderPipelines.GUI, 0, bottom, graphics.guiWidth(), graphics.guiHeight(), -16777216);
1045
		graphics.fill(RenderPipelines.GUI, 0, 0, graphics.guiWidth(), top, -16777216);
1046
		graphics.fill(RenderPipelines.GUI, 0, top, left, bottom, -16777216);
1047
		graphics.fill(RenderPipelines.GUI, right, top, graphics.guiWidth(), bottom, -16777216);
1048
	}
1049
1050
	private void updateVignetteBrightness(final Entity camera) {
1051
		BlockPos blockPos = BlockPos.containing(camera.getX(), camera.getEyeY(), camera.getZ());
1052
		float levelBrightness = Lightmap.getBrightness(camera.level().dimensionType(), camera.level().getMaxLocalRawBrightness(blockPos));
1053
		float brightness = Mth.clamp(1.0F - levelBrightness, 0.0F, 1.0F);
1054
		this.vignetteBrightness = this.vignetteBrightness + (brightness - this.vignetteBrightness) * 0.01F;
1055
	}
1056
1057
	private void extractVignette(final GuiGraphicsExtractor graphics, final @Nullable Entity camera) {
1058
		WorldBorder worldBorder = this.minecraft.level.getWorldBorder();
1059
		float borderWarningStrength = 0.0F;
1060
		if (camera != null) {
1061
			float distToBorder = (float)worldBorder.getDistanceToBorder(camera);
1062
			double movingBlocksThreshold = Math.min(
1063
				worldBorder.getLerpSpeed() * worldBorder.getWarningTime(), Math.abs(worldBorder.getLerpTarget() - worldBorder.getSize())
1064
			);
1065
			double warningDistance = Math.max(worldBorder.getWarningBlocks(), movingBlocksThreshold);
1066
			if (distToBorder < warningDistance) {
1067
				borderWarningStrength = 1.0F - (float)(distToBorder / warningDistance);
1068
			}
1069
		}
1070
1071
		float brightness = Mth.clamp(this.vignetteBrightness, 0.0F, 1.0F);
1072
		int color;
1073
		if (borderWarningStrength > 0.0F) {
1074
			borderWarningStrength = Mth.clamp(borderWarningStrength, 0.0F, 1.0F);
1075
			float red = brightness * (1.0F - borderWarningStrength);
1076
			float greenBlue = brightness + (1.0F - brightness) * borderWarningStrength;
1077
			color = ARGB.colorFromFloat(1.0F, red, greenBlue, greenBlue);
1078
		} else {
1079
			color = ARGB.colorFromFloat(1.0F, brightness, brightness, brightness);
1080
		}
1081
1082
		graphics.blit(
1083
			RenderPipelines.VIGNETTE, VIGNETTE_LOCATION, 0, 0, 0.0F, 0.0F, graphics.guiWidth(), graphics.guiHeight(), graphics.guiWidth(), graphics.guiHeight(), color
1084
		);
1085
	}
1086
1087
	private void extractPortalOverlay(final GuiGraphicsExtractor graphics, float alpha) {
1088
		if (alpha < 1.0F) {
1089
			alpha *= alpha;
1090
			alpha *= alpha;
1091
			alpha = alpha * 0.8F + 0.2F;
1092
		}
1093
1094
		int color = ARGB.white(alpha);
1095
		TextureAtlasSprite slot = this.minecraft.getModelManager().getBlockStateModelSet().getParticleMaterial(Blocks.NETHER_PORTAL.defaultBlockState()).sprite();
1096
		graphics.blitSprite(RenderPipelines.GUI_TEXTURED, slot, 0, 0, graphics.guiWidth(), graphics.guiHeight(), color);
1097
	}
1098
1099
	private void extractConfusionOverlay(final GuiGraphicsExtractor graphics, final float strength) {
1100
		int screenWidth = graphics.guiWidth();
1101
		int screenHeight = graphics.guiHeight();
1102
		graphics.pose().pushMatrix();
1103
		float size = Mth.lerp(strength, 2.0F, 1.0F);
1104
		graphics.pose().translate(screenWidth / 2.0F, screenHeight / 2.0F);
1105
		graphics.pose().scale(size, size);
1106
		graphics.pose().translate(-screenWidth / 2.0F, -screenHeight / 2.0F);
1107
		float red = 0.2F * strength;
1108
		float green = 0.4F * strength;
1109
		float blue = 0.2F * strength;
1110
		graphics.blit(
1111
			RenderPipelines.GUI_NAUSEA_OVERLAY,
1112
			NAUSEA_LOCATION,
1113
			0,
1114
			0,
1115
			0.0F,
1116
			0.0F,
1117
			screenWidth,
1118
			screenHeight,
1119
			screenWidth,
1120
			screenHeight,
1121
			ARGB.colorFromFloat(1.0F, red, green, blue)
1122
		);
1123
		graphics.pose().popMatrix();
1124
	}
1125
1126
	private void extractSlot(
1127
		final GuiGraphicsExtractor graphics,
1128
		final int x,
1129
		final int y,
1130
		final DeltaTracker deltaTracker,
1131
		final Player player,
1132
		final ItemStack itemStack,
1133
		final int seed
1134
	) {
1135
		if (!itemStack.isEmpty()) {
1136
			float pop = itemStack.getPopTime() - deltaTracker.getGameTimeDeltaPartialTick(false);
1137
			if (pop > 0.0F) {
1138
				float squeeze = 1.0F + pop / 5.0F;
1139
				graphics.pose().pushMatrix();
1140
				graphics.pose().translate(x + 8, y + 12);
1141
				graphics.pose().scale(1.0F / squeeze, (squeeze + 1.0F) / 2.0F);
1142
				graphics.pose().translate(-(x + 8), -(y + 12));
1143
			}
1144
1145
			graphics.item(player, itemStack, x, y, seed);
1146
			if (pop > 0.0F) {
1147
				graphics.pose().popMatrix();
1148
			}
1149
1150
			graphics.itemDecorations(this.minecraft.font, itemStack, x, y);
1151
		}
1152
	}
1153
1154
	public void tick(final boolean pause) {
1155
		this.tickAutosaveIndicator();
1156
		if (!pause) {
1157
			this.tick();
1158
		}
1159
	}
1160
1161
	private void tick() {
1162
		if (this.overlayMessageTime > 0) {
1163
			this.overlayMessageTime--;
1164
		}
1165
1166
		if (this.titleTime > 0) {
1167
			this.titleTime--;
1168
			if (this.titleTime <= 0) {
1169
				this.title = null;
1170
				this.subtitle = null;
1171
			}
1172
		}
1173
1174
		this.tickCount++;
1175
		Entity camera = this.minecraft.getCameraEntity();
1176
		if (camera != null) {
1177
			this.updateVignetteBrightness(camera);
1178
		}
1179
1180
		if (this.minecraft.player != null) {
1181
			ItemStack selected = this.minecraft.player.getInventory().getSelectedItem();
1182
			if (selected.isEmpty()) {
1183
				this.toolHighlightTimer = 0;
1184
			} else if (this.lastToolHighlight.isEmpty()
1185
				|| !selected.is(this.lastToolHighlight.getItem())
1186
				|| !selected.getHoverName().equals(this.lastToolHighlight.getHoverName())) {
1187
				this.toolHighlightTimer = (int)(40.0 * this.minecraft.options.notificationDisplayTime().get());
1188
			} else if (this.toolHighlightTimer > 0) {
1189
				this.toolHighlightTimer--;
1190
			}
1191
1192
			this.lastToolHighlight = selected;
1193
		}
1194
1195
		this.chat.tick();
1196
	}
1197
1198
	private void tickAutosaveIndicator() {
1199
		MinecraftServer server = this.minecraft.getSingleplayerServer();
1200
		boolean isAutosaving = server != null && server.isCurrentlySaving();
1201
		this.lastAutosaveIndicatorValue = this.autosaveIndicatorValue;
1202
		this.autosaveIndicatorValue = Mth.lerp(0.2F, this.autosaveIndicatorValue, isAutosaving ? 1.0F : 0.0F);
1203
	}
1204
1205
	public void setNowPlaying(final Component string) {
1206
		Component message = Component.translatable("record.nowPlaying", string);
1207
		this.setOverlayMessage(message, true);
1208
		this.minecraft.getNarrator().saySystemNow(message);
1209
	}
1210
1211
	public void setOverlayMessage(final Component string, final boolean animate) {
1212
		this.overlayMessageString = string;
1213
		this.overlayMessageTime = 60;
1214
		this.animateOverlayMessageColor = animate;
1215
	}
1216
1217
	public void setTimes(final int fadeInTime, final int stayTime, final int fadeOutTime) {
1218
		if (fadeInTime >= 0) {
1219
			this.titleFadeInTime = fadeInTime;
1220
		}
1221
1222
		if (stayTime >= 0) {
1223
			this.titleStayTime = stayTime;
1224
		}
1225
1226
		if (fadeOutTime >= 0) {
1227
			this.titleFadeOutTime = fadeOutTime;
1228
		}
1229
1230
		if (this.titleTime > 0) {
1231
			this.titleTime = this.titleFadeInTime + this.titleStayTime + this.titleFadeOutTime;
1232
		}
1233
	}
1234
1235
	public void setSubtitle(final Component subtitle) {
1236
		this.subtitle = subtitle;
1237
	}
1238
1239
	public void setTitle(final Component title) {
1240
		this.title = title;
1241
		this.titleTime = this.titleFadeInTime + this.titleStayTime + this.titleFadeOutTime;
1242
	}
1243
1244
	public void clearTitles() {
1245
		this.title = null;
1246
		this.subtitle = null;
1247
		this.titleTime = 0;
1248
	}
1249
1250
	public ChatComponent getChat() {
1251
		return this.chat;
1252
	}
1253
1254
	public WaypointStyleManager getWaypointStyles() {
1255
		return this.waypointStyles;
1256
	}
1257
1258
	public int getGuiTicks() {
1259
		return this.tickCount;
1260
	}
1261
1262
	public Font getFont() {
1263
		return this.minecraft.font;
1264
	}
1265
1266
	public SpectatorGui getSpectatorGui() {
1267
		return this.spectatorGui;
1268
	}
1269
1270
	public PlayerTabOverlay getTabList() {
1271
		return this.tabList;
1272
	}
1273
1274
	public void onDisconnected() {
1275
		this.tabList.reset();
1276
		this.bossOverlay.reset();
1277
		this.minecraft.gui.toastManager().clear();
1278
		this.debugOverlay.reset();
1279
		this.chat.clearMessages(true);
1280
		this.clearTitles();
1281
		this.resetTitleTimes();
1282
	}
1283
1284
	public BossHealthOverlay getBossOverlay() {
1285
		return this.bossOverlay;
1286
	}
1287
1288
	public DebugScreenOverlay getDebugOverlay() {
1289
		return this.debugOverlay;
1290
	}
1291
1292
	public void clearCache() {
1293
		this.debugOverlay.clearChunkCache();
1294
	}
1295
1296
	public void extractSavingIndicator(final GuiGraphicsExtractor graphics, final DeltaTracker deltaTracker) {
1297
		if (this.minecraft.options.showAutosaveIndicator().get() && (this.autosaveIndicatorValue > 0.0F || this.lastAutosaveIndicatorValue > 0.0F)) {
1298
			int alpha = Mth.floor(
1299
				255.0F * Mth.clamp(Mth.lerp(deltaTracker.getRealtimeDeltaTicks(), this.lastAutosaveIndicatorValue, this.autosaveIndicatorValue), 0.0F, 1.0F)
1300
			);
1301
			if (alpha > 0) {
1302
				Font font = this.getFont();
1303
				int width = font.width(SAVING_TEXT);
1304
				int color = ARGB.color(alpha, -1);
1305
				int textX = graphics.guiWidth() - width - 5;
1306
				int textY = graphics.guiHeight() - 9 - 5;
1307
				graphics.nextStratum();
1308
				graphics.textWithBackdrop(font, SAVING_TEXT, textX, textY, width, color);
1309
			}
1310
		}
1311
	}
1312
1313
	private boolean willPrioritizeExperienceInfo() {
1314
		return this.minecraft.player.experienceDisplayStartTick + 100 > this.minecraft.player.tickCount;
1315
	}
1316
1317
	private boolean willPrioritizeJumpInfo() {
1318
		return this.minecraft.player.getJumpRidingScale() > 0.0F
1319
			|| Optionull.mapOrDefault(this.minecraft.player.jumpableVehicle(), PlayerRideableJumping::getJumpCooldown, 0) > 0;
1320
	}
1321
1322
	private Hud.ContextualInfo nextContextualInfoState() {
1323
		boolean canShowLocatorInfo = this.minecraft.player.connection.getWaypointManager().hasWaypoints();
1324
		boolean canShowVehicleJumpInfo = this.minecraft.player.jumpableVehicle() != null;
1325
		boolean canShowExperienceInfo = this.minecraft.gameMode.hasExperience();
1326
		if (canShowLocatorInfo) {
1327
			if (canShowVehicleJumpInfo && this.willPrioritizeJumpInfo()) {
1328
				return Hud.ContextualInfo.JUMPABLE_VEHICLE;
1329
			} else {
1330
				return canShowExperienceInfo && this.willPrioritizeExperienceInfo() ? Hud.ContextualInfo.EXPERIENCE : Hud.ContextualInfo.LOCATOR;
1331
			}
1332
		} else if (canShowVehicleJumpInfo) {
1333
			return Hud.ContextualInfo.JUMPABLE_VEHICLE;
1334
		} else {
1335
			return canShowExperienceInfo ? Hud.ContextualInfo.EXPERIENCE : Hud.ContextualInfo.EMPTY;
1336
		}
1337
	}
1338
1339
	@Environment(EnvType.CLIENT)
1340
	private enum ContextualInfo {
1341
		EMPTY,
1342
		EXPERIENCE,
1343
		LOCATOR,
1344
		JUMPABLE_VEHICLE;
1345
	}
1346
1347
	@Environment(EnvType.CLIENT)
1348
	private enum HeartType {
1349
		CONTAINER(
1350
			Identifier.withDefaultNamespace("hud/heart/container"),
1351
			Identifier.withDefaultNamespace("hud/heart/container_blinking"),
1352
			Identifier.withDefaultNamespace("hud/heart/container"),
1353
			Identifier.withDefaultNamespace("hud/heart/container_blinking"),
1354
			Identifier.withDefaultNamespace("hud/heart/container_hardcore"),
1355
			Identifier.withDefaultNamespace("hud/heart/container_hardcore_blinking"),
1356
			Identifier.withDefaultNamespace("hud/heart/container_hardcore"),
1357
			Identifier.withDefaultNamespace("hud/heart/container_hardcore_blinking")
1358
		),
1359
		NORMAL(
1360
			Identifier.withDefaultNamespace("hud/heart/full"),
1361
			Identifier.withDefaultNamespace("hud/heart/full_blinking"),
1362
			Identifier.withDefaultNamespace("hud/heart/half"),
1363
			Identifier.withDefaultNamespace("hud/heart/half_blinking"),
1364
			Identifier.withDefaultNamespace("hud/heart/hardcore_full"),
1365
			Identifier.withDefaultNamespace("hud/heart/hardcore_full_blinking"),
1366
			Identifier.withDefaultNamespace("hud/heart/hardcore_half"),
1367
			Identifier.withDefaultNamespace("hud/heart/hardcore_half_blinking")
1368
		),
1369
		POISIONED(
1370
			Identifier.withDefaultNamespace("hud/heart/poisoned_full"),
1371
			Identifier.withDefaultNamespace("hud/heart/poisoned_full_blinking"),
1372
			Identifier.withDefaultNamespace("hud/heart/poisoned_half"),
1373
			Identifier.withDefaultNamespace("hud/heart/poisoned_half_blinking"),
1374
			Identifier.withDefaultNamespace("hud/heart/poisoned_hardcore_full"),
1375
			Identifier.withDefaultNamespace("hud/heart/poisoned_hardcore_full_blinking"),
1376
			Identifier.withDefaultNamespace("hud/heart/poisoned_hardcore_half"),
1377
			Identifier.withDefaultNamespace("hud/heart/poisoned_hardcore_half_blinking")
1378
		),
1379
		WITHERED(
1380
			Identifier.withDefaultNamespace("hud/heart/withered_full"),
1381
			Identifier.withDefaultNamespace("hud/heart/withered_full_blinking"),
1382
			Identifier.withDefaultNamespace("hud/heart/withered_half"),
1383
			Identifier.withDefaultNamespace("hud/heart/withered_half_blinking"),
1384
			Identifier.withDefaultNamespace("hud/heart/withered_hardcore_full"),
1385
			Identifier.withDefaultNamespace("hud/heart/withered_hardcore_full_blinking"),
1386
			Identifier.withDefaultNamespace("hud/heart/withered_hardcore_half"),
1387
			Identifier.withDefaultNamespace("hud/heart/withered_hardcore_half_blinking")
1388
		),
1389
		ABSORBING(
1390
			Identifier.withDefaultNamespace("hud/heart/absorbing_full"),
1391
			Identifier.withDefaultNamespace("hud/heart/absorbing_full_blinking"),
1392
			Identifier.withDefaultNamespace("hud/heart/absorbing_half"),
1393
			Identifier.withDefaultNamespace("hud/heart/absorbing_half_blinking"),
1394
			Identifier.withDefaultNamespace("hud/heart/absorbing_hardcore_full"),
1395
			Identifier.withDefaultNamespace("hud/heart/absorbing_hardcore_full_blinking"),
1396
			Identifier.withDefaultNamespace("hud/heart/absorbing_hardcore_half"),
1397
			Identifier.withDefaultNamespace("hud/heart/absorbing_hardcore_half_blinking")
1398
		),
1399
		FROZEN(
1400
			Identifier.withDefaultNamespace("hud/heart/frozen_full"),
1401
			Identifier.withDefaultNamespace("hud/heart/frozen_full_blinking"),
1402
			Identifier.withDefaultNamespace("hud/heart/frozen_half"),
1403
			Identifier.withDefaultNamespace("hud/heart/frozen_half_blinking"),
1404
			Identifier.withDefaultNamespace("hud/heart/frozen_hardcore_full"),
1405
			Identifier.withDefaultNamespace("hud/heart/frozen_hardcore_full_blinking"),
1406
			Identifier.withDefaultNamespace("hud/heart/frozen_hardcore_half"),
1407
			Identifier.withDefaultNamespace("hud/heart/frozen_hardcore_half_blinking")
1408
		);
1409
1410
		private final Identifier full;
1411
		private final Identifier fullBlinking;
1412
		private final Identifier half;
1413
		private final Identifier halfBlinking;
1414
		private final Identifier hardcoreFull;
1415
		private final Identifier hardcoreFullBlinking;
1416
		private final Identifier hardcoreHalf;
1417
		private final Identifier hardcoreHalfBlinking;
1418
1419
		HeartType(
1420
			final Identifier full,
1421
			final Identifier fullBlinking,
1422
			final Identifier half,
1423
			final Identifier halfBlinking,
1424
			final Identifier hardcoreFull,
1425
			final Identifier hardcoreFullBlinking,
1426
			final Identifier hardcoreHalf,
1427
			final Identifier hardcoreHalfBlinking
1428
		) {
1429
			this.full = full;
1430
			this.fullBlinking = fullBlinking;
1431
			this.half = half;
1432
			this.halfBlinking = halfBlinking;
1433
			this.hardcoreFull = hardcoreFull;
1434
			this.hardcoreFullBlinking = hardcoreFullBlinking;
1435
			this.hardcoreHalf = hardcoreHalf;
1436
			this.hardcoreHalfBlinking = hardcoreHalfBlinking;
1437
		}
1438
1439
		public Identifier getSprite(final boolean isHardcore, final boolean isHalf, final boolean isBlink) {
1440
			if (!isHardcore) {
1441
				if (isHalf) {
1442
					return isBlink ? this.halfBlinking : this.half;
1443
				} else {
1444
					return isBlink ? this.fullBlinking : this.full;
1445
				}
1446
			} else if (isHalf) {
1447
				return isBlink ? this.hardcoreHalfBlinking : this.hardcoreHalf;
1448
			} else {
1449
				return isBlink ? this.hardcoreFullBlinking : this.hardcoreFull;
1450
			}
1451
		}
1452
1453
		private static Hud.HeartType forPlayer(final Player player) {
1454
			Hud.HeartType type;
1455
			if (player.hasEffect(MobEffects.POISON)) {
1456
				type = POISIONED;
1457
			} else if (player.hasEffect(MobEffects.WITHER)) {
1458
				type = WITHERED;
1459
			} else if (player.isFullyFrozen()) {
1460
				type = FROZEN;
1461
			} else {
1462
				type = NORMAL;
1463
			}
1464
1465
			return type;
1466
		}
1467
	}
1468
}
1469

Decompiled Minecraft 26.3 source of Hud (net/minecraft/client/gui/Hud.java) with Mojang official mappings, stored verbatim on the site.