-
Notifications
You must be signed in to change notification settings - Fork 0
/
Minecraft.java
2877 lines (2501 loc) · 109 KB
/
Minecraft.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package net.minecraft.client;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListenableFutureTask;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import org.utilityclient.UtilityClient;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.audio.MusicTicker;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.achievement.GuiAchievement;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.main.GameConfiguration;
import net.minecraft.client.multiplayer.GuiConnecting;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerLoginClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.*;
import net.minecraft.client.resources.data.*;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLeashKnot;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.entity.item.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Bootstrap;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.handshake.client.C00Handshake;
import net.minecraft.network.login.client.C00PacketLoginStart;
import net.minecraft.network.play.client.C16PacketClientStatus;
import net.minecraft.profiler.IPlayerUsage;
import net.minecraft.profiler.PlayerUsageSnooper;
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.stats.AchievementList;
import net.minecraft.stats.StatFileWriter;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Timer;
import net.minecraft.util.Util;
import net.minecraft.util.*;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.WorldProviderEnd;
import net.minecraft.world.WorldProviderHell;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.chunk.storage.AnvilSaveConverter;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.util.glu.GLU;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.SocketAddress;
import java.nio.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
public class Minecraft implements IThreadListener, IPlayerUsage
{
private static final Logger logger = LogManager.getLogger();
public static final boolean isRunningOnMac = Util.getOSType() == Util.EnumOS.OSX;
/** A 10MiB preallocation to ensure the heap is reasonably sized. */
public static byte[] memoryReserve = new byte[10485760];
private static final List<DisplayMode> macDisplayModes = Lists.newArrayList(new DisplayMode(2560, 1600), new DisplayMode(2880, 1800));
private final File fileResourcepacks;
private final PropertyMap twitchDetails;
private final PropertyMap field_181038_N;
private ServerData currentServerData;
/** The RenderEngine instance used by Minecraft */
private TextureManager renderEngine;
/**
* Set to 'this' in Minecraft constructor; used by some settings get methods
*/
private static Minecraft theMinecraft;
public PlayerControllerMP playerController;
private boolean fullscreen;
private boolean hasCrashed;
/** Instance of CrashReport. */
private CrashReport crashReporter;
public int displayWidth;
public int displayHeight;
private boolean field_181541_X = false;
private final Timer timer = new Timer(20.0F);
/** Instance of PlayerUsageSnooper. */
private final PlayerUsageSnooper usageSnooper = new PlayerUsageSnooper("client", this, MinecraftServer.getCurrentTimeMillis());
public WorldClient theWorld;
public RenderGlobal renderGlobal;
private RenderManager renderManager;
private RenderItem renderItem;
private ItemRenderer itemRenderer;
public EntityPlayerSP thePlayer;
private Entity renderViewEntity;
public Entity pointedEntity;
public EffectRenderer effectRenderer;
private final Session session;
private boolean isGamePaused;
/** The font renderer used for displaying and measuring text */
public FontRenderer fontRendererObj;
public FontRenderer standardGalacticFontRenderer;
/** The GuiScreen that's being displayed at the moment. */
public GuiScreen currentScreen;
public LoadingScreenRenderer loadingScreen;
public EntityRenderer entityRenderer;
/** Mouse left click counter */
private int leftClickCounter;
/** Display width */
private final int tempDisplayWidth;
/** Display height */
private final int tempDisplayHeight;
/** Instance of IntegratedServer. */
private IntegratedServer theIntegratedServer;
/** Gui achievement */
public GuiAchievement guiAchievement;
public GuiIngame ingameGUI;
/** Skip render world */
public boolean skipRenderWorld;
/** The ray trace hit that the mouse is over. */
public MovingObjectPosition objectMouseOver;
/** The game settings that currently hold effect. */
public GameSettings gameSettings;
/** Mouse helper instance. */
public MouseHelper mouseHelper;
public final File mcDataDir;
private final File fileAssets;
private final String launchedVersion;
private final Proxy proxy;
private ISaveFormat saveLoader;
/**
* This is set to fpsCounter every debug screen update, and is shown on the debug screen. It's also sent as part of
* the usage snooping.
*/
private static int debugFPS;
/**
* When you place a block, it's set to 6, decremented once per tick, when it's 0, you can place another block.
*/
private int rightClickDelayTimer;
private String serverName;
private int serverPort;
/**
* Does the actual gameplay have focus. If so then mouse and keys will effect the player instead of menus.
*/
public boolean inGameHasFocus;
long systemTime = getSystemTime();
/** Join player counter */
private int joinPlayerCounter;
public final FrameTimer field_181542_y = new FrameTimer();
long field_181543_z = System.nanoTime();
private final boolean jvm64bit;
private NetworkManager networkManager;
private boolean integratedServerIsRunning;
/** The profiler instance */
public final Profiler mcProfiler = new Profiler();
/**
* Keeps track of how long the debug crash keycombo (F3+C) has been pressed for, in order to crash after 10 seconds.
*/
private IReloadableResourceManager mcResourceManager;
private final IMetadataSerializer metadataSerializer_ = new IMetadataSerializer();
private final List<IResourcePack> defaultResourcePacks = Lists.newArrayList();
private final DefaultResourcePack mcDefaultResourcePack;
private ResourcePackRepository mcResourcePackRepository;
private LanguageManager mcLanguageManager;
private Framebuffer framebufferMc;
private TextureMap textureMapBlocks;
private SoundHandler mcSoundHandler;
private MusicTicker mcMusicTicker;
private ResourceLocation mojangLogo;
private final MinecraftSessionService sessionService;
private SkinManager skinManager;
private final Queue < FutureTask<? >> scheduledTasks = Queues.newArrayDeque();
private final Thread mcThread = Thread.currentThread();
/**
* The BlockRenderDispatcher instance that will be used based off gamesettings
*/
private BlockRendererDispatcher blockRenderDispatcher;
/**
* Set to true to keep the game loop running. Set to false by shutdown() to allow the game loop to exit cleanly.
*/
volatile boolean running = true;
/** String that shows the debug information */
public String debug = "";
public boolean renderChunksMany = true;
/** Approximate time (in ms) of last update to debug string */
long debugUpdateTime = getSystemTime();
/** holds the current fps */
int fpsCounter;
long prevFrameTime = -1L;
/** Profiler currently displayed in the debug screen pie chart */
private String debugProfilerName = "root";
public Minecraft(GameConfiguration gameConfig)
{
theMinecraft = this;
this.mcDataDir = gameConfig.folderInfo.mcDataDir;
this.fileAssets = gameConfig.folderInfo.assetsDir;
this.fileResourcepacks = gameConfig.folderInfo.resourcePacksDir;
this.launchedVersion = gameConfig.gameInfo.version;
this.twitchDetails = gameConfig.userInfo.userProperties;
this.field_181038_N = gameConfig.userInfo.field_181172_c;
this.mcDefaultResourcePack = new DefaultResourcePack((new ResourceIndex(gameConfig.folderInfo.assetsDir, gameConfig.folderInfo.assetIndex)).getResourceMap());
this.proxy = gameConfig.userInfo.proxy == null ? Proxy.NO_PROXY : gameConfig.userInfo.proxy;
assert gameConfig.userInfo.proxy != null;
this.sessionService = (new YggdrasilAuthenticationService(gameConfig.userInfo.proxy, UUID.randomUUID().toString())).createMinecraftSessionService();
this.session = gameConfig.userInfo.session;
this.displayWidth = gameConfig.displayInfo.width > 0 ? gameConfig.displayInfo.width : 1;
this.displayHeight = gameConfig.displayInfo.height > 0 ? gameConfig.displayInfo.height : 1;
this.tempDisplayWidth = gameConfig.displayInfo.width;
this.tempDisplayHeight = gameConfig.displayInfo.height;
this.fullscreen = gameConfig.displayInfo.fullscreen;
this.jvm64bit = isJvm64bit();
this.theIntegratedServer = new IntegratedServer(this);
if (gameConfig.serverInfo.serverName != null)
{
this.serverName = gameConfig.serverInfo.serverName;
this.serverPort = gameConfig.serverInfo.serverPort;
}
ImageIO.setUseCache(false);
Bootstrap.register();
}
public void run()
{
this.running = true;
try
{
this.startGame();
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Initializing game");
crashreport.makeCategory("Initialization");
this.displayCrashReport(this.addGraphicsAndWorldToCrashReport(crashreport));
return;
}
while (true)
{
try
{
while (this.running)
{
if (!this.hasCrashed || this.crashReporter == null)
{
try
{
this.runGameLoop();
}
catch (OutOfMemoryError var10)
{
this.freeMemory();
this.displayGuiScreen(new GuiMemoryErrorScreen());
System.gc();
}
}
else
{
this.displayCrashReport(this.crashReporter);
}
}
}
catch (MinecraftError var12)
{
break;
}
catch (ReportedException reportedexception)
{
this.addGraphicsAndWorldToCrashReport(reportedexception.getCrashReport());
this.freeMemory();
logger.fatal("Reported exception thrown!", reportedexception);
this.displayCrashReport(reportedexception.getCrashReport());
break;
}
catch (Throwable throwable1)
{
CrashReport crashreport1 = this.addGraphicsAndWorldToCrashReport(new CrashReport("Unexpected error", throwable1));
this.freeMemory();
logger.fatal("Unreported exception thrown!", throwable1);
this.displayCrashReport(crashreport1);
break;
}
finally
{
this.shutdownMinecraftApplet();
}
return;
}
}
/**
* Starts the game: initializes the canvas, the title, the settings, etcetera.
*/
private void startGame() throws LWJGLException
{
this.gameSettings = new GameSettings(this, this.mcDataDir);
this.defaultResourcePacks.add(this.mcDefaultResourcePack);
this.startTimerHackThread();
if (this.gameSettings.overrideHeight > 0 && this.gameSettings.overrideWidth > 0)
{
this.displayWidth = this.gameSettings.overrideWidth;
this.displayHeight = this.gameSettings.overrideHeight;
}
logger.info("LWJGL Version: " + Sys.getVersion());
this.setInitialDisplayMode();
this.createDisplay();
OpenGlHelper.initializeTextures();
this.framebufferMc = new Framebuffer(this.displayWidth, this.displayHeight, true);
this.framebufferMc.setFramebufferColor(0.0F, 0.0F, 0.0F, 0.0F);
this.registerMetadataSerializers();
this.mcResourcePackRepository = new ResourcePackRepository(this.fileResourcepacks, new File(this.mcDataDir, "server-resource-packs"), this.mcDefaultResourcePack, this.metadataSerializer_, this.gameSettings);
this.mcResourceManager = new SimpleReloadableResourceManager(this.metadataSerializer_);
this.mcLanguageManager = new LanguageManager(this.metadataSerializer_, this.gameSettings.language);
this.mcResourceManager.registerReloadListener(this.mcLanguageManager);
this.refreshResources();
this.renderEngine = new TextureManager(this.mcResourceManager);
this.mcResourceManager.registerReloadListener(this.renderEngine);
this.drawSplashScreen(this.renderEngine);
this.skinManager = new SkinManager(this.renderEngine, new File(this.fileAssets, "skins"), this.sessionService);
this.saveLoader = new AnvilSaveConverter(new File(this.mcDataDir, "saves"));
this.mcSoundHandler = new SoundHandler(this.mcResourceManager, this.gameSettings);
this.mcResourceManager.registerReloadListener(this.mcSoundHandler);
this.mcMusicTicker = new MusicTicker(this);
this.fontRendererObj = new FontRenderer(this.gameSettings, new ResourceLocation("textures/font/ascii.png"), this.renderEngine, false);
this.setWindowIcon();
if (this.gameSettings.language != null)
{
this.fontRendererObj.setUnicodeFlag(this.isUnicode());
this.fontRendererObj.setBidiFlag(this.mcLanguageManager.isCurrentLanguageBidirectional());
}
this.standardGalacticFontRenderer = new FontRenderer(this.gameSettings, new ResourceLocation("textures/font/ascii_sga.png"), this.renderEngine, false);
this.mcResourceManager.registerReloadListener(this.fontRendererObj);
this.mcResourceManager.registerReloadListener(this.standardGalacticFontRenderer);
this.mcResourceManager.registerReloadListener(new GrassColorReloadListener());
this.mcResourceManager.registerReloadListener(new FoliageColorReloadListener());
AchievementList.openInventory.setStatStringFormatter(p_74535_1_ -> {
try
{
return String.format(p_74535_1_, GameSettings.getKeyDisplayString(Minecraft.this.gameSettings.keyBindInventory.getKeyCode()));
}
catch (Exception exception)
{
return "Error: " + exception.getLocalizedMessage();
}
});
this.mouseHelper = new MouseHelper();
this.checkGLError("Pre startup");
GlStateManager.enableTexture2D();
GlStateManager.shadeModel(7425);
GlStateManager.clearDepth(1.0D);
GlStateManager.enableDepth();
GlStateManager.depthFunc(515);
GlStateManager.enableAlpha();
GlStateManager.alphaFunc(516, 0.1F);
GlStateManager.cullFace(1029);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.matrixMode(5888);
this.checkGLError("Startup");
this.textureMapBlocks = new TextureMap("textures");
this.textureMapBlocks.setMipmapLevels(this.gameSettings.mipmapLevels);
this.renderEngine.loadTickableTexture(TextureMap.locationBlocksTexture, this.textureMapBlocks);
this.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
this.textureMapBlocks.setBlurMipmapDirect(false, this.gameSettings.mipmapLevels > 0);
ModelManager modelManager = new ModelManager(this.textureMapBlocks);
this.mcResourceManager.registerReloadListener(modelManager);
this.renderItem = new RenderItem(this.renderEngine, modelManager);
this.renderManager = new RenderManager(this.renderEngine, this.renderItem);
this.itemRenderer = new ItemRenderer(this);
this.mcResourceManager.registerReloadListener(this.renderItem);
this.entityRenderer = new EntityRenderer(this, this.mcResourceManager);
this.mcResourceManager.registerReloadListener(this.entityRenderer);
this.blockRenderDispatcher = new BlockRendererDispatcher(modelManager.getBlockModelShapes(), this.gameSettings);
this.mcResourceManager.registerReloadListener(this.blockRenderDispatcher);
this.renderGlobal = new RenderGlobal(this);
this.mcResourceManager.registerReloadListener(this.renderGlobal);
this.guiAchievement = new GuiAchievement(this);
GlStateManager.viewport(0, 0, this.displayWidth, this.displayHeight);
this.effectRenderer = new EffectRenderer(this.theWorld, this.renderEngine);
this.checkGLError("Post startup");
this.ingameGUI = new GuiIngame(this);
if (this.serverName != null)
{
this.displayGuiScreen(new GuiConnecting(new GuiMainMenu(), this, this.serverName, this.serverPort));
}
else
{
this.displayGuiScreen(new GuiMainMenu());
}
this.renderEngine.deleteTexture(this.mojangLogo);
this.mojangLogo = null;
this.loadingScreen = new LoadingScreenRenderer(this);
if (this.gameSettings.fullScreen && !this.fullscreen)
{
this.toggleFullscreen();
}
try
{
Display.setVSyncEnabled(this.gameSettings.enableVsync);
}
catch (OpenGLException e)
{
this.gameSettings.enableVsync = false;
this.gameSettings.saveOptions();
}
this.renderGlobal.makeEntityOutlineShader();
UtilityClient.getInstance().start();
}
private void registerMetadataSerializers()
{
this.metadataSerializer_.registerMetadataSectionType(new TextureMetadataSectionSerializer(), TextureMetadataSection.class);
this.metadataSerializer_.registerMetadataSectionType(new FontMetadataSectionSerializer(), FontMetadataSection.class);
this.metadataSerializer_.registerMetadataSectionType(new AnimationMetadataSectionSerializer(), AnimationMetadataSection.class);
this.metadataSerializer_.registerMetadataSectionType(new PackMetadataSectionSerializer(), PackMetadataSection.class);
this.metadataSerializer_.registerMetadataSectionType(new LanguageMetadataSectionSerializer(), LanguageMetadataSection.class);
}
private void createDisplay() throws LWJGLException
{
Display.setResizable(true);
Display.setTitle(UtilityClient.getClientName() + " " + UtilityClient.getVersion());
try
{
Display.create((new PixelFormat()).withDepthBits(24));
}
catch (LWJGLException lwjglexception)
{
logger.error("Couldn't set pixel format", lwjglexception);
try
{
Thread.sleep(1000L);
}
catch (InterruptedException var3)
{
System.out.println(var3.getMessage());
}
if (this.fullscreen)
{
this.updateDisplayMode();
}
Display.create();
}
}
private void setInitialDisplayMode() throws LWJGLException
{
if (this.fullscreen)
{
Display.setFullscreen(true);
DisplayMode displaymode = Display.getDisplayMode();
this.displayWidth = Math.max(1, displaymode.getWidth());
this.displayHeight = Math.max(1, displaymode.getHeight());
}
else
{
Display.setDisplayMode(new DisplayMode(this.displayWidth, this.displayHeight));
}
}
private void setWindowIcon()
{
Util.EnumOS util$enumos = Util.getOSType();
if (util$enumos != Util.EnumOS.OSX)
{
InputStream inputstream = null;
InputStream inputstream1 = null;
try
{
inputstream = this.defaultResourcePacks.get(0).getInputStream(new ResourceLocation("icons/icon_16x16.png"));
inputstream1 = this.defaultResourcePacks.get(0).getInputStream(new ResourceLocation("icons/icon_32x32.png"));
if (inputstream != null && inputstream1 != null)
{
Display.setIcon(new ByteBuffer[] {this.readImageToBuffer(inputstream), this.readImageToBuffer(inputstream1)});
}
}
catch (IOException ioexception)
{
logger.error("Couldn't set icon", ioexception);
}
finally
{
try {
assert inputstream != null;
assert inputstream1 != null;
inputstream.close();
inputstream1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static boolean isJvm64bit()
{
String[] astring = new String[] {"sun.arch.data.model", "com.ibm.vm.bitmode", "os.arch"};
for (String s : astring)
{
String s1 = System.getProperty(s);
if (s1 != null && s1.contains("64"))
{
return true;
}
}
return false;
}
public Framebuffer getFramebuffer()
{
return this.framebufferMc;
}
public String getVersion()
{
return this.launchedVersion;
}
private void startTimerHackThread()
{
Thread thread = new Thread("Timer hack thread")
{
public void run()
{
while (Minecraft.this.running)
{
try
{
Thread.sleep(2147483647L);
}
catch (InterruptedException var2) {
var2.printStackTrace();
}
}
}
};
thread.setDaemon(true);
thread.start();
}
public void crashed(CrashReport crash)
{
this.hasCrashed = true;
this.crashReporter = crash;
}
/**
* Wrapper around displayCrashReportInternal
*/
public void displayCrashReport(CrashReport crashReportIn)
{
File file1 = new File(getMinecraft().mcDataDir, "crash-reports");
File file2 = new File(file1, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-client.txt");
Bootstrap.printToSYSOUT(crashReportIn.getCompleteReport());
if (crashReportIn.getFile() != null)
{
Bootstrap.printToSYSOUT("#@!@# Game crashed! Crash report saved to: #@!@# " + crashReportIn.getFile());
System.exit(-1);
}
else if (crashReportIn.saveToFile(file2))
{
Bootstrap.printToSYSOUT("#@!@# Game crashed! Crash report saved to: #@!@# " + file2.getAbsolutePath());
System.exit(-1);
}
else
{
Bootstrap.printToSYSOUT("#@?@# Game crashed! Crash report could not be saved. #@?@#");
System.exit(-2);
}
}
public boolean isUnicode()
{
return this.mcLanguageManager.isCurrentLocaleUnicode() || this.gameSettings.forceUnicodeFont;
}
public void refreshResources()
{
List<IResourcePack> list = Lists.newArrayList(this.defaultResourcePacks);
for (ResourcePackRepository.Entry resourcepackrepository$entry : this.mcResourcePackRepository.getRepositoryEntries())
{
list.add(resourcepackrepository$entry.getResourcePack());
}
if (this.mcResourcePackRepository.getResourcePackInstance() != null)
{
list.add(this.mcResourcePackRepository.getResourcePackInstance());
}
try
{
this.mcResourceManager.reloadResources(list);
}
catch (RuntimeException runtimeexception)
{
logger.info("Caught error stitching, removing all assigned resourcepacks", runtimeexception);
list.clear();
list.addAll(this.defaultResourcePacks);
this.mcResourcePackRepository.setRepositories(Collections.emptyList());
this.mcResourceManager.reloadResources(list);
this.gameSettings.resourcePacks.clear();
this.gameSettings.field_183018_l.clear();
this.gameSettings.saveOptions();
}
this.mcLanguageManager.parseLanguageMetadata(list);
if (this.renderGlobal != null)
{
this.renderGlobal.loadRenderers();
}
}
private ByteBuffer readImageToBuffer(InputStream imageStream) throws IOException
{
BufferedImage bufferedimage = ImageIO.read(imageStream);
int[] aint = bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), null, 0, bufferedimage.getWidth());
ByteBuffer bytebuffer = ByteBuffer.allocate(4 * aint.length);
for (int i : aint)
{
bytebuffer.putInt(i << 8 | i >> 24 & 255);
}
bytebuffer.flip();
return bytebuffer;
}
private void updateDisplayMode() throws LWJGLException
{
Set<DisplayMode> set = Sets.newHashSet();
Collections.addAll(set, Display.getAvailableDisplayModes());
DisplayMode displaymode = Display.getDesktopDisplayMode();
if (!set.contains(displaymode) && Util.getOSType() == Util.EnumOS.OSX)
{
label53:
for (DisplayMode displaymode1 : macDisplayModes)
{
boolean flag = true;
for (DisplayMode displaymode2 : set)
{
if (displaymode2.getBitsPerPixel() == 32 && displaymode2.getWidth() == displaymode1.getWidth() && displaymode2.getHeight() == displaymode1.getHeight())
{
flag = false;
break;
}
}
if (!flag)
{
Iterator<DisplayMode> iterator = set.iterator();
DisplayMode displaymode3;
while (true)
{
if (!iterator.hasNext())
{
continue label53;
}
displaymode3 = iterator.next();
if (displaymode3.getBitsPerPixel() == 32 && displaymode3.getWidth() == displaymode1.getWidth() / 2 && displaymode3.getHeight() == displaymode1.getHeight() / 2)
{
break;
}
}
displaymode = displaymode3;
}
}
}
Display.setDisplayMode(displaymode);
this.displayWidth = displaymode.getWidth();
this.displayHeight = displaymode.getHeight();
}
private void drawSplashScreen(TextureManager textureManagerInstance)
{
ScaledResolution sr = new ScaledResolution(this);
int i = sr.getScaleFactor();
Framebuffer framebuffer = new Framebuffer(sr.getScaledWidth() * i, sr.getScaledHeight() * i, true);
framebuffer.bindFramebuffer(false);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.ortho(0.0D, sr.getScaledWidth(), sr.getScaledHeight(), 0.0D, 1000.0D, 3000.0D);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translate(0.0F, 0.0F, -2000.0F);
GlStateManager.disableLighting();
GlStateManager.disableFog();
GlStateManager.disableDepth();
GlStateManager.enableTexture2D();
// TODO: UtilityClient
textureManagerInstance.bindTexture(new ResourceLocation("textures/background.png"));
Gui.drawScaledCustomSizeModalRect(0, 0, 0, 0, sr.getScaledWidth(), sr.getScaledHeight(), sr.getScaledWidth(), sr.getScaledHeight(), sr.getScaledWidth(), sr.getScaledHeight());
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
GlStateManager.disableFog();
framebuffer.unbindFramebuffer();
framebuffer.framebufferRender(sr.getScaledWidth() * i, sr.getScaledHeight() * i);
GlStateManager.enableAlpha();
GlStateManager.alphaFunc(516, 0.1F);
this.updateDisplay();
}
/**
* Returns the save loader that is currently being used
*/
public ISaveFormat getSaveLoader()
{
return this.saveLoader;
}
/**
* Sets the argument GuiScreen as the main (topmost visible) screen.
*/
public void displayGuiScreen(GuiScreen guiScreenIn)
{
if (this.currentScreen != null)
{
this.currentScreen.onGuiClosed();
}
if (guiScreenIn == null && this.theWorld == null)
{
guiScreenIn = new GuiMainMenu();
}
else if (guiScreenIn == null && this.thePlayer.getHealth() <= 0.0F)
{
guiScreenIn = new GuiGameOver();
}
if (guiScreenIn instanceof GuiMainMenu)
{
this.gameSettings.showDebugInfo = false;
this.ingameGUI.getChatGUI().clearChatMessages();
}
this.currentScreen = guiScreenIn;
if (guiScreenIn != null)
{
this.setIngameNotInFocus();
ScaledResolution scaledresolution = new ScaledResolution(this);
int i = scaledresolution.getScaledWidth();
int j = scaledresolution.getScaledHeight();
guiScreenIn.setWorldAndResolution(this, i, j);
this.skipRenderWorld = false;
}
else
{
this.mcSoundHandler.resumeSounds();
this.setIngameFocus();
}
//UtilityClient.DISCORD_INSTANCE.onScreenChangeEvent();
}
/**
* Checks for an OpenGL error. If there is one, prints the error ID and error string.
*/
private void checkGLError(String message)
{
int i = GL11.glGetError();
if (i != 0)
{
String s = GLU.gluErrorString(i);
logger.error("########## GL ERROR ##########");
logger.error("@ " + message);
logger.error(i + ": " + s);
}
}
/**
* Shuts down the minecraft applet by stopping the resource downloads, and clearing up GL stuff; called when the
* application (or web page) is exited.
*/
public void shutdownMinecraftApplet()
{
try
{
logger.info("Stopping!");
try
{
this.loadWorld(null);
}
catch (Throwable var5) {
var5.printStackTrace();
}
this.mcSoundHandler.unloadSounds();
}
finally
{
Display.destroy();
if (!this.hasCrashed)
{
System.exit(0);
}
}
System.gc();
}
/**
* Called repeatedly from run()
*/
private void runGameLoop() throws IOException
{
long i = System.nanoTime();
this.mcProfiler.startSection("root");
if (Display.isCreated() && Display.isCloseRequested())
{
this.shutdown();
}
if (this.isGamePaused && this.theWorld != null)
{
float f = this.timer.renderPartialTicks;
this.timer.updateTimer();
this.timer.renderPartialTicks = f;
}
else
{
this.timer.updateTimer();
}
this.mcProfiler.startSection("scheduledExecutables");
synchronized (this.scheduledTasks)
{
while (!this.scheduledTasks.isEmpty())
{
Util.func_181617_a(this.scheduledTasks.poll(), logger);
}
}
this.mcProfiler.endSection();
this.mcProfiler.startSection("tick");
for (int j = 0; j < this.timer.elapsedTicks; ++j)
{
this.runTick();
}
this.mcProfiler.endStartSection("preRenderErrors");
this.checkGLError("Pre render");
this.mcProfiler.endStartSection("sound");
this.mcSoundHandler.setListener(this.thePlayer, this.timer.renderPartialTicks);
this.mcProfiler.endSection();
this.mcProfiler.startSection("render");
GlStateManager.pushMatrix();
GlStateManager.clear(16640);
this.framebufferMc.bindFramebuffer(true);
this.mcProfiler.startSection("display");
GlStateManager.enableTexture2D();
if (this.thePlayer != null && this.thePlayer.isEntityInsideOpaqueBlock())
{
this.gameSettings.thirdPersonView = 0;
}
this.mcProfiler.endSection();
if (!this.skipRenderWorld)
{
this.mcProfiler.endStartSection("gameRenderer");
this.entityRenderer.func_181560_a(this.timer.renderPartialTicks, i);
this.mcProfiler.endSection();
}
this.mcProfiler.endSection();
if (this.gameSettings.showDebugInfo && this.gameSettings.showDebugProfilerChart && !this.gameSettings.hideGUI)
{
if (!this.mcProfiler.profilingEnabled)
{
this.mcProfiler.clearProfiling();
}
this.mcProfiler.profilingEnabled = true;
this.displayDebugInfo();
}
else
{