Port to 1.16.3

This commit is contained in:
vladmarica 2020-09-17 00:22:33 -03:00
parent b5df22f881
commit 8e1a22a996
7 changed files with 50 additions and 43 deletions

View file

@ -13,7 +13,7 @@ This is a client-side mod. The server doesn't need to have it installed. It work
## Supported Minecraft Versions ## Supported Minecraft Versions
* **1.15.x** * **1.15.x**
* **1.16.x**
## Requirements ## Requirements
* [Fabric](https://fabricmc.net/) * [Fabric](https://fabricmc.net/)

View file

@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version=1.15.2 minecraft_version=1.16.3
yarn_mappings=1.15.2+build.17 yarn_mappings=1.16.3+build.7
loader_version=0.9.2+build.206 loader_version=0.9.3+build.207
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.0.0
@ -14,4 +14,4 @@ org.gradle.jvmargs=-Xmx1G
# Dependencies # Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.19.0+build.325-1.15 fabric_version=0.20.2+build.402-1.16

View file

@ -5,6 +5,7 @@ import com.google.common.collect.Ordering;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.vladmarica.betterpingdisplay.Config; import com.vladmarica.betterpingdisplay.Config;
import com.vladmarica.betterpingdisplay.hud.CustomPlayerListHud.EntryOrderComparator;
import com.vladmarica.betterpingdisplay.BetterPingDisplayMod; import com.vladmarica.betterpingdisplay.BetterPingDisplayMod;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
@ -18,11 +19,13 @@ import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.render.entity.PlayerModelPart; import net.minecraft.client.render.entity.PlayerModelPart;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreboardCriterion; import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.scoreboard.ScoreboardObjective; import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.scoreboard.Team; import net.minecraft.scoreboard.Team;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
@ -34,7 +37,7 @@ public final class CustomPlayerListHud {
private static final int PLAYER_SLOT_EXTRA_WIDTH = 45; private static final int PLAYER_SLOT_EXTRA_WIDTH = 45;
private static final int PLAYER_ICON_WIDTH = 9; private static final int PLAYER_ICON_WIDTH = 9;
public static void render(PlayerListHud hud, int width, Scoreboard scoreboard, ScoreboardObjective obj) { public static void render(PlayerListHud hud, MatrixStack stack, int width, Scoreboard scoreboard, ScoreboardObjective obj) {
MinecraftClient mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
TextRenderer textRenderer = mc.textRenderer; TextRenderer textRenderer = mc.textRenderer;
Text header = PlayerListHudUtil.getHeader(hud); Text header = PlayerListHudUtil.getHeader(hud);
@ -50,10 +53,10 @@ public final class CustomPlayerListHud {
int n; int n;
while(playerListIterator.hasNext()) { while(playerListIterator.hasNext()) {
PlayerListEntry playerListEntry = (PlayerListEntry)playerListIterator.next(); PlayerListEntry playerListEntry = (PlayerListEntry)playerListIterator.next();
n = mc.textRenderer.getStringWidth(hud.getPlayerName(playerListEntry).asFormattedString()); n = mc.textRenderer.getWidth(hud.getPlayerName(playerListEntry));
i = Math.max(i, n); i = Math.max(i, n);
if (obj != null && obj.getRenderType() != ScoreboardCriterion.RenderType.HEARTS) { if (obj != null && obj.getRenderType() != ScoreboardCriterion.RenderType.HEARTS) {
n = textRenderer.getStringWidth(" " + scoreboard.getPlayerScore(playerListEntry.getProfile().getName(), obj).getScore()); n = textRenderer.getWidth(" " + scoreboard.getPlayerScore(playerListEntry.getProfile().getName(), obj).getScore());
j = Math.max(j, n); j = Math.max(j, n);
} }
} }
@ -81,23 +84,23 @@ public final class CustomPlayerListHud {
int s = width / 2 - (r * n + (n - 1) * 5) / 2; int s = width / 2 - (r * n + (n - 1) * 5) / 2;
int t = 10; int t = 10;
int u = r * n + (n - 1) * 5; int u = r * n + (n - 1) * 5;
List<String> list2 = null; List<OrderedText> list2 = null;
if (header != null) { if (header != null) {
list2 = mc.textRenderer.wrapStringToWidthAsList(header.asFormattedString(), width - 50); list2 = mc.textRenderer.wrapLines(header, width - 50);
String string; String string;
for(Iterator var18 = list2.iterator(); var18.hasNext(); u = Math.max(u, mc.textRenderer.getStringWidth(string))) { for(Iterator var18 = list2.iterator(); var18.hasNext(); u = Math.max(u, mc.textRenderer.getWidth(string))) {
string = (String)var18.next(); string = (String)var18.next();
} }
} }
List<String> list3 = null; List<OrderedText> list3 = null;
String string3; String string3;
Iterator var36; Iterator var36;
if (footer != null) { if (footer != null) {
list3 = mc.textRenderer.wrapStringToWidthAsList(footer.asFormattedString(), width - 50); list3 = mc.textRenderer.wrapLines(footer, width - 50);
for(var36 = list3.iterator(); var36.hasNext(); u = Math.max(u, mc.textRenderer.getStringWidth(string3))) { for(var36 = list3.iterator(); var36.hasNext(); u = Math.max(u, mc.textRenderer.getWidth(string3))) {
string3 = (String)var36.next(); string3 = (String)var36.next();
} }
} }
@ -112,18 +115,18 @@ public final class CustomPlayerListHud {
var10001 = t - 1; var10001 = t - 1;
var10002 = width / 2 + u / 2 + 1; var10002 = width / 2 + u / 2 + 1;
var10004 = list2.size(); var10004 = list2.size();
DrawableHelper.fill(var10000, var10001, var10002, t + var10004 * 9, Integer.MIN_VALUE); DrawableHelper.fill(stack, var10000, var10001, var10002, t + var10004 * 9, Integer.MIN_VALUE);
for(var36 = list2.iterator(); var36.hasNext(); t += 9) { for(var36 = list2.iterator(); var36.hasNext(); t += 9) {
string3 = (String)var36.next(); string3 = (String)var36.next();
y = mc.textRenderer.getStringWidth(string3); y = mc.textRenderer.getWidth(string3);
mc.textRenderer.drawWithShadow(string3, (float)(width / 2 - y / 2), (float)t, -1); mc.textRenderer.drawWithShadow(stack, string3, (float)(width / 2 - y / 2), (float)t, -1);
} }
++t; ++t;
} }
DrawableHelper.fill(width / 2 - u / 2 - 1, t - 1, width / 2 + u / 2 + 1, t + m * 9, Integer.MIN_VALUE); DrawableHelper.fill(stack, width / 2 - u / 2 - 1, t - 1, width / 2 + u / 2 + 1, t + m * 9, Integer.MIN_VALUE);
int w = mc.options.getTextBackgroundColor(553648127); int w = mc.options.getTextBackgroundColor(553648127);
int ai; int ai;
@ -132,7 +135,7 @@ public final class CustomPlayerListHud {
ai = x % m; ai = x % m;
int aa = s + y * r + y * 5; int aa = s + y * r + y * 5;
int ab = t + ai * 9; int ab = t + ai * 9;
DrawableHelper.fill(aa, ab, aa + r, ab + 8, w); DrawableHelper.fill(stack, aa, ab, aa + r, ab + 8, w);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.enableAlphaTest(); RenderSystem.enableAlphaTest();
RenderSystem.enableBlend(); RenderSystem.enableBlend();
@ -147,41 +150,42 @@ public final class CustomPlayerListHud {
mc.getTextureManager().bindTexture(player.getSkinTexture()); mc.getTextureManager().bindTexture(player.getSkinTexture());
ah = 8 + (bl2 ? 8 : 0); ah = 8 + (bl2 ? 8 : 0);
int ad = 8 * (bl2 ? -1 : 1); int ad = 8 * (bl2 ? -1 : 1);
DrawableHelper.blit(aa, ab, 8, 8, 8.0F, (float)ah, 8, ad, 64, 64); DrawableHelper.drawTexture(stack, aa, ab, 8, 8, 8.0F, (float)ah, 8, ad, 64, 64);
if (playerEntity != null && playerEntity.isPartVisible(PlayerModelPart.HAT)) { if (playerEntity != null && playerEntity.isPartVisible(PlayerModelPart.HAT)) {
int ae = 8 + (bl2 ? 8 : 0); int ae = 8 + (bl2 ? 8 : 0);
int af = 8 * (bl2 ? -1 : 1); int af = 8 * (bl2 ? -1 : 1);
DrawableHelper.blit(aa, ab, 8, 8, 40.0F, (float)ae, 8, af, 64, 64); DrawableHelper.drawTexture(stack, aa, ab, 8, 8, 40.0F, (float)ae, 8, af, 64, 64);
} }
aa += 9; aa += 9;
} }
String string4 = hud.getPlayerName(player).asFormattedString(); Text playerName = hud.getPlayerName(player);
if (player.getGameMode() == GameMode.SPECTATOR) { if (player.getGameMode() == GameMode.SPECTATOR) {
mc.textRenderer.drawWithShadow(Formatting.ITALIC + string4, (float)aa, (float)ab, -1862270977); mc.textRenderer.drawWithShadow(stack, playerName, (float)aa, (float)ab, -1862270977);
} else { } else {
mc.textRenderer.drawWithShadow(string4, (float)aa, (float)ab, -1); mc.textRenderer.drawWithShadow(stack, playerName, (float)aa, (float)ab, -1);
} }
if (obj != null && player.getGameMode() != GameMode.SPECTATOR) { if (obj != null && player.getGameMode() != GameMode.SPECTATOR) {
int ag = aa + i + 1; int ag = aa + i + 1;
ah = ag + q; ah = ag + q;
if (ah - ag > 5) { if (ah - ag > 5) {
PlayerListHudUtil.renderScoreboardObjective(hud, obj, ab, gameProfile.getName(), ag, ah, player); PlayerListHudUtil.renderScoreboardObjective(hud, stack, obj, ab, gameProfile.getName(), ag, ah, player);
} }
} }
// Here is the magic, rendering the ping text // Here is the magic, rendering the ping text
String pingString = String.format(config.getTextFormatString(), player.getLatency()); String pingString = String.format(config.getTextFormatString(), player.getLatency());
int pingStringWidth = textRenderer.getStringWidth(pingString); int pingStringWidth = textRenderer.getWidth(pingString);
textRenderer.drawWithShadow( textRenderer.draw(
stack,
pingString, pingString,
(float) r + aa - pingStringWidth + PING_TEXT_RENDER_OFFSET - (displayPlayerIcons ? PLAYER_ICON_WIDTH : 0), (float) r + aa - pingStringWidth + PING_TEXT_RENDER_OFFSET - (displayPlayerIcons ? PLAYER_ICON_WIDTH : 0),
(float) ab, (float) ab,
config.getTextColor()); config.getTextColor());
PlayerListHudUtil.renderLatencyIcon(hud, r, aa - (displayPlayerIcons ? PLAYER_ICON_WIDTH : 0), ab, player); PlayerListHudUtil.renderLatencyIcon(hud, stack ,r, aa - (displayPlayerIcons ? PLAYER_ICON_WIDTH : 0), ab, player);
} }
} }
@ -191,12 +195,12 @@ public final class CustomPlayerListHud {
var10001 = t - 1; var10001 = t - 1;
var10002 = width / 2 + u / 2 + 1; var10002 = width / 2 + u / 2 + 1;
var10004 = list3.size(); var10004 = list3.size();
DrawableHelper.fill(var10000, var10001, var10002, t + var10004 * 9, Integer.MIN_VALUE); DrawableHelper.fill(stack, var10000, var10001, var10002, t + var10004 * 9, Integer.MIN_VALUE);
for(Iterator var39 = list3.iterator(); var39.hasNext(); t += 9) { for(Iterator var39 = list3.iterator(); var39.hasNext(); t += 9) {
String string5 = (String)var39.next(); String string5 = (String)var39.next();
ai = textRenderer.getStringWidth(string5); ai = textRenderer.getWidth(string5);
textRenderer.drawWithShadow(string5, (float)(width / 2 - ai / 2), (float)t, -1); textRenderer.drawWithShadow(stack, string5, (float)(width / 2 - ai / 2), (float)t, -1);
} }
} }
} }

