Toast .java

net.minecraft.client.gui.components.toasts.Toast (interface): members: occcupiedSlotCount, SLOT_HEIGHT, NO_TOKEN, onFinishedRendering, Visibility, yPos.

net.minecraft.client.gui.components.toastsinterface73 linesclient1.7 KB

API Surface (1)

void playSound(final SoundManager manager)

Fields & Constants (3)

NO_TOKEN
DEFAULT_WIDTH
SLOT_HEIGHT

Full Source

Toast.java73 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.components.toasts;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.Font;
6
import net.minecraft.client.gui.GuiGraphicsExtractor;
7
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
8
import net.minecraft.client.sounds.SoundManager;
9
import net.minecraft.sounds.SoundEvent;
10
import net.minecraft.sounds.SoundEvents;
11
import net.minecraft.util.Mth;
12
import org.jspecify.annotations.Nullable;
13
14
@Environment(EnvType.CLIENT)
15
public interface Toast {
16
	Object NO_TOKEN = new Object();
17
	int DEFAULT_WIDTH = 160;
18
	int SLOT_HEIGHT = 32;
19
20
	Toast.Visibility getWantedVisibility();
21
22
	void update(final ToastManager manager, final long fullyVisibleForMs);
23
24
	default @Nullable SoundEvent getSoundEvent() {
25
		return null;
26
	}
27
28
	void extractRenderState(final GuiGraphicsExtractor graphics, final Font font, final long fullyVisibleForMs);
29
30
	default Object getToken() {
31
		return NO_TOKEN;
32
	}
33
34
	default float xPos(final int screenWidth, final float visiblePortion) {
35
		return screenWidth - this.width() * visiblePortion;
36
	}
37
38
	default float yPos(final int firstSlotIndex) {
39
		return firstSlotIndex * this.height();
40
	}
41
42
	default int width() {
43
		return 160;
44
	}
45
46
	default int height() {
47
		return 32;
48
	}
49
50
	default int occcupiedSlotCount() {
51
		return Mth.positiveCeilDiv(this.height(), 32);
52
	}
53
54
	default void onFinishedRendering() {
55
	}
56
57
	@Environment(EnvType.CLIENT)
58
	enum Visibility {
59
		SHOW(SoundEvents.UI_TOAST_IN),
60
		HIDE(SoundEvents.UI_TOAST_OUT);
61
62
		private final SoundEvent soundEvent;
63
64
		Visibility(final SoundEvent soundEvent) {
65
			this.soundEvent = soundEvent;
66
		}
67
68
		public void playSound(final SoundManager manager) {
69
			manager.play(SimpleSoundInstance.forUI(this.soundEvent, 1.0F, 1.0F));
70
		}
71
	}
72
}
73

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