Skip to content

Commit 52fdb16

Browse files
committed
Switch to Mojang mappings
1 parent 68c0903 commit 52fdb16

5 files changed

Lines changed: 65 additions & 67 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919

2020
dependencies {
2121
minecraft "com.mojang:minecraft:${project.minecraft_version}"
22-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
22+
mappings loom.officialMojangMappings()
2323
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
2424
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
2525
modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"

src/main/java/io/toadlabs/numeralping/NumeralPingMod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
99
import net.fabricmc.loader.api.FabricLoader;
1010
import net.fabricmc.loader.api.ModContainer;
11-
import net.minecraft.util.Identifier;
11+
import net.minecraft.resources.ResourceLocation;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

@@ -48,8 +48,8 @@ public void onInitializeClient() {
4848
saveConfig();
4949

5050
ModContainer container = FabricLoader.getInstance().getModContainer(ID).get();
51-
ResourceManagerHelper.registerBuiltinResourcePack(Identifier.of(ID, "font_fix"), container, ResourcePackActivationType.NORMAL);
52-
ResourceManagerHelper.registerBuiltinResourcePack(Identifier.of(ID, "font_fix_high_res"), container, ResourcePackActivationType.NORMAL);
51+
ResourceManagerHelper.registerBuiltinResourcePack(ResourceLocation.fromNamespaceAndPath(ID, "font_fix"), container, ResourcePackActivationType.NORMAL);
52+
ResourceManagerHelper.registerBuiltinResourcePack(ResourceLocation.fromNamespaceAndPath(ID, "font_fix_high_res"), container, ResourcePackActivationType.NORMAL);
5353
}
5454

5555
public void saveConfig() {

src/main/java/io/toadlabs/numeralping/integration/ModMenuIntegration.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
1212
import io.toadlabs.numeralping.NumeralPingMod;
1313
import io.toadlabs.numeralping.config.NumeralConfig;
14-
import net.minecraft.text.Text;
15-
1614
import java.awt.*;
15+
import net.minecraft.network.chat.Component;
1716

1817
import static io.toadlabs.numeralping.NumeralPingMod.ID;
1918

@@ -26,15 +25,15 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
2625
return parent -> {
2726
NumeralConfig config = NumeralConfig.instance();
2827
return YetAnotherConfigLib.createBuilder()
29-
.title(Text.of(NumeralPingMod.NAME))
28+
.title(Component.nullToEmpty(NumeralPingMod.NAME))
3029

3130
.category(ConfigCategory.createBuilder()
32-
.name(Text.of(NumeralPingMod.NAME))
31+
.name(Component.nullToEmpty(NumeralPingMod.NAME))
3332

3433
// Player List
3534
.option(Option.<Boolean>createBuilder()
36-
.name(Text.translatable(OPTION + ".playerList"))
37-
.description(OptionDescription.of(Text.translatable(OPTION + ".playerList.desc")))
35+
.name(Component.translatable(OPTION + ".playerList"))
36+
.description(OptionDescription.of(Component.translatable(OPTION + ".playerList.desc")))
3837
.binding(NumeralConfig.DEFAULTS.playerList,
3938
() -> config.playerList,
4039
value -> config.playerList = value)
@@ -43,8 +42,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
4342

4443
// Server List
4544
.option(Option.<Boolean>createBuilder()
46-
.name(Text.translatable(OPTION + ".serverList"))
47-
.description(OptionDescription.of(Text.translatable(OPTION + ".serverList.desc")))
45+
.name(Component.translatable(OPTION + ".serverList"))
46+
.description(OptionDescription.of(Component.translatable(OPTION + ".serverList.desc")))
4847
.binding(NumeralConfig.DEFAULTS.serverList,
4948
() -> config.serverList,
5049
value -> config.serverList = value)
@@ -53,8 +52,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
5352

5453
// Small Ping
5554
.option(Option.<Boolean>createBuilder()
56-
.name(Text.translatable(OPTION + ".smallPing"))
57-
.description(OptionDescription.of(Text.translatable(OPTION + ".smallPing.desc")))
55+
.name(Component.translatable(OPTION + ".smallPing"))
56+
.description(OptionDescription.of(Component.translatable(OPTION + ".smallPing.desc")))
5857
.binding(NumeralConfig.DEFAULTS.smallPing,
5958
() -> config.smallPing,
6059
value -> config.smallPing = value)
@@ -65,8 +64,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
6564

6665
// Default
6766
.option(Option.<Integer>createBuilder()
68-
.name(Text.translatable(OPTION + ".defaultPingThreshold"))
69-
.description(OptionDescription.of(Text.translatable(OPTION + ".defaultPingThreshold.desc")))
67+
.name(Component.translatable(OPTION + ".defaultPingThreshold"))
68+
.description(OptionDescription.of(Component.translatable(OPTION + ".defaultPingThreshold.desc")))
7069
.binding(NumeralConfig.DEFAULTS.defaultPingThreshold,
7170
() -> config.defaultPingThreshold,
7271
value -> config.defaultPingThreshold = value)
@@ -75,8 +74,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
7574

7675
// levelOnePingThreshold
7776
.option(Option.<Integer>createBuilder()
78-
.name(Text.translatable(OPTION + ".levelOnePingThreshold"))
79-
.description(OptionDescription.of(Text.translatable(OPTION + ".levelOnePingThreshold.desc")))
77+
.name(Component.translatable(OPTION + ".levelOnePingThreshold"))
78+
.description(OptionDescription.of(Component.translatable(OPTION + ".levelOnePingThreshold.desc")))
8079
.binding(NumeralConfig.DEFAULTS.levelOnePingThreshold,
8180
() -> config.levelOnePingThreshold,
8281
value -> config.levelOnePingThreshold = value)
@@ -85,8 +84,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
8584

8685
// levelTwoPingThreshold
8786
.option(Option.<Integer>createBuilder()
88-
.name(Text.translatable(OPTION + ".levelTwoPingThreshold"))
89-
.description(OptionDescription.of(Text.translatable(OPTION + ".levelTwoPingThreshold.desc")))
87+
.name(Component.translatable(OPTION + ".levelTwoPingThreshold"))
88+
.description(OptionDescription.of(Component.translatable(OPTION + ".levelTwoPingThreshold.desc")))
9089
.binding(NumeralConfig.DEFAULTS.levelTwoPingThreshold,
9190
() -> config.levelTwoPingThreshold,
9291
value -> config.levelTwoPingThreshold = value)
@@ -95,8 +94,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
9594

9695
// levelThreePingThreshold
9796
.option(Option.<Integer>createBuilder()
98-
.name(Text.translatable(OPTION + ".levelThreePingThreshold"))
99-
.description(OptionDescription.of(Text.translatable(OPTION + ".levelThreePingThreshold.desc")))
97+
.name(Component.translatable(OPTION + ".levelThreePingThreshold"))
98+
.description(OptionDescription.of(Component.translatable(OPTION + ".levelThreePingThreshold.desc")))
10099
.binding(NumeralConfig.DEFAULTS.levelThreePingThreshold,
101100
() -> config.levelThreePingThreshold,
102101
value -> config.levelThreePingThreshold = value)
@@ -105,7 +104,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
105104

106105
// Ping < defaultPingThreshold Colour
107106
.option(Option.<Color>createBuilder()
108-
.name(Text.translatable(OPTION + ".defaultPingColour"))
107+
.name(Component.translatable(OPTION + ".defaultPingColour"))
109108
.binding(NumeralConfig.DEFAULTS.defaultPingColour,
110109
() -> config.defaultPingColour,
111110
value -> config.defaultPingColour = value)
@@ -114,7 +113,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
114113

115114
// Ping < levelOnePingThreshold Colour
116115
.option(Option.<Color>createBuilder()
117-
.name(Text.translatable(OPTION + ".levelOnePingColour"))
116+
.name(Component.translatable(OPTION + ".levelOnePingColour"))
118117
.binding(NumeralConfig.DEFAULTS.levelOnePingColour,
119118
() -> config.levelOnePingColour,
120119
value -> config.levelOnePingColour = value)
@@ -123,7 +122,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
123122

124123
// Ping < levelTwoPingThreshold Colour
125124
.option(Option.<Color>createBuilder()
126-
.name(Text.translatable(OPTION + ".levelTwoPingColour"))
125+
.name(Component.translatable(OPTION + ".levelTwoPingColour"))
127126
.binding(NumeralConfig.DEFAULTS.levelTwoPingColour,
128127
() -> config.levelTwoPingColour,
129128
value -> config.levelTwoPingColour = value)
@@ -132,7 +131,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
132131

133132
// Ping < levelThreePingThreshold Colour
134133
.option(Option.<Color>createBuilder()
135-
.name(Text.translatable(OPTION + ".levelThreePingColour"))
134+
.name(Component.translatable(OPTION + ".levelThreePingColour"))
136135
.binding(NumeralConfig.DEFAULTS.levelThreePingColour,
137136
() -> config.levelThreePingColour,
138137
value -> config.levelThreePingColour = value)
@@ -141,8 +140,8 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
141140

142141
// Ping ≥ levelThreePingThreshold Colour
143142
.option(Option.<Color>createBuilder()
144-
.name(Text.translatable(OPTION + ".levelFourPingColour"))
145-
.description(OptionDescription.of(Text.translatable(OPTION + ".levelFourPingColour.desc")))
143+
.name(Component.translatable(OPTION + ".levelFourPingColour"))
144+
.description(OptionDescription.of(Component.translatable(OPTION + ".levelFourPingColour.desc")))
146145
.binding(NumeralConfig.DEFAULTS.levelFourPingColour,
147146
() -> config.levelFourPingColour,
148147
value -> config.levelFourPingColour = value)
@@ -151,7 +150,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
151150

152151
// Timed Out Ping Colour
153152
.option(Option.<Color>createBuilder()
154-
.name(Text.translatable(OPTION + ".levelFivePingColour"))
153+
.name(Component.translatable(OPTION + ".levelFivePingColour"))
155154
.binding(NumeralConfig.DEFAULTS.levelFivePingColour,
156155
() -> config.levelFivePingColour,
157156
value -> config.levelFivePingColour = value)

src/main/java/io/toadlabs/numeralping/mixin/PlayerListHudMixin.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,33 @@
99

1010
import io.toadlabs.numeralping.config.NumeralConfig;
1111
import io.toadlabs.numeralping.util.Utils;
12-
import net.minecraft.client.MinecraftClient;
13-
import net.minecraft.client.gui.DrawContext;
14-
import net.minecraft.client.gui.hud.PlayerListHud;
15-
import net.minecraft.client.network.PlayerListEntry;
16-
1712
import java.util.List;
13+
import net.minecraft.client.Minecraft;
14+
import net.minecraft.client.gui.GuiGraphics;
15+
import net.minecraft.client.gui.components.PlayerTabOverlay;
16+
import net.minecraft.client.multiplayer.PlayerInfo;
1817

19-
@Mixin(PlayerListHud.class)
18+
@Mixin(PlayerTabOverlay.class)
2019
public class PlayerListHudMixin {
2120

2221
@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(II)I", ordinal = 0))
23-
private int adjustTablistEntryWidth(int a, int b, Operation<Integer> original, @Local(ordinal = 0) List<PlayerListEntry> playerListEntries) {
22+
private int adjustTablistEntryWidth(int a, int b, Operation<Integer> original, @Local(ordinal = 0) List<PlayerInfo> playerListEntries) {
2423
NumeralConfig config = NumeralConfig.instance();
2524
int vanillaPingWidth = 9;
2625
int maxPingWidth = vanillaPingWidth;
2726

28-
for (PlayerListEntry playerListEntry : playerListEntries) {
27+
for (PlayerInfo playerListEntry : playerListEntries) {
2928
String pingString = Integer.toString(playerListEntry.getLatency());
3029
pingString = config.shiftPing(pingString);
3130

32-
maxPingWidth = Math.max(maxPingWidth, client.textRenderer.getWidth(pingString));
31+
maxPingWidth = Math.max(maxPingWidth, minecraft.font.width(pingString));
3332
}
3433

3534
return original.call(a + maxPingWidth - vanillaPingWidth, b);
3635
}
3736

38-
@Inject(method = "renderLatencyIcon", at = @At("HEAD"), cancellable = true)
39-
public void renderDetailedLatency(DrawContext context, int width, int x, int y, PlayerListEntry entry,
37+
@Inject(method = "renderPingIcon", at = @At("HEAD"), cancellable = true)
38+
public void renderDetailedLatency(GuiGraphics context, int width, int x, int y, PlayerInfo entry,
4039
CallbackInfo callback) {
4140
NumeralConfig config = NumeralConfig.instance();
4241

@@ -46,17 +45,17 @@ public void renderDetailedLatency(DrawContext context, int width, int x, int y,
4645
String pingString = Integer.toString(entry.getLatency());
4746
pingString = config.shiftPing(pingString);
4847

49-
context.getMatrices().pushMatrix();
48+
context.pose().pushMatrix();
5049

51-
context.drawTextWithShadow(client.textRenderer, pingString,
52-
x + width - client.textRenderer.getWidth(pingString) - 1, y - (config.smallPing ? 2 : 0),
50+
context.drawString(minecraft.font, pingString,
51+
x + width - minecraft.font.width(pingString) - 1, y - (config.smallPing ? 2 : 0),
5352
Utils.getPingColour(entry.getLatency()));
5453

55-
context.getMatrices().popMatrix();
54+
context.pose().popMatrix();
5655
}
5756
}
5857

5958
@Shadow
60-
private @Final MinecraftClient client;
59+
private @Final Minecraft minecraft;
6160

6261
}

src/main/java/io/toadlabs/numeralping/mixin/ServerEntryMixin.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import com.mojang.blaze3d.pipeline.RenderPipeline;
55
import io.toadlabs.numeralping.config.NumeralConfig;
66
import io.toadlabs.numeralping.util.Utils;
7-
import net.minecraft.client.MinecraftClient;
8-
import net.minecraft.client.gui.DrawContext;
9-
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
10-
import net.minecraft.client.network.ServerInfo;
11-
import net.minecraft.text.Text;
12-
import net.minecraft.text.TranslatableTextContent;
13-
import net.minecraft.util.Identifier;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.client.gui.GuiGraphics;
9+
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
10+
import net.minecraft.client.multiplayer.ServerData;
11+
import net.minecraft.network.chat.Component;
12+
import net.minecraft.network.chat.contents.TranslatableContents;
13+
import net.minecraft.resources.ResourceLocation;
1414
import org.spongepowered.asm.mixin.Final;
1515
import org.spongepowered.asm.mixin.Mixin;
1616
import org.spongepowered.asm.mixin.Shadow;
@@ -22,48 +22,48 @@
2222

2323
// a priority of 2000 means it will apply later
2424
// this is combined with `require = 0` to allow other mods to apply more integral functionality first without the game crashing
25-
@Mixin(value = MultiplayerServerListWidget.ServerEntry.class, priority = 0)
25+
@Mixin(value = ServerSelectionList.OnlineServerEntry.class, priority = 0)
2626
public class ServerEntryMixin {
2727

28-
@ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V", ordinal = 0))
28+
@ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Lnet/minecraft/network/chat/Component;III)V", ordinal = 0))
2929
public void shiftText(Args args) {
3030
NumeralConfig config = NumeralConfig.instance();
3131

3232
if (config.serverList) {
33-
args.set(2, ((int) args.get(2)) + 10 - client.textRenderer.getWidth(getPingText(config, server.ping)));
33+
args.set(2, ((int) args.get(2)) + 10 - minecraft.font.width(getPingText(config, serverData.ping)));
3434
}
3535
}
3636

3737
// hide the tooltip if it's redundant
38-
@WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTooltip(Lnet/minecraft/text/Text;II)V"))
39-
public boolean hideTooltip(DrawContext instance, Text text, int x, int y) {
40-
return !(NumeralConfig.instance().serverList && text.getContent() instanceof TranslatableTextContent content && content.getKey().equalsIgnoreCase("multiplayer.status.ping"));
38+
@WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;setTooltipForNextFrame(Lnet/minecraft/network/chat/Component;II)V"))
39+
public boolean hideTooltip(GuiGraphics instance, Component text, int x, int y) {
40+
return !(NumeralConfig.instance().serverList && text.getContents() instanceof TranslatableContents content && content.getKey().equalsIgnoreCase("multiplayer.status.ping"));
4141
}
4242

4343
@Redirect(
4444
method = "render",
4545
at = @At(
4646
value = "INVOKE",
47-
target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/util/Identifier;IIII)V",
47+
target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/resources/ResourceLocation;IIII)V",
4848
ordinal = 0))
49-
public void renderDetailedLatency(DrawContext instance, RenderPipeline pipeline, Identifier sprite, int x, int y, int width, int height) {
49+
public void renderDetailedLatency(GuiGraphics instance, RenderPipeline pipeline, ResourceLocation sprite, int x, int y, int width, int height) {
5050
NumeralConfig config = NumeralConfig.instance();
5151

52-
if (server.ping >= 0 && config.serverList) {
53-
String text = getPingText(config, server.ping);
52+
if (serverData.ping >= 0 && config.serverList) {
53+
String text = getPingText(config, serverData.ping);
5454

5555
if (config.smallPing) {
5656
y--;
5757
} else {
5858
y++;
5959
}
6060

61-
instance.drawText(client.textRenderer, text, x + 11 - client.textRenderer.getWidth(text), y,
62-
Utils.getPingColour((int) server.ping), false);
61+
instance.drawString(minecraft.font, text, x + 11 - minecraft.font.width(text), y,
62+
Utils.getPingColour((int) serverData.ping), false);
6363
return;
6464
}
6565

66-
instance.drawGuiTexture(pipeline, sprite, x, y, width, height);
66+
instance.blitSprite(pipeline, sprite, x, y, width, height);
6767
}
6868

6969
@Unique
@@ -72,9 +72,9 @@ private String getPingText(NumeralConfig config, long ping) {
7272
}
7373

7474
@Shadow
75-
private @Final ServerInfo server;
75+
private @Final ServerData serverData;
7676

7777
@Shadow
78-
private @Final MinecraftClient client;
78+
private @Final Minecraft minecraft;
7979

8080
}

0 commit comments

Comments
 (0)