This commit is contained in:
kirillsaint 2023-07-01 17:49:31 +06:00
parent 924859dfd1
commit 5161ddf1ad
3 changed files with 162 additions and 1 deletions

View File

@ -0,0 +1,159 @@
package net.silentclient.client.mixin.mixins;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiPlayerTabOverlay;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.Client;
import net.silentclient.client.cosmetics.StaticResourceLocation;
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
import net.silentclient.client.mixin.ducks.TextureManagerExt;
import net.silentclient.client.mods.render.TabMod;
import net.silentclient.client.utils.Players;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.List;
@Mixin(GuiPlayerTabOverlay.class)
public class GuiPlayerTabOverlayMixin {
@Shadow @Final private Minecraft mc;
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;listFormattedStringToWidth(Ljava/lang/String;I)Ljava/util/List;", ordinal = 0))
public List<String> disableHeader(FontRenderer instance, String str, int wrapWidth) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && (Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Disable Header").getValBoolean())) {
return new ArrayList();
}
return instance.listFormattedStringToWidth(str, wrapWidth);
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiPlayerTabOverlay;drawRect(IIIII)V", ordinal = 0))
public void disableHeaderBackground(int i1, int i2, int i3, int i4, int i5) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && (Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Disable Header").getValBoolean() || !Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Background").getValBoolean())) {
return;
}
Gui.drawRect(i1, i2, i3, i4, i5);
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;listFormattedStringToWidth(Ljava/lang/String;I)Ljava/util/List;", ordinal = 1))
public List<String> disableFooter(FontRenderer instance, String str, int wrapWidth) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Disable Footer").getValBoolean()) {
return new ArrayList();
}
return instance.listFormattedStringToWidth(str, wrapWidth);
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiPlayerTabOverlay;drawRect(IIIII)V", ordinal = 3))
public void disableFooterBackground(int i1, int i2, int i3, int i4, int i5) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && (Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Disable Footer").getValBoolean() || !Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Background").getValBoolean())) {
return;
}
Gui.drawRect(i1, i2, i3, i4, i5);
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiPlayerTabOverlay;drawRect(IIIII)V", ordinal = 1))
public void disableBackground1(int i1, int i2, int i3, int i4, int i5) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && !Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Background").getValBoolean()) {
return;
}
Gui.drawRect(i1, i2, i3, i4, i5);
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiPlayerTabOverlay;drawRect(IIIII)V", ordinal = 2))
public void disableBackground2(int i1, int i2, int i3, int i4, int i5) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && !Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Background").getValBoolean()) {
return;
}
Gui.drawRect(i1, i2, i3, i4, i5);
}
@Inject(method = "drawPing", at = @At("HEAD"), cancellable = true)
public void numbersPing(int p_175245_1_, int p_175245_2_, int p_175245_3_, NetworkPlayerInfo networkPlayerInfoIn, CallbackInfo ci) {
if(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Show Ping Numbers").getValBoolean()) {
EntityPlayer entityplayer = this.mc.theWorld.getPlayerEntityByUUID(networkPlayerInfoIn.getGameProfile().getId());
int ping = 0;
if(entityplayer == null || entityplayer != mc.thePlayer) {
ping = networkPlayerInfoIn.getResponseTime();
}
if(entityplayer != null && entityplayer == mc.thePlayer) {
ping = Client.getInstance().ping;
}
int x = (p_175245_2_ + p_175245_1_) - (mc.fontRendererObj.getStringWidth(String.valueOf(ping)) >> 1) - 2;
int y = p_175245_3_ + 2;
int color;
if (ping > 500) {
color = 11141120;
} else if (ping > 300) {
color = 11184640;
} else if (ping > 200) {
color = 11193344;
} else if (ping > 135) {
color = 2128640;
} else if (ping > 70) {
color = 39168;
} else if (ping >= 0) {
color = 47872;
} else {
color = 11141120;
}
GlStateManager.pushMatrix();
GlStateManager.scale(0.5f, 0.5f, 0.5f);
mc.fontRendererObj.drawStringWithShadow(" " + (ping == 0 ? "?" : ping), (2 * x) - 10, 2 * y, color);
GlStateManager.scale(2.0f, 2.0f, 2.0f);
GlStateManager.popMatrix();
ci.cancel();
}
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V"))
public void nametagIcon1(TextureManager instance, ResourceLocation resource) {
if(!(Client.getInstance().getModInstances().getModByClass(TabMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(TabMod.class, "Show Nametag Icons").getValBoolean())) {
((TextureManagerExt) instance).waitBindTexture(new StaticResourceLocation(resource.getResourcePath()));
}
}
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetworkPlayerInfo;getGameProfile()Lcom/mojang/authlib/GameProfile;"))
public GameProfile nametagIcon2(NetworkPlayerInfo instance) {
GameProfile gameprofile = instance.getGameProfile();
if(this.mc.isIntegratedServerRunning() || this.mc.getNetHandler().getNetworkManager().getIsencrypted()) {
boolean isSilent = false;
EntityPlayer entityplayer = this.mc.theWorld.getPlayerEntityByUUID(gameprofile.getId());
try {
isSilent = Boolean.parseBoolean(Players.getPlayerStatus(entityplayer == mc.thePlayer, entityplayer.getName().toString(), entityplayer.getUniqueID(), (AbstractClientPlayer) entityplayer));
} catch (Exception e) {
isSilent = false;
}
if(isSilent && ((AbstractClientPlayerExt) entityplayer).silent$getPlayerIcon() != null) {
this.mc.getTextureManager().bindTexture(((AbstractClientPlayerExt) entityplayer).silent$getPlayerIcon().getLocation());
}
}
return gameprofile;
}
}

View File

@ -15,5 +15,6 @@ public class TabMod extends Mod {
this.addBooleanSetting("Disable Header", this, false);
this.addBooleanSetting("Disable Footer", this, false);
this.addBooleanSetting("Show Ping Numbers", this, true);
this.addBooleanSetting("Show Nametag Icons", this, true);
}
}

View File

@ -48,6 +48,7 @@
"mixins.RenderMixin",
"accessors.FontRendererAccessor",
"mixins.FontRendererMixin",
"mixins.WorldInfoMixin"
"mixins.WorldInfoMixin",
"mixins.GuiPlayerTabOverlayMixin"
]
}