51 lines
2 KiB
Java
51 lines
2 KiB
Java
package net.saltymc.eaa.mixin;
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.gui.hud.PlayerListHud;
|
|
import net.minecraft.client.network.PlayerListEntry;
|
|
import net.minecraft.client.util.math.MatrixStack;
|
|
import net.saltymc.eaa.custom.ping.CustomPlayerListHud;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.Unique;
|
|
import org.spongepowered.asm.mixin.injection.*;
|
|
|
|
/**
|
|
* By: https://github.com/vladmarica/better-ping-display-fabric/
|
|
*/
|
|
|
|
@Mixin(PlayerListHud.class)
|
|
public abstract class PlayerListHudMixin {
|
|
@Unique
|
|
@Final
|
|
private static final int PLAYER_SLOT_EXTRA_WIDTH = 70; // 45
|
|
|
|
@Shadow
|
|
@Final
|
|
private MinecraftClient client;
|
|
|
|
/**
|
|
* Increases the int constant {@code 13} in the {@link PlayerListHud#render} method by
|
|
* {@value #PLAYER_SLOT_EXTRA_WIDTH}. This constant is used to define the width of the "slots" in the player list.
|
|
* In order to fit the ping text, this needs to be increased.
|
|
*/
|
|
@ModifyConstant(method = "render", constant = @Constant(intValue = 13))
|
|
private int modifySlotWidthConstant(int original) {
|
|
return original + PLAYER_SLOT_EXTRA_WIDTH;
|
|
}
|
|
|
|
/**
|
|
* Redirects the call to {@code renderLatencyIcon} in {@link PlayerListHud#render} to instead call
|
|
* {@link CustomPlayerListHud#renderPingDisplay}.
|
|
*/
|
|
@Redirect(method = "render",
|
|
at = @At(value = "INVOKE", target = "net/minecraft/client/gui/hud/PlayerListHud.renderLatencyIcon(Lnet/minecraft/client/util/math/MatrixStack;IIILnet/minecraft/client/network/PlayerListEntry;)V"))
|
|
private void redirectRenderLatencyIconCall(
|
|
PlayerListHud instance, MatrixStack matrices, int width, int x, int y, @NotNull PlayerListEntry entry) {
|
|
CustomPlayerListHud.renderPingDisplay(client, instance, matrices, width, x, y, entry);
|
|
}
|
|
}
|
|
|