Skip to content

Commit 21b1f4d

Browse files
committed
1.0.9
properly fix essential
1 parent 77ef160 commit 21b1f4d

File tree

11 files changed

+226
-37
lines changed

11 files changed

+226
-37
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod_name=PolyNametag
55
# Sets the id of your mod that mod loaders use to recognize it.
66
mod_id=polynametag
77
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
8-
mod_version=1.0.8
8+
mod_version=1.0.9
99
# Sets the name of the jar file that you put in your 'mods' folder.
1010
mod_archives_name=PolyNametag
1111

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package gg.essential.cosmetics;
2+
3+
import net.minecraft.client.entity.AbstractClientPlayer;
4+
5+
public interface CosmeticsRenderState {
6+
final class Live implements CosmeticsRenderState {
7+
8+
@SuppressWarnings("unused")
9+
public Live(AbstractClientPlayer player) {
10+
}
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package gg.essential.handlers;
22

3+
import gg.essential.cosmetics.CosmeticsRenderState;
34
import gg.essential.universal.UMatrixStack;
45
import net.minecraft.entity.Entity;
56

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

11+
public static void drawNametagIndicator(UMatrixStack matrixStack, CosmeticsRenderState state, String str, int light) {
12+
}
13+
1014
}

src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.client.Minecraft;
44
import net.minecraft.client.gui.FontRenderer;
55
import net.minecraft.client.renderer.GlStateManager;
6+
import net.minecraft.client.renderer.OpenGlHelper;
67
import net.minecraft.client.renderer.Tessellator;
78
import net.minecraft.client.renderer.entity.Render;
89
import net.minecraft.entity.Entity;
@@ -92,7 +93,7 @@ private void drawBG(Entity entityIn, String str, double x, double y, double z, i
9293
@Inject(method = "renderLivingLabel", at = @At("HEAD"), cancellable = true)
9394
private void move(Entity entityIn, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) {
9495
if (!ModConfig.INSTANCE.enabled) return;
95-
//PolyNametag.INSTANCE.setShouldDrawIndicator(PolyNametag.INSTANCE.getDrawingPlayerName() && NametagRenderingKt.canDrawIndicator(entityIn));
96+
PolyNametag.INSTANCE.setShouldDrawIndicator(PolyNametag.INSTANCE.getDrawingPlayerName() && NametagRenderingKt.canDrawIndicator(entityIn));
9697
PolyNametag.INSTANCE.setDrawingPlayerName(false);
9798
if (!PolyNametag.INSTANCE.getDrawingTags() && PolyNametag.INSTANCE.getDrawingWorld()) {
9899
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.LabelInfo((Render<Entity>) (Object) this, entityIn, str, x, y, z, maxDistance));
@@ -117,8 +118,8 @@ private void essential(Entity entityIn, String str, double x, double y, double z
117118
if (!ModConfig.INSTANCE.enabled) return;
118119
PolyNametag instance = PolyNametag.INSTANCE;
119120
if (instance.isEssential() && instance.getShouldDrawIndicator()) {
120-
//NametagRenderingKt.drawIndicator(entityIn, str);
121-
//instance.setShouldDrawIndicator(false);
121+
NametagRenderingKt.drawIndicator(entityIn, str, (((int) OpenGlHelper.lastBrightnessY) << 16) + (int) OpenGlHelper.lastBrightnessX);
122+
instance.setShouldDrawIndicator(false);
122123
}
123124
}
124125

src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.client.Minecraft;
44
import net.minecraft.client.gui.FontRenderer;
55
import net.minecraft.client.renderer.GlStateManager;
6+
import net.minecraft.client.renderer.OpenGlHelper;
67
import net.minecraft.client.renderer.Tessellator;
78
import net.minecraft.client.renderer.entity.RenderManager;
89
import net.minecraft.client.renderer.entity.RendererLivingEntity;
@@ -110,7 +111,7 @@ private void drawBG(EntityLivingBase entity, double x, double y, double z, Callb
110111
@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true)
111112
private void move(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) {
112113
if (!ModConfig.INSTANCE.enabled) return;
113-
//PolyNametag.INSTANCE.setShouldDrawIndicator(NametagRenderingKt.canDrawIndicator(entity));
114+
PolyNametag.INSTANCE.setShouldDrawIndicator(NametagRenderingKt.canDrawIndicator(entity));
114115
if (!PolyNametag.INSTANCE.getDrawingTags() && PolyNametag.INSTANCE.getDrawingWorld()) {
115116
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.NameInfo((RendererLivingEntity<EntityLivingBase>) (Object) this, entity, x, y, z));
116117
ci.cancel();
@@ -122,8 +123,8 @@ private void essential(EntityLivingBase entity, double x, double y, double z, Ca
122123
if (!ModConfig.INSTANCE.enabled) return;
123124
PolyNametag instance = PolyNametag.INSTANCE;
124125
if (instance.isEssential() && instance.getShouldDrawIndicator()) {
125-
//NametagRenderingKt.drawIndicator(entity, entity.getDisplayName().getFormattedText());
126-
//instance.setShouldDrawIndicator(false);
126+
NametagRenderingKt.drawIndicator(entity, entity.getDisplayName().getFormattedText(), (((int) OpenGlHelper.lastBrightnessY) << 16) + (int) OpenGlHelper.lastBrightnessX);
127+
instance.setShouldDrawIndicator(false);
127128
}
128129
}
129130
}

src/main/java/org/polyfrost/polynametag/mixin/essential/OnlineIndicatorMixin.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package org.polyfrost.polynametag.mixin.essential;
22

33
import gg.essential.universal.UMatrixStack;
4-
import net.minecraft.entity.Entity;
54
import org.polyfrost.polynametag.PolyNametag;
65
import org.polyfrost.polynametag.config.ModConfig;
76
import org.polyfrost.polynametag.render.NametagRenderingKt;
87
import org.spongepowered.asm.mixin.Dynamic;
98
import org.spongepowered.asm.mixin.Mixin;
109
import org.spongepowered.asm.mixin.Pseudo;
11-
import org.spongepowered.asm.mixin.injection.At;
12-
import org.spongepowered.asm.mixin.injection.Inject;
13-
import org.spongepowered.asm.mixin.injection.ModifyArg;
14-
import org.spongepowered.asm.mixin.injection.ModifyArgs;
10+
import org.spongepowered.asm.mixin.injection.*;
1511
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1612
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
1713

@@ -21,7 +17,7 @@ public class OnlineIndicatorMixin {
2117

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

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

4339
@Dynamic("Essential")
4440
@ModifyArg(
45-
method = "drawNametagIndicator(Lgg/essential/universal/UMatrixStack;Lnet/minecraft/entity/Entity;Ljava/lang/String;I)V",
41+
method = "drawNametagIndicator",
4642
at = @At(
4743
value = "INVOKE",
4844
target = "Lgg/essential/universal/UGraphics;pos(Lgg/essential/universal/UMatrixStack;DDD)V",
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package org.polyfrost.polynametag.render;
2+
3+
import gg.essential.universal.UMatrixStack;
4+
import net.minecraft.client.entity.AbstractClientPlayer;
5+
import net.minecraft.entity.Entity;
6+
import org.polyfrost.polynametag.PolyNametag;
7+
import org.polyfrost.polynametag.render.icon.EssentialIconRender;
8+
9+
import java.util.UUID;
10+
11+
public class EssentialBSManager {
12+
13+
public enum IconRenderType {
14+
NONE,
15+
PRE_1354,
16+
V1354
17+
}
18+
19+
private final EssentialIconRender iconRender;
20+
21+
public EssentialBSManager() {
22+
IconRenderType iconRenderType1 = IconRenderType.NONE;
23+
24+
if (PolyNametag.INSTANCE.isEssential()) {
25+
try {
26+
// Reflective access to OnboardingData.hasAcceptedTos()
27+
Class<?> onboardingDataClass = Class.forName("gg.essential.data.OnboardingData");
28+
onboardingDataClass.getDeclaredMethod("hasAcceptedTos");
29+
30+
// Reflective access to EssentialConfig.getShowEssentialIndicatorOnNametag()
31+
Class<?> essentialConfigClass = Class.forName("gg.essential.config.EssentialConfig");
32+
essentialConfigClass.getDeclaredMethod("getShowEssentialIndicatorOnNametag");
33+
34+
// Reflective access to EssentialConfig.INSTANCE
35+
essentialConfigClass.getDeclaredField("INSTANCE");
36+
37+
// Reflective access to Essential.getConnectionManager()
38+
Class<?> essentialClass = Class.forName("gg.essential.Essential");
39+
essentialClass.getDeclaredMethod("getConnectionManager");
40+
41+
// Reflective access to Essential.getInstance()
42+
essentialClass.getDeclaredMethod("getInstance");
43+
44+
// Reflective access to ConnectionManager.getProfileManager()
45+
Class<?> connectionManagerClass = Class.forName("gg.essential.network.connectionmanager.ConnectionManager");
46+
connectionManagerClass.getDeclaredMethod("getProfileManager");
47+
48+
// Reflective access to ProfileManager.getStatus()
49+
Class<?> profileManagerClass = Class.forName("gg.essential.network.connectionmanager.profile.ProfileManager");
50+
Class<?> profileStatusClass = Class.forName("gg.essential.connectionmanager.common.enums.ProfileStatus");
51+
profileManagerClass.getDeclaredMethod("getStatus", UUID.class);
52+
53+
// Reflective access to ProfileStatus.OFFLINE
54+
profileStatusClass.getDeclaredField("OFFLINE");
55+
56+
try {
57+
// Reflective access to CosmeticsRenderState$Live constructor
58+
Class<?> cosmeticsRenderStateClass = Class.forName("gg.essential.cosmetics.CosmeticsRenderState$Live");
59+
cosmeticsRenderStateClass.getDeclaredConstructor(AbstractClientPlayer.class);
60+
61+
// Reflective access to OnlineIndicator.drawNametagIndicator()
62+
Class<?> onlineIndicatorClass = Class.forName("gg.essential.handlers.OnlineIndicator");
63+
Class<?> uMatrixStackClass = Class.forName("gg.essential.universal.UMatrixStack");
64+
onlineIndicatorClass.getDeclaredMethod("drawNametagIndicator",
65+
uMatrixStackClass, Class.forName("gg.essential.cosmetics.CosmeticsRenderState"), String.class, int.class);
66+
iconRenderType1 = IconRenderType.V1354;
67+
} catch (Exception e) {
68+
iconRenderType1 = IconRenderType.PRE_1354;
69+
try {
70+
// Reflective access to OnlineIndicator.drawNametagIndicator()
71+
Class<?> onlineIndicatorClass = Class.forName("gg.essential.handlers.OnlineIndicator");
72+
Class<?> uMatrixStackClass = Class.forName("gg.essential.universal.UMatrixStack");
73+
onlineIndicatorClass.getDeclaredMethod("drawNametagIndicator",
74+
uMatrixStackClass, Entity.class, String.class, int.class);
75+
} catch (Exception e2) {
76+
e.printStackTrace();
77+
e2.printStackTrace();
78+
iconRenderType1 = IconRenderType.NONE;
79+
}
80+
}
81+
} catch (Exception e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
IconRenderType iconRenderType = iconRenderType1;
86+
EssentialIconRender iconRender1;
87+
switch (iconRenderType) {
88+
case V1354:
89+
try {
90+
iconRender1 = Class.forName("org.polyfrost.polynametag.render.icon.V1354IconRender").asSubclass(EssentialIconRender.class).getDeclaredConstructor().newInstance();
91+
} catch (Exception e) {
92+
e.printStackTrace();
93+
iconRender1 = null;
94+
}
95+
break;
96+
case PRE_1354:
97+
try {
98+
iconRender1 = Class.forName("org.polyfrost.polynametag.render.icon.Pre1354IconRender").asSubclass(EssentialIconRender.class).getDeclaredConstructor().newInstance();
99+
} catch (Exception e) {
100+
e.printStackTrace();
101+
iconRender1 = null;
102+
}
103+
break;
104+
default:
105+
iconRender1 = null;
106+
break;
107+
}
108+
iconRender = iconRender1;
109+
}
110+
111+
public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
112+
if (iconRender != null) {
113+
iconRender.drawIndicator(matrices, entity, str, light);
114+
}
115+
}
116+
117+
public boolean canDrawIndicator(Entity entity) {
118+
if (iconRender != null) {
119+
return iconRender.canDrawIndicator(entity);
120+
}
121+
return false;
122+
}
123+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.polyfrost.polynametag.render.icon;
2+
3+
import gg.essential.universal.UMatrixStack;
4+
import net.minecraft.entity.Entity;
5+
6+
public interface EssentialIconRender {
7+
void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light);
8+
boolean canDrawIndicator(Entity entity);
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.polyfrost.polynametag.render.icon;
2+
3+
import gg.essential.Essential;
4+
import gg.essential.config.EssentialConfig;
5+
import gg.essential.connectionmanager.common.enums.ProfileStatus;
6+
import gg.essential.data.OnboardingData;
7+
import gg.essential.handlers.OnlineIndicator;
8+
import gg.essential.universal.UMatrixStack;
9+
import net.minecraft.entity.Entity;
10+
import net.minecraft.entity.player.EntityPlayer;
11+
12+
public class Pre1354IconRender implements EssentialIconRender {
13+
@Override
14+
public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
15+
OnlineIndicator.drawNametagIndicator(matrices, entity, str, light);
16+
}
17+
18+
@Override
19+
public boolean canDrawIndicator(Entity entity) {
20+
if (OnboardingData.hasAcceptedTos() && EssentialConfig.INSTANCE.getShowEssentialIndicatorOnNametag() && entity instanceof EntityPlayer) {
21+
return Essential.getInstance().getConnectionManager().getProfileManager().getStatus(((EntityPlayer) entity).getGameProfile().getId()) != ProfileStatus.OFFLINE;
22+
}
23+
return false;
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.polyfrost.polynametag.render.icon;
2+
3+
import gg.essential.Essential;
4+
import gg.essential.config.EssentialConfig;
5+
import gg.essential.connectionmanager.common.enums.ProfileStatus;
6+
import gg.essential.cosmetics.CosmeticsRenderState;
7+
import gg.essential.data.OnboardingData;
8+
import gg.essential.handlers.OnlineIndicator;
9+
import gg.essential.universal.UMatrixStack;
10+
import net.minecraft.client.entity.AbstractClientPlayer;
11+
import net.minecraft.entity.Entity;
12+
import net.minecraft.entity.player.EntityPlayer;
13+
14+
public class V1354IconRender implements EssentialIconRender {
15+
@Override
16+
public void drawIndicator(UMatrixStack matrices, Entity entity, String str, int light) {
17+
OnlineIndicator.drawNametagIndicator(matrices, new CosmeticsRenderState.Live(((AbstractClientPlayer) entity)), str, light);
18+
}
19+
20+
@Override
21+
public boolean canDrawIndicator(Entity entity) {
22+
if (OnboardingData.hasAcceptedTos() && EssentialConfig.INSTANCE.getShowEssentialIndicatorOnNametag() && entity instanceof AbstractClientPlayer) {
23+
return Essential.getInstance().getConnectionManager().getProfileManager().getStatus(((EntityPlayer) entity).getGameProfile().getId()) != ProfileStatus.OFFLINE;
24+
}
25+
return false;
26+
}
27+
}

0 commit comments

Comments
 (0)