This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
/
EventRenderGame.java
257 lines (211 loc) · 10.7 KB
/
EventRenderGame.java
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package fuj1n.recmod.client.event;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiPlayerTabOverlay;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.scoreboard.IScoreCriteria;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.GameType;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.List;
import fuj1n.recmod.RecMod;
import fuj1n.recmod.lib.IndexReference;
public class EventRenderGame extends Gui {
private static final int INDICATOR_WIDTH = 8;
private static final int INDICATOR_PADDING = 0;
private static final int INDICATOR_TOTAL = INDICATOR_WIDTH * 2 + INDICATOR_PADDING * 2;
private ResourceLocation indicatorsHigh = new ResourceLocation("recmod:textures/sheets/indicatorsx2.png");
private ResourceLocation indicatorsLow = new ResourceLocation("recmod:textures/sheets/indicators.png");
private GuiPlayerTabOverlay to;
@SubscribeEvent
public void preRenderGameOverlay(RenderGameOverlayEvent.Pre event) {
Minecraft mc = Minecraft.getMinecraft();
ResourceLocation indicators = Minecraft.isFancyGraphicsEnabled() ? indicatorsHigh : indicatorsLow;
if(event.getType() == ElementType.PLAYER_LIST) {
event.setCanceled(true);
to = mc.ingameGUI.getTabList();
renderPlayerList(event, mc, indicators);
}
}
public void renderPlayerList(RenderGameOverlayEvent.Pre event, Minecraft mc, ResourceLocation indicators) {
int width = event.getResolution().getScaledWidth();
Scoreboard scoreboardIn = mc.theWorld.getScoreboard();
ScoreObjective scoreObjectiveIn = scoreboardIn.getObjectiveInDisplaySlot(0);
NetHandlerPlayClient nethandlerplayclient = mc.thePlayer.connection;
List<NetworkPlayerInfo> list = GuiPlayerTabOverlay.ENTRY_ORDERING.<NetworkPlayerInfo>sortedCopy(nethandlerplayclient.getPlayerInfoMap());
int namePingGap = 0;
int j = 0;
for (NetworkPlayerInfo networkplayerinfo : list) {
int nameWidth = mc.fontRendererObj.getStringWidth(to.getPlayerName(networkplayerinfo));
namePingGap = Math.max(namePingGap, nameWidth);
if (scoreObjectiveIn != null && scoreObjectiveIn.getRenderType() != IScoreCriteria.EnumRenderType.HEARTS) {
nameWidth = mc.fontRendererObj.getStringWidth(" " + scoreboardIn.getOrCreateScore(networkplayerinfo.getGameProfile().getName(), scoreObjectiveIn).getScorePoints());
j = Math.max(j, nameWidth);
}
}
list = list.subList(0, Math.min(list.size(), 80));
int l3 = list.size();
int i4 = l3;
int userRows;
for (userRows = 1; i4 > 20; i4 = (l3 + userRows - 1) / userRows) {
++userRows;
}
boolean flag = mc.isIntegratedServerRunning() || mc.getConnection().getNetworkManager().isEncrypted();
int l;
if (scoreObjectiveIn != null) {
if (scoreObjectiveIn.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS) {
l = 90;
} else {
l = j;
}
} else {
l = 0;
}
int userWidth = Math.min(userRows * ((flag ? 9 : 0) + namePingGap + l + 13), width - 50) / userRows;
int userX = width / 2 - (userWidth * userRows + (userRows - 1) * 5) / 2;
int menuY = 10;
int menuWidth = userWidth * userRows + (userRows - 1) * 5;
List<String> list1 = null;
List<String> list2 = null;
if (to.header != null) {
list1 = mc.fontRendererObj.listFormattedStringToWidth(to.header.getFormattedText(), width - 50);
for (String s : list1) {
menuWidth = Math.max(menuWidth, mc.fontRendererObj.getStringWidth(s));
}
}
if (to.footer != null) {
list2 = mc.fontRendererObj.listFormattedStringToWidth(to.footer.getFormattedText(), width - 50);
for (String s2 : list2) {
menuWidth = Math.max(menuWidth, mc.fontRendererObj.getStringWidth(s2));
}
}
// Indicator space transforms
userWidth += INDICATOR_TOTAL;
userX -= INDICATOR_TOTAL * userRows / 2;
menuWidth += INDICATOR_TOTAL * userRows;
if (list1 != null) {
drawRect(width / 2 - menuWidth / 2 - 1, menuY - 1, width / 2 + menuWidth / 2 + 1, menuY + list1.size() * mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE);
for (String s3 : list1) {
int i2 = mc.fontRendererObj.getStringWidth(s3);
mc.fontRendererObj.drawStringWithShadow(s3, (float) (width / 2 - i2 / 2), (float) menuY, -1);
menuY += mc.fontRendererObj.FONT_HEIGHT;
}
++menuY;
}
drawRect(width / 2 - menuWidth / 2 - 1, menuY - 1, width / 2 + menuWidth / 2 + 1, menuY + i4 * 9, Integer.MIN_VALUE);
for (int k4 = 0; k4 < l3; ++k4) {
int l4 = k4 / i4;
int i5 = k4 % i4;
int j2 = userX + l4 * userWidth + l4 * 5;
int k2 = menuY + i5 * 9;
drawRect(j2, k2, j2 + userWidth, k2 + 8, 553648127);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
if (k4 < list.size()) {
NetworkPlayerInfo networkplayerinfo1 = (NetworkPlayerInfo) list.get(k4);
String s1 = to.getPlayerName(networkplayerinfo1);
GameProfile gameprofile = networkplayerinfo1.getGameProfile();
if (flag) {
EntityPlayer entityplayer = mc.theWorld.getPlayerEntityByUUID(gameprofile.getId());
boolean flag1 = entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.CAPE) && (gameprofile.getName().equals("Dinnerbone") || gameprofile.getName().equals("Grumm"));
mc.getTextureManager().bindTexture(networkplayerinfo1.getLocationSkin());
int l2 = 8 + (flag1 ? 8 : 0);
int i3 = 8 * (flag1 ? -1 : 1);
Gui.drawScaledCustomSizeModalRect(j2, k2, 8.0F, (float) l2, 8, i3, 8, 8, 64.0F, 64.0F);
if (entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.HAT)) {
int j3 = 8 + (flag1 ? 8 : 0);
int k3 = 8 * (flag1 ? -1 : 1);
Gui.drawScaledCustomSizeModalRect(j2, k2, 40.0F, (float) j3, 8, k3, 8, 8, 64.0F, 64.0F);
}
j2 += 9;
}
if(networkplayerinfo1.getGameType() == GameType.SPECTATOR) {
s1 = TextFormatting.ITALIC + s1;
mc.fontRendererObj.drawStringWithShadow(s1, (float) j2, (float) k2, -1862270977);
} else {
mc.fontRendererObj.drawStringWithShadow(s1, (float) j2, (float) k2, -1);
}
// Indicator rendering
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(indicators);
int indicatorRecIndex = RecMod.instance.isPlayerRecording(networkplayerinfo1.getGameProfile().getName()) ? IndexReference.ICON_RED_INDEX : IndexReference.ICON_GRAY_INDEX;
int indicatorStrIndex = RecMod.instance.isPlayerStreaming(networkplayerinfo1.getGameProfile().getName()) ? IndexReference.ICON_GREEN_INDEX : IndexReference.ICON_GRAY_INDEX;
if (indicatorRecIndex != IndexReference.ICON_DISABLE_INDEX)
drawTexturedModalRect(j2 - (flag ? 9 : 0) + userWidth - INDICATOR_TOTAL + INDICATOR_PADDING, k2, indicatorRecIndex * 8, (int) Math.floor(indicatorRecIndex / 32) * 8 + IndexReference.RES_SSD, INDICATOR_WIDTH, INDICATOR_WIDTH);
drawTexturedModalRect(j2 - (flag ? 9 : 0) + userWidth - INDICATOR_TOTAL + INDICATOR_PADDING * 2 + INDICATOR_WIDTH, k2, indicatorStrIndex * 8, (int) Math.floor(indicatorStrIndex / 32) * 8 + IndexReference.RES_SSD, INDICATOR_WIDTH, INDICATOR_WIDTH);
if(scoreObjectiveIn != null && networkplayerinfo1.getGameType() != GameType.SPECTATOR) {
int k5 = j2 + namePingGap + 1;
int l5 = k5 + l;
if (l5 - k5 > 5) {
to.drawScoreboardValues(scoreObjectiveIn, k2, gameprofile.getName(), k5, l5, networkplayerinfo1);
}
}
to.drawPing(userWidth - INDICATOR_TOTAL, j2 - (flag ? 9 : 0), k2, networkplayerinfo1);
}
}
if (list2 != null) {
menuY = menuY + i4 * 9 + 1;
drawRect(width / 2 - menuWidth / 2 - 1, menuY - 1, width / 2 + menuWidth / 2 + 1, menuY + list2.size() * mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE);
for (String s4 : list2) {
int j5 = mc.fontRendererObj.getStringWidth(s4);
mc.fontRendererObj.drawStringWithShadow(s4, (float) (width / 2 - j5 / 2), (float) menuY, -1);
menuY += mc.fontRendererObj.FONT_HEIGHT;
}
}
}
@SubscribeEvent
public void renderGameOverlay(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getMinecraft();
ResourceLocation indicators = Minecraft.isFancyGraphicsEnabled() ? indicatorsHigh : indicatorsLow;
if(event.getType() == ElementType.ALL && RecMod.instance.showSelf && mc.currentScreen == null) {
int x;
int y;
switch (RecMod.instance.posMode) {
case 0:
x = 0;
y = 0;
break;
case 1:
x = event.getResolution().getScaledWidth() - 32;
y = 0;
break;
case 2:
x = event.getResolution().getScaledWidth() / 2 - 16;
y = event.getResolution().getScaledHeight() / 2 - 8;
break;
case 3:
x = 0;
y = event.getResolution().getScaledHeight() - 16;
break;
case 4:
x = event.getResolution().getScaledWidth() - 32;
y = event.getResolution().getScaledHeight() - 16;
break;
case 5:
x = event.getResolution().getScaledWidth() / 2 - 16 + RecMod.instance.absX;
y = event.getResolution().getScaledHeight() / 2 - 8 + RecMod.instance.absY;
break;
default:
x = event.getResolution().getScaledWidth() - 32;
y = 0;
}
int indicatorRecIndex = RecMod.instance.isPlayerRecording(mc.thePlayer.getName()) ? IndexReference.ICON_RED_INDEX : IndexReference.ICON_GRAY_INDEX;
int indicatorStrIndex = RecMod.instance.isPlayerStreaming(mc.thePlayer.getName()) ? IndexReference.ICON_GREEN_INDEX : IndexReference.ICON_GRAY_INDEX;
mc.getTextureManager().bindTexture(indicators);
drawTexturedModalRect(x, y, indicatorRecIndex * 16, (int) Math.floor(indicatorRecIndex / 16) * 16 + IndexReference.RES_SD, 16, 16);
drawTexturedModalRect(x + 16, y, indicatorStrIndex * 16, (int) Math.floor(indicatorStrIndex / 16) * 16 + IndexReference.RES_SD, 16, 16);
}
}
}