-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathGuiUtils.java
More file actions
79 lines (66 loc) · 2.67 KB
/
Copy pathGuiUtils.java
File metadata and controls
79 lines (66 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package dev.isxander.yacl3.gui.utils;
import dev.isxander.yacl3.mixin.GuiAccessor;
import dev.isxander.yacl3.platform.YACLPlatform;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.util.FormattedCharSequence;
public class GuiUtils {
public static final WidgetSprites BUTTON_SPRITES = new WidgetSprites(
YACLPlatform.mcRl("widget/button"), // normal
YACLPlatform.mcRl("widget/button_disabled"), // disabled & !focused
YACLPlatform.mcRl("widget/button_highlighted"), // !disabled & focused
YACLPlatform.mcRl("widget/slider_highlighted") // disabled & focused
);
public static MutableComponent translatableFallback(String key, Component fallback) {
if (Language.getInstance().has(key))
return Component.translatable(key);
return fallback.copy();
}
public static String shortenString(String string, Font font, int maxWidth, String suffix) {
if (string.isEmpty())
return string;
boolean firstIter = true;
while (font.width(string) > maxWidth) {
string = string.substring(0, Math.max(string.length() - 1 - (firstIter ? 1 : suffix.length() + 1), 0)).trim();
string += suffix;
if (string.equals(suffix))
break;
firstIter = false;
}
return string;
}
public static FormattedCharSequence applyFallbackStyle(FormattedCharSequence seq, Style fallback) {
return output -> seq.accept((c, s, t) -> output.accept(c, s.applyTo(fallback), t));
}
public static void setScreen(Screen screen, boolean ignoreVanilla) {
if (ignoreVanilla) {
//? >=26.2 {
((GuiAccessor) Minecraft.getInstance().gui).yacl$setScreen(screen);
//? } else {
/*Minecraft.getInstance().screen = screen;
*///? }
} else {
//? >=26.2 {
Minecraft.getInstance().gui.setScreen(screen);
//? } else {
/*Minecraft.getInstance().setScreen(screen);
*///? }
}
}
public static void setScreen(Screen screen) {
setScreen(screen, false);
}
public static Screen getCurrentScreen() {
//? >=26.2 {
return Minecraft.getInstance().gui.screen();
//? } else {
/*return Minecraft.getInstance().screen;
*///? }
}
}