Skip to content

Commit 061687c

Browse files
committed
Add a way to find all fonts registered on the client.
1 parent 10f89fa commit 061687c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Common/src/main/java/net/darkhax/bookshelf/api/util/TextHelper.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package net.darkhax.bookshelf.api.util;
22

3+
import net.darkhax.bookshelf.api.Services;
4+
import net.darkhax.bookshelf.mixin.client.AccessorFontManager;
5+
import net.darkhax.bookshelf.mixin.client.AccessorMinecraft;
36
import net.darkhax.bookshelf.mixin.entity.AccessorEntity;
7+
import net.minecraft.client.Minecraft;
48
import net.minecraft.network.chat.Component;
59
import net.minecraft.network.chat.HoverEvent;
610
import net.minecraft.network.chat.MutableComponent;
@@ -11,8 +15,16 @@
1115
import net.minecraft.world.entity.Entity;
1216
import net.minecraft.world.item.ItemStack;
1317

18+
import java.util.Collections;
19+
import java.util.Set;
20+
1421
public final class TextHelper {
1522

23+
public static final ResourceLocation FONT_ALT = new ResourceLocation("minecraft", "alt");
24+
public static final ResourceLocation FONT_DEFAULT = new ResourceLocation("minecraft", "default");
25+
public static final ResourceLocation FONT_ILLAGER = new ResourceLocation("minecraft", "illageralt");
26+
public static final ResourceLocation FONT_UNIFORM = new ResourceLocation("minecraft", "uniform");
27+
1628
public static MutableComponent getFormatedTime(int ticks, boolean includeHover) {
1729

1830
MutableComponent component = new TextComponent(StringUtil.formatTickDuration(ticks));
@@ -77,4 +89,14 @@ public static Component applyFont(Component text, ResourceLocation font) {
7789
text.getSiblings().forEach(sib -> applyFont(sib, font));
7890
return text;
7991
}
92+
93+
public static Set<ResourceLocation> getRegisteredFonts() {
94+
95+
if (!Services.PLATFORM.isPhysicalClient()) {
96+
97+
return Collections.emptySet();
98+
}
99+
100+
return ((AccessorFontManager) (((AccessorMinecraft) Minecraft.getInstance()).bookshelf$getFontManager())).bookshelf$getFonts().keySet();
101+
}
80102
}

0 commit comments

Comments
 (0)