View file

@ -3,16 +3,17 @@ package com.vladmarica.betterpingdisplay.hud;
import com.vladmarica.betterpingdisplay.mixin.PlayerListHudAccessor; import com.vladmarica.betterpingdisplay.mixin.PlayerListHudAccessor;
import net.minecraft.client.gui.hud.PlayerListHud; import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.scoreboard.ScoreboardObjective; import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class PlayerListHudUtil { public class PlayerListHudUtil {
static void renderLatencyIcon(PlayerListHud hud, int x, int offsetX, int y, PlayerListEntry player) { static void renderLatencyIcon(PlayerListHud hud, MatrixStack stack, int x, int offsetX, int y, PlayerListEntry player) {
((PlayerListHudAccessor) hud).invokeRenderLatencyIcon(x, offsetX, y, player); ((PlayerListHudAccessor) hud).invokeRenderLatencyIcon(stack, x, offsetX, y, player);
} }
static void renderScoreboardObjective(PlayerListHud hud, ScoreboardObjective obj, int i, String str, int j, int k, PlayerListEntry player) { static void renderScoreboardObjective(PlayerListHud hud, MatrixStack stack, ScoreboardObjective obj, int i, String str, int j, int k, PlayerListEntry player) {
((PlayerListHudAccessor) hud).invokeRenderScoreboardObjective(obj, i, str, j, k, player); ((PlayerListHudAccessor) hud).invokeRenderScoreboardObjective(obj, i, str, j, k, player, stack);
} }
static Text getHeader(PlayerListHud hud) { static Text getHeader(PlayerListHud hud) {

View file

@ -3,6 +3,7 @@ package com.vladmarica.betterpingdisplay.mixin;
import com.vladmarica.betterpingdisplay.hud.CustomPlayerListHud; import com.vladmarica.betterpingdisplay.hud.CustomPlayerListHud;
import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.gui.hud.PlayerListHud; import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreboardObjective; import net.minecraft.scoreboard.ScoreboardObjective;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -12,8 +13,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(InGameHud.class) @Mixin(InGameHud.class)
abstract class InGameHudMixin { abstract class InGameHudMixin {
@Redirect(method = "render", @Redirect(method = "render",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/PlayerListHud;render(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreboardObjective;)V")) at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/PlayerListHud;render(Lnet/minecraft/client/util/math/MatrixStack;ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreboardObjective;)V"))
private void render(PlayerListHud hud, int width, Scoreboard scoreboard, ScoreboardObjective objective) { private void render(PlayerListHud hud, MatrixStack stack, int width, Scoreboard scoreboard, ScoreboardObjective objective) {
CustomPlayerListHud.render(hud, width, scoreboard, objective); CustomPlayerListHud.render(hud, stack, width, scoreboard, objective);
} }
} }

View file

@ -2,6 +2,7 @@ package com.vladmarica.betterpingdisplay.mixin;
import net.minecraft.client.gui.hud.PlayerListHud; import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.scoreboard.ScoreboardObjective; import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -11,10 +12,10 @@ import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(PlayerListHud.class) @Mixin(PlayerListHud.class)
public interface PlayerListHudAccessor { public interface PlayerListHudAccessor {
@Invoker @Invoker
void invokeRenderLatencyIcon(int x, int offsetX, int y, PlayerListEntry player); void invokeRenderLatencyIcon(MatrixStack stack, int x, int offsetX, int y, PlayerListEntry player);
@Invoker @Invoker
void invokeRenderScoreboardObjective(ScoreboardObjective obj, int i, String str, int j, int k, PlayerListEntry player); void invokeRenderScoreboardObjective(ScoreboardObjective obj, int i, String str, int j, int k, PlayerListEntry player, MatrixStack stack);
@Accessor("header") @Accessor("header")
Text getHeader(); Text getHeader();

View file

@ -1,10 +1,10 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "modid", "id": "betterpingdisplay",
"version": "1.0", "version": "1.0",
"name": "Better Ping Display", "name": "Better Ping Display",
"description": "Shows the actual ping number instead of just bars in the player list.!", "description": "Shows the actual ping number instead of just bars in the player list!",
"authors": [ "authors": [
"Quintinity" "Quintinity"
], ],
@ -28,7 +28,7 @@
"depends": { "depends": {
"fabricloader": ">=0.7.4", "fabricloader": ">=0.7.4",
"minecraft": "1.15.x" "minecraft": "1.16.x"
}, },
"suggests": { "suggests": {
"flamingo": "*" "flamingo": "*"