Skip to content

Commit

Permalink
1.0.9
Browse files Browse the repository at this point in the history
properly fix essential
  • Loading branch information
Wyvest committed Dec 24, 2024
1 parent 77ef160 commit 21b1f4d
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod_name=PolyNametag
# Sets the id of your mod that mod loaders use to recognize it.
mod_id=polynametag
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
mod_version=1.0.8
mod_version=1.0.9
# Sets the name of the jar file that you put in your 'mods' folder.
mod_archives_name=PolyNametag

Expand Down
12 changes: 12 additions & 0 deletions src/dummy/java/gg/essential/cosmetics/CosmeticsRenderState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gg.essential.cosmetics;

import net.minecraft.client.entity.AbstractClientPlayer;

public interface CosmeticsRenderState {
final class Live implements CosmeticsRenderState {

@SuppressWarnings("unused")
public Live(AbstractClientPlayer player) {
}
}
}
4 changes: 4 additions & 0 deletions src/dummy/java/gg/essential/handlers/OnlineIndicator.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package gg.essential.handlers;

import gg.essential.cosmetics.CosmeticsRenderState;
import gg.essential.universal.UMatrixStack;
import net.minecraft.entity.Entity;

public class OnlineIndicator {
public static void drawNametagIndicator(UMatrixStack matrixStack, Entity entity, String str, int light) {
}

public static void drawNametagIndicator(UMatrixStack matrixStack, CosmeticsRenderState state, String str, int light) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -92,7 +93,7 @@ private void drawBG(Entity entityIn, String str, double x, double y, double z, i
@Inject(method = "renderLivingLabel", at = @At("HEAD"), cancellable = true)
private void move(Entity entityIn, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
//PolyNametag.INSTANCE.setShouldDrawIndicator(PolyNametag.INSTANCE.getDrawingPlayerName() && NametagRenderingKt.canDrawIndicator(entityIn));
PolyNametag.INSTANCE.setShouldDrawIndicator(PolyNametag.INSTANCE.getDrawingPlayerName() && NametagRenderingKt.canDrawIndicator(entityIn));
PolyNametag.INSTANCE.setDrawingPlayerName(false);
if (!PolyNametag.INSTANCE.getDrawingTags() && PolyNametag.INSTANCE.getDrawingWorld()) {
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.LabelInfo((Render<Entity>) (Object) this, entityIn, str, x, y, z, maxDistance));
Expand All @@ -117,8 +118,8 @@ private void essential(Entity entityIn, String str, double x, double y, double z
if (!ModConfig.INSTANCE.enabled) return;
PolyNametag instance = PolyNametag.INSTANCE;
if (instance.isEssential() && instance.getShouldDrawIndicator()) {
//NametagRenderingKt.drawIndicator(entityIn, str);
//instance.setShouldDrawIndicator(false);
NametagRenderingKt.drawIndicator(entityIn, str, (((int) OpenGlHelper.lastBrightnessY) << 16) + (int) OpenGlHelper.lastBrightnessX);
instance.setShouldDrawIndicator(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
Expand Down Expand Up @@ -110,7 +111,7 @@ private void drawBG(EntityLivingBase entity, double x, double y, double z, Callb
@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true)
private void move(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
//PolyNametag.INSTANCE.setShouldDrawIndicator(NametagRenderingKt.canDrawIndicator(entity));
PolyNametag.INSTANCE.setShouldDrawIndicator(NametagRenderingKt.canDrawIndicator(entity));
if (!PolyNametag.INSTANCE.getDrawingTags() && PolyNametag.INSTANCE.getDrawingWorld()) {
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.NameInfo((RendererLivingEntity<EntityLivingBase>) (Object) this, entity, x, y, z));
ci.cancel();
Expand All @@ -122,8 +123,8 @@ private void essential(EntityLivingBase entity, double x, double y, double z, Ca
if (!ModConfig.INSTANCE.enabled) return;
PolyNametag instance = PolyNametag.INSTANCE;
if (instance.isEssential() && instance.getShouldDrawIndicator()) {
//NametagRenderingKt.drawIndicator(entity, entity.getDisplayName().getFormattedText());
//instance.setShouldDrawIndicator(false);
NametagRenderingKt.drawIndicator(entity, entity.getDisplayName().getFormattedText(), (((int) OpenGlHelper.lastBrightnessY) << 16) + (int) OpenGlHelper.lastBrightnessX);
instance.setShouldDrawIndicator(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package org.polyfrost.polynametag.mixin.essential;

import gg.essential.universal.UMatrixStack;
import net.minecraft.entity.Entity;
import org.polyfrost.polynametag.PolyNametag;
import org.polyfrost.polynametag.config.ModConfig;
import org.polyfrost.polynametag.render.NametagRenderingKt;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

Expand All @@ -21,7 +17,7 @@ public class OnlineIndicatorMixin {

@Dynamic("Essential")
@ModifyArgs(
method = "drawNametagIndicator(Lgg/essential/universal/UMatrixStack;Lnet/minecraft/entity/Entity;Ljava/lang/String;I)V",
method = "drawNametagIndicator",
at = @At(
remap = false,
value = "INVOKE",
Expand All @@ -35,14 +31,14 @@ public class OnlineIndicatorMixin {

@Dynamic("Essential")
@Inject(method = "drawNametagIndicator", at = @At("HEAD"), cancellable = true)
private static void skip(UMatrixStack matrixStack, Entity entity, String str, int light, CallbackInfo ci) {
private static void skip(UMatrixStack matrixStack, @Coerce Object entity, String str, int light, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
if (!PolyNametag.INSTANCE.getDrawingIndicator()) ci.cancel();
}

@Dynamic("Essential")
@ModifyArg(
method = "drawNametagIndicator(Lgg/essential/universal/UMatrixStack;Lnet/minecraft/entity/Entity;Ljava/lang/String;I)V",
method = "drawNametagIndicator",
at = @At(
value = "INVOKE",
target = "Lgg/essential/universal/UGraphics;pos(Lgg/essential/universal/UMatrixStack;DDD)V",
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/org/polyfrost/polynametag/render/EssentialBSManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.polyfrost.polynametag.render;

import gg.essential.universal.UMatrixStack;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.Entity;
import org.polyfrost.polynametag.PolyNametag;
import org.polyfrost.polynametag.render.icon.EssentialIconRender;

import java.util.UUID;

public class EssentialBSManager {

public enum IconRenderType {
NONE,
PRE_1354,
V1354
}

private final EssentialIconRender iconRender;

public EssentialBSManager() {
IconRenderType iconRenderType1 = IconRenderType.NONE;

if (PolyNametag.INSTANCE.isEssential()) {
try {
// Reflective access to OnboardingData.hasAcceptedTos()
Class<?> onboardingDataClass = Class.forName("gg.essential.data.OnboardingData");
onboardingDataClass.getDeclaredMethod("hasAcceptedTos");

// Reflective access to EssentialConfig.getShowEssentialIndicatorOnNametag()
Class<?> essentialConfigClass = Class.forName("gg.essential.config.EssentialConfig");
essentialConfigClass.getDeclaredMethod("getShowEssentialIndicatorOnNametag");

// Reflective access to EssentialConfig.INSTANCE
essentialConfigClass.getDeclaredField("INSTANCE");

// Reflective access to Essential.getConnectionManager()
Class<?> essentialClass = Class.forName("gg.essential.Essential");
essentialClass.getDeclaredMethod("getConnectionManager");

// Reflective access to Essential.getInstance()
essentialClass.getDeclaredMethod("getInstance");

// Reflective access to ConnectionManager.getProfileManager()
Class<?> connectionManagerClass = Class.forName("gg.essential.network.connectionmanager.ConnectionManager");
connectionManagerClass.getDeclaredMethod("getProfileManager");

// Reflective access to ProfileManager.getStatus()
Class<?> profileManagerClass = Class.forName("gg.essential.network.connectionmanager.profile.ProfileManager");
Class<?> profileStatusClass = Class.forName("gg.essential.connectionmanager.common.enums.ProfileStatus");
profileManagerClass.getDeclaredMethod("getStatus", UUID.class);

// Reflective access to ProfileStatus.OFFLINE
profileStatusClass.getDeclaredField("OFFLINE");

try {
// Reflective access to CosmeticsRenderState$Live constructor
Class<?> cosmeticsRenderStateClass = Class.forName("gg.essential.cosmetics.CosmeticsRenderState$Live");
cosmeticsRenderStateClass.getDeclaredConstructor(AbstractClientPlayer.class);

// Reflective access to OnlineIndicator.drawNametagIndicator()
Class<?> onlineIndicatorClass = Class.forName("gg.essential.handlers.OnlineIndicator");
Class<?> uMatrixStackClass = Class.forName("gg.essential.universal.UMatrixStack");
onlineIndicatorClass.getDeclaredMethod("drawNametagIndicator",
uMatrixStackClass, Class.forName("gg.essential.cosmetics.CosmeticsRenderState"), String.class, int.class);
iconRenderType1 = IconRenderType.V1354;
} catch (Exception e) {
iconRenderType1 = IconRenderType.PRE_1354;
try {
// Reflective access to OnlineIndicator.drawNametagIndicator()
Class<?> onlineIndicatorClass = Class.forName("gg.essential.handlers.OnlineIndicator");
Class<?> uMatrixStackClass = Class.forName("gg.essential.universal.UMatrixStack");
onlineIndicatorClass.getDeclaredMethod("drawNametagIndicator",
uMatrixStackClass, Entity.class, String.class, int.class);
} catch (Exception e2) {
e.printStackTrace();
e2.printStackTrace();
iconRenderType1 = IconRenderType.NONE;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
IconRenderType iconRenderType = iconRenderType1;
EssentialIconRender iconRender1;
switch (iconRenderType) {
case V1354:
try {
iconRender1 = Class.forName("org.polyfrost.polynametag.render.icon.V1354IconRender").asSubclass(EssentialIconRender.class).getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
iconRender1 = null;
}
break;
case PRE_1354:
try {
iconRender1 = Class.forName("org.polyfrost.polynametag.render.icon.Pre1354IconRender").asSubclass(EssentialIconRender.class).getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
iconRender1 = null;
}
break;
default:
iconRender1 = null;
break;
}
iconRender = iconRender1;
}

public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
if (iconRender != null) {
iconRender.drawIndicator(matrices, entity, str, light);
}
}

public boolean canDrawIndicator(Entity entity) {
if (iconRender != null) {
return iconRender.canDrawIndicator(entity);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.polyfrost.polynametag.render.icon;

import gg.essential.universal.UMatrixStack;
import net.minecraft.entity.Entity;

public interface EssentialIconRender {
void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light);
boolean canDrawIndicator(Entity entity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.polyfrost.polynametag.render.icon;

import gg.essential.Essential;
import gg.essential.config.EssentialConfig;
import gg.essential.connectionmanager.common.enums.ProfileStatus;
import gg.essential.data.OnboardingData;
import gg.essential.handlers.OnlineIndicator;
import gg.essential.universal.UMatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;

public class Pre1354IconRender implements EssentialIconRender {
@Override
public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
OnlineIndicator.drawNametagIndicator(matrices, entity, str, light);
}

@Override
public boolean canDrawIndicator(Entity entity) {
if (OnboardingData.hasAcceptedTos() && EssentialConfig.INSTANCE.getShowEssentialIndicatorOnNametag() && entity instanceof EntityPlayer) {
return Essential.getInstance().getConnectionManager().getProfileManager().getStatus(((EntityPlayer) entity).getGameProfile().getId()) != ProfileStatus.OFFLINE;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.polyfrost.polynametag.render.icon;

import gg.essential.Essential;
import gg.essential.config.EssentialConfig;
import gg.essential.connectionmanager.common.enums.ProfileStatus;
import gg.essential.cosmetics.CosmeticsRenderState;
import gg.essential.data.OnboardingData;
import gg.essential.handlers.OnlineIndicator;
import gg.essential.universal.UMatrixStack;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;

public class V1354IconRender implements EssentialIconRender {
@Override
public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
OnlineIndicator.drawNametagIndicator(matrices, new CosmeticsRenderState.Live(((AbstractClientPlayer) entity)), str, light);
}

@Override
public boolean canDrawIndicator(Entity entity) {
if (OnboardingData.hasAcceptedTos() && EssentialConfig.INSTANCE.getShowEssentialIndicatorOnNametag() && entity instanceof AbstractClientPlayer) {
return Essential.getInstance().getConnectionManager().getProfileManager().getStatus(((EntityPlayer) entity).getGameProfile().getId()) != ProfileStatus.OFFLINE;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ import cc.polyfrost.oneconfig.renderer.TextRenderer
import cc.polyfrost.oneconfig.utils.dsl.getAlpha
import cc.polyfrost.oneconfig.utils.dsl.mc
import club.sk1er.patcher.config.PatcherConfig
import gg.essential.Essential
import gg.essential.config.EssentialConfig
import gg.essential.connectionmanager.common.enums.ProfileStatus
import gg.essential.data.OnboardingData
import gg.essential.handlers.OnlineIndicator
import gg.essential.universal.UMatrixStack
import net.minecraft.client.entity.AbstractClientPlayer
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import org.lwjgl.opengl.GL11
import org.polyfrost.polynametag.PolyNametag
import org.polyfrost.polynametag.PolyNametag.drawingIndicator
Expand All @@ -26,6 +21,8 @@ var drawingText = false

var drawingWithDepth = false

private val essentialBSManager = EssentialBSManager()

internal fun shouldDrawBackground() =
ModConfig.background && (!PolyNametag.isPatcher || !PatcherConfig.disableNametagBoxes)
fun getBackBackgroundAlpha(): Int = if (shouldDrawBackground()) ModConfig.backgroundColor.alpha.coerceAtMost(63) else 0
Expand Down Expand Up @@ -97,22 +94,16 @@ fun drawBackground(xStart: Double, xEnd: Double, red: Int, green: Int, blue: Int
GL11.glDisable(GL11.GL_LINE_SMOOTH)
}

//fun drawIndicator(entity: Entity, string: String) {
// if (entity !is EntityPlayer) return
// drawingIndicator = true
// OnlineIndicator.drawNametagIndicator(UMatrixStack(), entity, string, 0)
// drawingIndicator = false
//}

//fun Entity.canDrawIndicator(): Boolean {
// if (!PolyNametag.isEssential) return false
// if (OnboardingData.hasAcceptedTos() && EssentialConfig.showEssentialIndicatorOnNametag && this is EntityPlayer) {
// if (Essential.getInstance().connectionManager.profileManager.getStatus(this.gameProfile.id) != ProfileStatus.OFFLINE) {
// return true
// }
// }
// return false
//}
fun drawIndicator(entity: Entity, string: String, light: Int) {
if (entity !is AbstractClientPlayer) return
drawingIndicator = true
essentialBSManager.drawIndicator(UMatrixStack(), entity, string, light)
drawingIndicator = false
}

fun Entity.canDrawIndicator(): Boolean {
return essentialBSManager.canDrawIndicator(this)
}

internal fun FontRenderer.drawStringWithoutZFighting(text: String, x: Float, y: Float, color: Int): Int {
if (this !is FontRendererAccessor) return 0
Expand Down

0 comments on commit 21b1f4d

Please sign in to comment.