generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
properly fix essential
- Loading branch information
Showing
11 changed files
with
226 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/dummy/java/gg/essential/cosmetics/CosmeticsRenderState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/java/org/polyfrost/polynametag/render/EssentialBSManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/polyfrost/polynametag/render/icon/EssentialIconRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/polyfrost/polynametag/render/icon/Pre1354IconRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/polyfrost/polynametag/render/icon/V1354IconRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters