1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
package gtPlusPlus.xmod.gregtech.common.render;
import static gtPlusPlus.GTplusplus.*;
import java.util.Collection;
import java.util.UUID;
import org.lwjgl.opengl.GL11;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import gregtech.api.enums.GT_Values;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.lib.CORE;
import net.minecraftforge.client.event.RenderPlayerEvent;
public class GTPP_CapeRenderer
extends RenderPlayer {
private final ResourceLocation[] mCapes = {new ResourceLocation("miscutils:textures/OrangeHD.png"), new ResourceLocation("miscutils:textures/FancyCapeHD.png"), new ResourceLocation("miscutils:textures/TesterCapeHD.png"), new ResourceLocation("miscutils:textures/DevCapeHD.png"), new ResourceLocation("miscutils:textures/PatreonCapeHD.png")};
private final Collection<String> mCapeList;
public GTPP_CapeRenderer(Collection<String> aCapeList) {
this.mCapeList = aCapeList;
setRenderManager(RenderManager.instance);
BuildCapeList();
}
private static volatile ResourceLocation cachedResource = null;
private static boolean hasResourceChecked = false;
public synchronized void receiveRenderSpecialsEvent(RenderPlayerEvent.Specials.Pre aEvent) {
AbstractClientPlayer aPlayer = (AbstractClientPlayer) aEvent.entityPlayer;
ResourceLocation tResource = null;
//Make sure we don't keep checking on clients who dont have capes.
if (!hasResourceChecked) {
//Give Devs Dev capes.
if (CORE.DEVENV) {
cachedResource = this.mCapes[4];
hasResourceChecked = true;
}
else {
String mTemp = "";
//If list's have not been built yet for some reason, we best do it now.
if (mDevCapes.size() <= 1) {
BuildCapeList();
}
//Iterates all players in all lists, caches result.
for (Pair<String, String> mName : mOrangeCapes){
mTemp = getPlayerName(mName.getKey(), mName.getValue());
mCapeList.add(mTemp);
if (mTemp.toLowerCase().contains(aPlayer.getDisplayName().toLowerCase())) {
tResource = this.mCapes[0];
}
}
for (Pair<String, String> mName : mMiscCapes){
mTemp = getPlayerName(mName.getKey(), mName.getValue());
mCapeList.add(mTemp);
if (mTemp.toLowerCase().contains(aPlayer.getDisplayName().toLowerCase())) {
tResource = this.mCapes[1];
}
}
for (Pair<String, String> mName : mBetaTestCapes){
mTemp = getPlayerName(mName.getKey(), mName.getValue());
mCapeList.add(mTemp);
if (mTemp.toLowerCase().contains(aPlayer.getDisplayName().toLowerCase())) {
tResource = this.mCapes[2];
}
}
for (Pair<String, String> mName : mDevCapes){
mTemp = getPlayerName(mName.getKey(), mName.getValue());
mCapeList.add(mTemp);
if (mTemp.toLowerCase().contains(aPlayer.getDisplayName().toLowerCase())) {
tResource = this.mCapes[3];
}
}
for (Pair<String, String> mName : mPatreonCapes){
mTemp = getPlayerName(mName.getKey(), mName.getValue());
mCapeList.add(mTemp);
if (mTemp.toLowerCase().contains(aPlayer.getDisplayName().toLowerCase())) {
tResource = this.mCapes[4];
}
}
}
if (tResource != null) {
cachedResource = tResource;
}
//Only run once.
hasResourceChecked = true;
}
if (GT_Utility.getFullInvisibility(aPlayer) || aPlayer.isInvisible() || GT_Utility.getPotion(aPlayer, Integer.valueOf(Potion.invisibility.id).intValue())) {
aEvent.setCanceled(true);
return;
}
float aPartialTicks = aEvent.partialRenderTick;
try {
if ((cachedResource != null) && (!aPlayer.getHideCape())) {
bindTexture(cachedResource);
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, 0.125F);
double d0 = aPlayer.field_71091_bM + (aPlayer.field_71094_bP - aPlayer.field_71091_bM) * aPartialTicks - (aPlayer.prevPosX + (aPlayer.posX - aPlayer.prevPosX) * aPartialTicks);
double d1 = aPlayer.field_71096_bN + (aPlayer.field_71095_bQ - aPlayer.field_71096_bN) * aPartialTicks - (aPlayer.prevPosY + (aPlayer.posY - aPlayer.prevPosY) * aPartialTicks);
double d2 = aPlayer.field_71097_bO + (aPlayer.field_71085_bR - aPlayer.field_71097_bO) * aPartialTicks - (aPlayer.prevPosZ + (aPlayer.posZ - aPlayer.prevPosZ) * aPartialTicks);
float f6 = aPlayer.prevRenderYawOffset + (aPlayer.renderYawOffset - aPlayer.prevRenderYawOffset) * aPartialTicks;
double d3 = MathHelper.sin(f6 * CORE.PI / 180.0F);
double d4 = -MathHelper.cos(f6 * CORE.PI / 180.0F);
float f7 = (float) d1 * 10.0F;
float f8 = (float) (d0 * d3 + d2 * d4) * 100.0F;
float f9 = (float) (d0 * d4 - d2 * d3) * 100.0F;
if (f7 < -6.0F) {
f7 = -6.0F;
}
if (f7 > 32.0F) {
f7 = 32.0F;
}
if (f8 < 0.0F) {
f8 = 0.0F;
}
float f10 = aPlayer.prevCameraYaw + (aPlayer.cameraYaw - aPlayer.prevCameraYaw) * aPartialTicks;
f7 += MathHelper.sin((aPlayer.prevDistanceWalkedModified + (aPlayer.distanceWalkedModified - aPlayer.prevDistanceWalkedModified) * aPartialTicks) * 6.0F) * 32.0F * f10;
if (aPlayer.isSneaking()) {
f7 += 25.0F;
}
GL11.glRotatef(6.0F + f8 / 2.0F + f7, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(f9 / 2.0F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(-f9 / 2.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
((ModelBiped) this.mainModel).renderCloak(0.0625F);
GL11.glPopMatrix();
}
} catch (Throwable e) {
if (GT_Values.D1) {
e.printStackTrace(GT_Log.err);
}
}
}
private String getPlayerName(String name, String uuid) {
Logger.WORLD("[Capes++] Trying to UUID check "+name+".");
if (uuid != null) {
if (uuid.length() > 0) {
UUID g = UUID.fromString(uuid);
if (g != null) {
Logger.WORLD("[Capes++] Mojang/Cache checking for "+name+".");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152652_a(g);
if (profile != null) {
Logger.INFO("[Capes++] Found for UUID check: "+profile.getName()+".");
return profile.getName();
}
}
}
}
if (name != null) {
if (name.length() > 0) {
Logger.WORLD("[Capes++] Mojang/Cache checking for "+name+".");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(name);
if (profile != null) {
Logger.INFO("[Capes++] Found for name check: "+profile.getName()+".");
return profile.getName();
}
}
}
Logger.WORLD("[Capes++] Failed UUID check for "+name+".");
return name;
}
}
|