mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 07:11:31 +01:00
Nametags Mod
This commit is contained in:
parent
91e1f7ead6
commit
e37065a457
@ -0,0 +1,146 @@
|
||||
package net.silentclient.client.hooks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.mixin.accessors.FontRendererAccessor;
|
||||
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
|
||||
import net.silentclient.client.mods.render.NametagsMod;
|
||||
import net.silentclient.client.utils.ColorUtils;
|
||||
import net.silentclient.client.utils.Players;
|
||||
import net.silentclient.client.utils.RenderTransformer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
public class NameTagRenderingHooks {
|
||||
public static int drawNametagText(FontRenderer fontRenderer, String text, int x, int y, int color, boolean shadow) {
|
||||
int render;
|
||||
|
||||
if (shadow) {
|
||||
GL11.glDepthMask(false);
|
||||
render = ((FontRendererAccessor) fontRenderer).silent$renderString(text, x + 1.0F, y + 1.0F, color, true);
|
||||
GL11.glDepthMask(true);
|
||||
|
||||
render = Math.max(render, ((FontRendererAccessor) fontRenderer).silent$renderString(text, x, y, color, false));
|
||||
|
||||
GL11.glColorMask(false, false, false, false);
|
||||
render = Math.max(render, fontRenderer.drawString(text, x, y, color, true));
|
||||
GL11.glColorMask(true, true, true, true);
|
||||
} else {
|
||||
render = ((FontRendererAccessor) fontRenderer).silent$renderString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
public static void renderNametag(Entity entityIn, String str, double x, double y, double z, int maxDistance, boolean isMainNametag, Render render) {
|
||||
String username = "";
|
||||
double d0 = entityIn.getDistanceSqToEntity(render.getRenderManager().livingPlayer);
|
||||
|
||||
if (d0 <= (double)(maxDistance * maxDistance))
|
||||
{
|
||||
boolean fontShadow = Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Font Shadow").getValBoolean();
|
||||
boolean icons = Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Show Nametag Icons").getValBoolean();
|
||||
boolean background = !Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() || Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Background").getValBoolean();
|
||||
FontRenderer fontrenderer = render.getFontRendererFromRenderManager();
|
||||
float f = 1.6F;
|
||||
float f1 = 0.016666668F * f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float)x + 0.0F, (float)y + entityIn.height + 0.5F, (float)z);
|
||||
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
|
||||
float viewY = render.getRenderManager().playerViewY;
|
||||
float viewX = render.getRenderManager().playerViewX;
|
||||
if(Client.getInstance().getModInstances().getSnaplookMod().isActive()) {
|
||||
viewY = Client.getInstance().getModInstances().getSnaplookMod().getYaw();
|
||||
viewX = Client.getInstance().getModInstances().getSnaplookMod().getPitch();
|
||||
}
|
||||
GlStateManager.rotate(-viewY, 0.0F, 1.0F, 0.0F);
|
||||
GlStateManager.rotate(viewX * RenderTransformer.checkPerspective(), 1.0F, 0.0F, 0.0F);
|
||||
GlStateManager.scale(-f1, -f1, f1);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.depthMask(false);
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
byte b0 = 0;
|
||||
|
||||
boolean status = false;
|
||||
if(entityIn instanceof AbstractClientPlayer) {
|
||||
try {
|
||||
status = Boolean.parseBoolean(Players.getPlayerStatus(entityIn == Minecraft.getMinecraft().thePlayer, entityIn.getName().toString(), entityIn.getUniqueID(), (AbstractClientPlayer) entityIn));
|
||||
} catch(Exception e) {
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
username += str;
|
||||
|
||||
|
||||
|
||||
if (username.equals("deadmau5"))
|
||||
{
|
||||
b0 = -10;
|
||||
}
|
||||
|
||||
int i = fontrenderer.getStringWidth(username) / 2;
|
||||
GlStateManager.disableTexture2D();
|
||||
|
||||
if(background) {
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
worldrenderer.pos((double)(-i - 1), (double)(-1 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos((double)(-i - 1), (double)(8 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos((double)(i + 1), (double)(8 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos((double)(i + 1), (double)(-1 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
tessellator.draw();
|
||||
if(status && isMainNametag && icons) {
|
||||
float x1 = (-(fontrenderer.getStringWidth(entityIn.getDisplayName().getFormattedText()) >> 1) - 11);
|
||||
float x2 = (-(fontrenderer.getStringWidth(entityIn.getDisplayName().getFormattedText()) >> 1) - 1);
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
worldrenderer.pos(x1, -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos(x1, 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos(x2, 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
worldrenderer.pos(x2, -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
GlStateManager.enableTexture2D();
|
||||
NameTagRenderingHooks.drawNametagText(fontrenderer, username, -fontrenderer.getStringWidth(username) / 2, b0, 553648127, fontShadow);
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.depthMask(true);
|
||||
NameTagRenderingHooks.drawNametagText(fontrenderer, username, -fontrenderer.getStringWidth(username) / 2, b0, -1, fontShadow);
|
||||
|
||||
if(status && isMainNametag && icons) {
|
||||
try {
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.depthMask(false);
|
||||
ColorUtils.setColor(-1, 0.2F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(((AbstractClientPlayerExt) entityIn).silent$getPlayerIcon().getLocation());
|
||||
Gui.drawModalRectWithCustomSizedTexture(-fontrenderer.getStringWidth(entityIn.getDisplayName().getFormattedText()) / 2 - 11, -1, 9, 9, 9, 9, 9, 9);
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.depthMask(true);
|
||||
ColorUtils.setColor(-1);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(((AbstractClientPlayerExt) entityIn).silent$getPlayerIcon().getLocation());
|
||||
Gui.drawModalRectWithCustomSizedTexture(-fontrenderer.getStringWidth(entityIn.getDisplayName().getFormattedText()) / 2 - 11, -1, 9, 9, 9, 9, 9, 9);
|
||||
} catch (Exception err) {
|
||||
|
||||
}
|
||||
}
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.disableBlend();
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package net.silentclient.client.mixin.accessors;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(FontRenderer.class)
|
||||
public interface FontRendererAccessor {
|
||||
@Invoker("renderString") int silent$renderString(String text, float x, float y, int color, boolean dropShadow);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.entity.ArmorStandRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityArmorStand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.mods.render.NametagsMod;
|
||||
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.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ArmorStandRenderer.class)
|
||||
public abstract class ArmorStandRendererMixin {
|
||||
@Inject(method = "canRenderName(Lnet/minecraft/entity/item/EntityArmorStand;)Z", at = @At("HEAD"), cancellable = true)
|
||||
public void nametagRenderer(EntityArmorStand entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!Minecraft.isGuiEnabled() && (!Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() || !Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Show in F1").getValBoolean())) {
|
||||
cir.setReturnValue(false);
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.silentclient.client.hooks.NameTagRenderingHooks;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
@Mixin(Render.class)
|
||||
public abstract class RenderMixin<T extends Entity> {
|
||||
/**
|
||||
* @author kirillsaint
|
||||
* @reason Custom Nametag
|
||||
*/
|
||||
@Overwrite
|
||||
protected void renderLivingLabel(T entityIn, String str, double x, double y, double z, int maxDistance) {
|
||||
NameTagRenderingHooks.renderNametag(entityIn, str, x, y, z, maxDistance, false, ((Render) (Object) this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @author kirillsaint
|
||||
* @reason Custom Nametag
|
||||
*/
|
||||
@Overwrite
|
||||
protected void renderOffsetLivingLabel(T entityIn, double x, double y, double z, String str, float p_177069_9_, double p_177069_10_)
|
||||
{
|
||||
NameTagRenderingHooks.renderNametag(entityIn, str, x, y, z, 64, true, ((Render) (Object) this));
|
||||
}
|
||||
}
|
@ -1,15 +1,22 @@
|
||||
package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.cosmetics.AbstractShieldRenderer;
|
||||
import net.silentclient.client.cosmetics.BandanaRenderer;
|
||||
import net.silentclient.client.cosmetics.CapeRenderer;
|
||||
import net.silentclient.client.cosmetics.HatRenderer;
|
||||
import net.silentclient.client.cosmetics.wings.WingsModel;
|
||||
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
|
||||
import net.silentclient.client.mods.render.NametagsMod;
|
||||
import net.silentclient.client.mods.util.Server;
|
||||
import net.silentclient.client.utils.HypixelUtils;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -31,4 +38,22 @@ public abstract class RenderPlayerMixin extends RendererLivingEntity<AbstractCli
|
||||
addLayer(new HatRenderer(((RenderPlayer) (Object) this), "mask"));
|
||||
addLayer(new AbstractShieldRenderer(((RenderPlayer) (Object) this)));
|
||||
}
|
||||
|
||||
@Inject(method = "renderOffsetLivingLabel(Lnet/minecraft/client/entity/AbstractClientPlayer;DDDLjava/lang/String;FD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;renderOffsetLivingLabel(Lnet/minecraft/entity/Entity;DDDLjava/lang/String;FD)V", shift = At.Shift.BEFORE))
|
||||
public void nametags(AbstractClientPlayer entityIn, double x, double y, double z, String str, float p_177069_9_, double p_177069_10_, CallbackInfo ci) {
|
||||
boolean toggle = Client.getInstance().getModInstances().getLevelHeadMod().isEnabled();
|
||||
boolean nametagMessages = Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Show Nametag Messages").getValBoolean() && ((AbstractClientPlayerExt) entityIn).silent$getAccount() != null && ((AbstractClientPlayerExt) entityIn).silent$getAccount().showNametagMessage() && !((AbstractClientPlayerExt) entityIn).silent$getAccount().getNametagMessage().isEmpty();
|
||||
|
||||
if(toggle && Server.isHypixel()) {
|
||||
String levelhead = HypixelUtils.getHypixelLevel(entityIn == Minecraft.getMinecraft().thePlayer, entityIn.getDisplayName().getFormattedText(), entityIn.getUniqueID());
|
||||
|
||||
if(levelhead != null && levelhead != "null") {
|
||||
renderLivingLabel(entityIn, "§r" + EnumChatFormatting.AQUA + "Level: " + EnumChatFormatting.YELLOW + levelhead + "§r", x, y + ((double) ((float) getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * p_177069_9_) + (nametagMessages ? ((double) ((float) getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * p_177069_9_)) : 0)), z, 64);
|
||||
}
|
||||
}
|
||||
|
||||
if(nametagMessages) {
|
||||
renderLivingLabel(entityIn, "§r" + ((AbstractClientPlayerExt) entityIn).silent$getAccount().getNametagMessage() + "§r", x, y + ((double) ((float) getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * p_177069_9_)), z, 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityArmorStand;
|
||||
@ -10,15 +13,17 @@ import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityWaterMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.admin.AdminRender;
|
||||
import net.silentclient.client.cosmetics.gui.CosmeticsGui;
|
||||
import net.silentclient.client.event.impl.EventHitOverlay;
|
||||
import net.silentclient.client.event.impl.RenderLivingEvent;
|
||||
import net.silentclient.client.hooks.NameTagRenderingHooks;
|
||||
import net.silentclient.client.mods.render.NametagsMod;
|
||||
import net.silentclient.client.mods.settings.FPSBoostMod;
|
||||
import net.silentclient.client.utils.RenderTransformer;
|
||||
import net.silentclient.client.utils.culling.EntityCulling;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@ -84,4 +89,43 @@ public class RendererLivingEntityMixin<T extends EntityLivingBase> {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawString(Ljava/lang/String;III)I"))
|
||||
private int useShadowedNametagRendering(FontRenderer instance, String text, int x, int y, int color) {
|
||||
return NameTagRenderingHooks.drawNametagText(instance, text, x, y, color, Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Font Shadow").getValBoolean());
|
||||
}
|
||||
|
||||
@Inject(method = "canRenderName(Lnet/minecraft/entity/EntityLivingBase;)Z", at = @At("HEAD"), cancellable = true)
|
||||
public void customCanRenderName(T entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!Minecraft.isGuiEnabled() && (!Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() || !Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Show in F1").getValBoolean())) {
|
||||
cir.setReturnValue(false);
|
||||
cir.cancel();
|
||||
}
|
||||
if(entity == Minecraft.getMinecraft().getRenderManager().livingPlayer && !entity.isInvisible() && (Client.getInstance().getModInstances().getModByClass(NametagsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NametagsMod.class, "Show in F5").getValBoolean()) && !(Minecraft.getMinecraft().currentScreen instanceof GuiContainer) && !(Minecraft.getMinecraft().currentScreen instanceof CosmeticsGui) && !(Minecraft.getMinecraft().currentScreen instanceof AdminRender)) {
|
||||
cir.setReturnValue(true);
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/RenderManager;playerViewX:F")
|
||||
)
|
||||
private float fixNametagPerspectiveX(RenderManager instance) {
|
||||
if(Client.getInstance().getModInstances().getSnaplookMod().isActive()) {
|
||||
return Client.getInstance().getModInstances().getSnaplookMod().getPitch();
|
||||
}
|
||||
return instance.playerViewX * RenderTransformer.checkPerspective();
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/RenderManager;playerViewY:F")
|
||||
)
|
||||
private float fixNametagPerspectiveY(RenderManager instance) {
|
||||
if(Client.getInstance().getModInstances().getSnaplookMod().isActive()) {
|
||||
return Client.getInstance().getModInstances().getSnaplookMod().getYaw();
|
||||
}
|
||||
return instance.playerViewY;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,9 @@
|
||||
"mixins.GuiContainerMixin",
|
||||
"mixins.InventoryEffectRendererMixin",
|
||||
"mixins.TextureManagerMixin",
|
||||
"mixins.ChunkMixin"
|
||||
"mixins.ChunkMixin",
|
||||
"mixins.ArmorStandRendererMixin",
|
||||
"mixins.RenderMixin",
|
||||
"accessors.FontRendererAccessor"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user