2025-11-24 22:52:51 +03:00

61 lines
2.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.gui.components;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.narration.NarrationSupplier;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import org.jspecify.annotations.Nullable;
public class Tooltip
implements NarrationSupplier {
private static final int MAX_WIDTH = 170;
private final Component message;
private @Nullable List<FormattedCharSequence> cachedTooltip;
private @Nullable Language splitWithLanguage;
private final @Nullable Component narration;
private Tooltip(Component message, @Nullable Component narration) {
this.message = message;
this.narration = narration;
}
public static Tooltip create(Component message, @Nullable Component narration) {
return new Tooltip(message, narration);
}
public static Tooltip create(Component message) {
return new Tooltip(message, message);
}
@Override
public void updateNarration(NarrationElementOutput output) {
if (this.narration != null) {
output.add(NarratedElementType.HINT, this.narration);
}
}
public List<FormattedCharSequence> toCharSequence(Minecraft minecraft) {
Language currentLanguage = Language.getInstance();
if (this.cachedTooltip == null || currentLanguage != this.splitWithLanguage) {
this.cachedTooltip = Tooltip.splitTooltip(minecraft, this.message);
this.splitWithLanguage = currentLanguage;
}
return this.cachedTooltip;
}
public static List<FormattedCharSequence> splitTooltip(Minecraft minecraft, Component message) {
return minecraft.font.split(message, 170);
}
}