-
Notifications
You must be signed in to change notification settings - Fork 7
/
ZanMinimap.java
3184 lines (2792 loc) · 122 KB
/
ZanMinimap.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.src;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.mamiyaotaru.CommandServerZanTp;
import net.minecraft.src.mamiyaotaru.EntityWaypoint;
import net.minecraft.src.mamiyaotaru.EnumOptionsHelperMinimap;
import net.minecraft.src.mamiyaotaru.EnumOptionsMinimap;
import net.minecraft.src.mamiyaotaru.GLBufferedImage;
import net.minecraft.src.mamiyaotaru.GuiMinimap;
import net.minecraft.src.mamiyaotaru.GuiScreenAddWaypoint;
import net.minecraft.src.mamiyaotaru.GuiWaypoints;
import net.minecraft.src.mamiyaotaru.MapChunkCache;
import net.minecraft.src.mamiyaotaru.MapData;
import net.minecraft.src.mamiyaotaru.MinimapTranslate;
import net.minecraft.src.mamiyaotaru.RenderWaypoint;
import net.minecraft.src.mamiyaotaru.Waypoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.input.Mouse;
import java.util.Random;
public class ZanMinimap implements Runnable { // implements Runnable
public Minecraft game;
private World world;
/* TODO allow this to be higher */
private int worldHeight = 256;
/*motion tracker, may or may not exist*/
// private mod_MotionTracker motionTracker = null;
/*whether motion tracker exists*/
public Boolean motionTrackerExists = false;
/* mob overlay */
public ZanRadar radar = null;
public ZanColorManager colorManager = null;
private MinimapTranslate translationManager = null;
private StringTranslate stringtranslate = null;
/*Stored data for each zoom level*/
private MapData[] mapData = new MapData[4];
private MapChunkCache[] chunkCache = new MapChunkCache[4];
/*Textures for each zoom level*/
private GLBufferedImage[] map = new GLBufferedImage[4];
private GLBufferedImage roundImage;
/* has the image changed - if not we don't need to delete GLtex and allocate a new one */
private boolean imageChanged = true;
/*use internal linear scale or more logarithmic looking minecraft scale*/
private boolean useInternalLightTable = false;
/*table of brightness values, affected by world provider's light brightness table without using its logarithmic scale.*/
private float[] internalLightBrightnessTable = new float[16];
/*regular default brightness table, against which to compare worldprovider's to catch light changes and allow us to translate them to our linear scale*/
private final float[] standardLightBrightnessTable = new float[] {0.0f, 0.017543858f, 0.037037037f, 0.058823526f, 0.08333333f, 0.11111113f, 0.14285712f, 0.1794872f, 0.22222225f, 0.2727273f, 0.33333334f, 0.40740743f, 0.50000006f, 0.61904764f, 0.77777773f, 1.0f};
/* last light brightness table (so we can detect changes and redo light */
private final float[] lastLightBrightnessTable = new float[16];
/* lets us keep track of sun going up or down */
private int lastDaylight = 0;
/* used to keep track of moving from aboveground to underground */
private boolean lastBeneathRendering = false;
public Random generator = new Random();
/*Current Menu Loaded*/
public int iMenu = 1;
/*Current Gui Screen*/
private GuiScreen guiScreen = null;
/*Display anything at all, menu, etc..*/
private boolean enabled = true;
/*Was mouse down last render?*/
private boolean lfclick = false;
/*Toggle full screen map*/
public boolean fullscreenMap = false;
/*Is map calc thread still executing?*/
public boolean active = false;
/*Current level of zoom*/
private int zoom = 2;
/*storage variable for zoom level; remembers old level when we go fullscreen (which is always level 3)*/
private int regularZoom = 2;
/*grow or shrink map*/
public int sizeModifier = 0;
/*corner to display in 0-3 upper left clockwise*/
public int mapCorner = 1;
/*center of map x coord*/
public int mapX = 37;
/*center of map y coord*/
public int mapY = 37;
int scWidth;
int scHeight;
/*Current build version*/
public String zmodver = "v2.0";
/*Waypoint name temporary input*/
private String way = "";
/*Waypoint X coord temp input*/
private int wayX = 0;
/*Waypoint Z coord temp input*/
private int wayZ = 0;
/*Colour or black and white minimap?*/
private boolean rc = true;
/*Holds error exceptions thrown*/
private String error = "";
/*Strings to show for menu*/
private String[] sMenu = new String[8]; // bump up options here
/*Time remaining to show error thrown for*/
private int ztimer = 0;
private int availableProcessors = Runtime.getRuntime().availableProcessors();
public boolean multicore = (availableProcessors > 0);
/*Key entry interval (ie, can only zoom once every 20 ticks)*/
private int inputFudge = 0;
/*reset heightmap after some ticks*/
private int heightMapFudge = 0;
/*needed for doing tasks occasionally, like checking for old waypoints*/
private int timer = 0;
/*whether we need to do a full render*/
public boolean doFullRender = true;
/*Last X coordinate rendered*/
public int lastX = 0;
/*Last Z coordinate rendered*/
public int lastZ = 0;
/*Last Y coordinate rendered*/
private int lastY = 0;
/*Last X coordinate rendered - greater precision*/
public double lastXDouble = 0;
/*Last Z coordinate rendered - greater precision*/
public double lastZDouble = 0;
/*Last gamma setting*/
private float lastGamma = 0;
/*Last UI scale factor*/
public int scScale = 0;
/*Last zoom level rendered at*/
public int lZoom = 0;
/*Direction you're facing*/
private float direction = 0.0f;
/*fine adjustment for player's position for positioning map image*/
public float percentX;
public float percentY;
/* only for squaremap, zoomed all the way in, with filtering. to know whether to draw image again, while cutting off more of the edge*/
public boolean lastPercentXOver = false;
public boolean lastPercentYOver = false;
/*Setting file access*/
private File settingsFile;
/*current (integrated) server. for injecting command when logging in to same singleplayer world twice in a row*/
MinecraftServer server;
/*Name of World currently loaded*/
private String worldName = "";
public KeyBinding keyBindZoom = new KeyBinding("key.minimap.zoom", Keyboard.KEY_Z);
public KeyBinding keyBindFullscreen = new KeyBinding("key.minimap.togglefullscreen", Keyboard.KEY_X);
public KeyBinding keyBindMenu = new KeyBinding("key.minimap.menu", Keyboard.KEY_M);
public KeyBinding keyBindWaypoint = new KeyBinding("key.minimap.waypointhotkey", Keyboard.KEY_C);
public KeyBinding keyBindMobToggle = new KeyBinding("key.minimap.togglemobs", Keyboard.KEY_NONE);
public KeyBinding[] keyBindings;
/*set if we want to cooperate with world downloader mod*/
public boolean dlSafe = false;
/*whether radar is allowed*/
public Boolean radarAllowed = true;
/*whether caves is allowed*/
public Boolean cavesAllowed = true;
/*Hide just the minimap*/
public boolean hide = false;
/*Show coordinates toggle*/
private boolean coords = true;
/*Show the minimap when in the Nether*/
private boolean showNether = true;
/*Cave mode (only applicable to overworld)*/
private boolean showCaves = true;
/*Dynamic lighting toggle*/
private boolean lightmap = true;
/*Terrain depth toggle*/
private boolean heightmap = multicore;
/*rerender height mapping after height changes by this much*/
private int heightMapResetHeight = multicore?2:5;
/*or after this amount of time has passed*/
private int heightMapResetTime = multicore?300:3000;
/*Terrain bump toggle*/
private boolean slopemap = true;
/*Filter (blur really) toggle */
boolean filtering = true;
/*Transparency (water only ATM) toggle */
public boolean waterTransparency = multicore;
/*Transparency (water only ATM) toggle */
public boolean blockTransparency = multicore;
/*Show biome colors*/
public boolean biomes = multicore;
/*Square map toggle*/
public boolean squareMap = false;
/*keep track if squaremap has changed*/
public boolean lastSquareMap = false;
/*Old north toggle*/
public boolean oldNorth = false;
public int northRotate = 0;
/*Waypoint in world beacon toggle*/
public boolean showBeacons = true;
/*Waypoint in world waypoint sign toggle*/
public boolean showWaypoints = true;
/*Show welcome message toggle*/
private boolean welcome = true;
/*Waypoint names and data*/
public ArrayList<Waypoint> wayPts = new ArrayList<Waypoint>();
/*old 2d Waypoint names and data*/
public ArrayList<Waypoint> old2dWayPts = new ArrayList<Waypoint>();
/*waypionts that have ben updated and should be removed from old2dwaypoints*/
public ArrayList<Waypoint> updatedPts;
/*Map calculation thread*/
public Thread zCalc = new Thread(this);
//should we be running the calc thread?
public boolean threading = multicore;
/*Polygon creation class*/
private Tessellator tesselator = Tessellator.instance;
/*Font rendering class*/
private FontRenderer fontRenderer;
/*Render texture*/
public RenderEngine renderEngine;
/* reference to our framebuffer object */
private int fboID = 0;
/*are framebuffer objects even supported*/
private boolean fboEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object;
/* reference to the texture created by rendering to the fbo */
private int fboTextureID = 0;
private final int[] selfHash = {
(""+(char)109+(char)105+(char)110+(char)101+(char)99+(char)114+(char)97+(char)102+(char)116+(char)120+(char)116+(char)101+(char)114+(char)105+(char)97).hashCode(),
(""+(char)106+(char)97+(char)99+(char)111+(char)98+(char)111+(char)111+(char)109+(char)49+(char)48+(char)48).hashCode(),
(""+(char)108+(char)97+(char)115+(char)101+(char)114+(char)112+(char)105+(char)103+(char)111+(char)102+(char)100+(char)111+(char)111+(char)109).hashCode()
};
private boolean tf = false;
public static ZanMinimap instance;
public ZanMinimap() {
instance=this;
stringtranslate = StringTranslate.getInstance();
/* if (classExists("mod_MotionTracker")) {
motionTracker = new mod_MotionTracker();
motionTrackerExists = true;
}*/
// if (classExists("ZanRadar")) { // change to mod_ZanRadar if this ever becomes independent and modloader enabled
radar = new ZanRadar(this);
// }
colorManager = new ZanColorManager(this);
this.keyBindings = new KeyBinding[] {this.keyBindMenu, this.keyBindWaypoint, this.keyBindZoom, this.keyBindFullscreen, this.keyBindMobToggle};
zCalc.start();
zCalc.setPriority(Thread.MIN_PRIORITY);
this.mapData[0] = new MapData(32, 32);
this.mapData[1] = new MapData(64, 64);
this.mapData[2] = new MapData(128, 128);
this.mapData[3] = new MapData(256, 256);
this.chunkCache[0] = new MapChunkCache(3, 3);
this.chunkCache[1] = new MapChunkCache(5, 5);
this.chunkCache[2] = new MapChunkCache(9, 9);
this.chunkCache[3] = new MapChunkCache(17, 17);
this.map[0] = new GLBufferedImage(32,32,BufferedImage.TYPE_4BYTE_ABGR);
this.map[1] = new GLBufferedImage(64,64,BufferedImage.TYPE_4BYTE_ABGR);
this.map[2] = new GLBufferedImage(128,128,BufferedImage.TYPE_4BYTE_ABGR);
this.map[3] = new GLBufferedImage(256,256,BufferedImage.TYPE_4BYTE_ABGR);
this.roundImage = new GLBufferedImage(128,128,BufferedImage.TYPE_4BYTE_ABGR);
translationManager = new MinimapTranslate(this);
this.translationManager.checkForChanges();
this.sMenu[0] = "§4Zan's§F Mod! " + this.zmodver + " " + stringtranslate.translateKey("minimap.ui.welcome1");
this.sMenu[1] = stringtranslate.translateKey("minimap.ui.welcome2");
this.sMenu[2] = stringtranslate.translateKey("minimap.ui.welcome3");
this.sMenu[3] = stringtranslate.translateKey("minimap.ui.welcome4");
this.sMenu[4] = "§B" + getKeyDisplayString(keyBindZoom.keyCode) + "§F: " + stringtranslate.translateKey("minimap.ui.welcome5a") + ", §B: " + getKeyDisplayString(keyBindMenu.keyCode) + "§F: " + stringtranslate.translateKey("minimap.ui.welcome5b");
this.sMenu[5] = "§B" + getKeyDisplayString(keyBindFullscreen.keyCode) + "§F: " + stringtranslate.translateKey("minimap.ui.welcome6");
this.sMenu[6] = "§B" + getKeyDisplayString(keyBindWaypoint.keyCode) + "§F: " + stringtranslate.translateKey("minimap.ui.welcome7");
//this.sMenu[6] = "§B" + getKeyDisplayString(keyBindMobToggle.keyCode) + "§F: " + stringtranslate.translateKey("minimap.ui.welcome7");
this.sMenu[7] = "§F" + getKeyDisplayString(keyBindZoom.keyCode) + "§7: " + stringtranslate.translateKey("minimap.ui.welcome8");
if (fboEnabled)
setupFBO(); // setup our framebuffer object
loadAll();
Object renderManager = RenderManager.instance;
if (renderManager == null) {
System.out.println("failed to get render manager");
}
else {
Object entityRenderMap = getPrivateFieldByType(renderManager, Map.class);
if (entityRenderMap == null) {
System.out.println("could not get entityRenderMap");
}
else {
RenderWaypoint renderWaypoint = new RenderWaypoint();
((java.util.HashMap)entityRenderMap).put(EntityWaypoint.class, renderWaypoint);
renderWaypoint.setRenderManager(RenderManager.instance);
}
}
//this does the same, clunkier than the above though
/* ((java.util.HashMap)entityRenderMap).put(EntityWaypoint.class, new RenderWaypoint());
Iterator iterator = ((java.util.HashMap)entityRenderMap).values().iterator();
Render render = null;
while (iterator.hasNext())
{
render = (Render)iterator.next();
if (render.getClass() == RenderWaypoint.class)
render.setRenderManager(RenderManager.instance);
}*/
}
public static ZanMinimap getInstance()
{
return instance;
}
public Object getPrivateFieldByName (Object o, String fieldName) {
// Go and find the private field...
final java.lang.reflect.Field fields[] = o.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; ++i) {
if (fieldName.equals(fields[i].getName())) {
try {
fields[i].setAccessible(true);
return fields[i].get(o);
}
catch (IllegalAccessException ex) {
//Assert.fail ("IllegalAccessException accessing " + fieldName);
}
}
}
//Assert.fail ("Field '" + fieldName +"' not found");
return null;
/*java.lang.reflect.Field privateField = null;
try {
privateField = o.getClass().getDeclaredField(fieldName);
}
catch (NoSuchFieldException e){}
privateField.setAccessible(true);
Object obj = null;
try {
obj = privateField.get(o);
}
catch (IllegalAccessException e){}
return obj;*/
}
public Object getPrivateFieldByType (Object o, Class classtype) {
return getPrivateFieldByType(o, classtype, 0);
}
public Object getPrivateFieldByType (Object o, Class classtype, int index) {
// Go and find the private field...
int counter = 0;
final java.lang.reflect.Field fields[] = o.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; ++i) {
if (classtype.equals(fields[i].getType())) {
if (counter == index) {
try {
fields[i].setAccessible(true);
return fields[i].get(o);
}
catch (IllegalAccessException ex) {
}
}
counter++;
}
}
return null;
}
private boolean classExists (String className) {
try {
Class.forName (className);
return true;
}
catch (ClassNotFoundException exception) {
return false;
}
}
public static File getAppDir(String app)
{
return Minecraft.getAppDir(app);
}
public void chatInfo(String s) {
game.thePlayer.addChatMessage(s);
}
public int xCoord() {
return (int)(this.game.thePlayer.posX < 0.0D ? this.game.thePlayer.posX - 1 : this.game.thePlayer.posX); // TODO defsck this off by one stuff
}
public int zCoord() {
return (int)(this.game.thePlayer.posZ < 0.0D ? this.game.thePlayer.posZ - 1 : this.game.thePlayer.posZ);
}
public int yCoord() {
return (int)this.game.thePlayer.posY;
}
public double xCoordDouble() {
return (this.game.thePlayer.posX < 0.0D ? this.game.thePlayer.posX - 1 : this.game.thePlayer.posX);
}
public double zCoordDouble() {
return (this.game.thePlayer.posZ < 0.0D ? this.game.thePlayer.posZ - 1 : this.game.thePlayer.posZ);
}
private float rotationYaw() {
return this.game.thePlayer.rotationYaw;
}
public World getWorld()
{
return game.theWorld;
}
public void run() {
if (this.game == null)
return;
while(true){
if(this.threading)
{
this.active = true;
while(this.enabled && this.game.thePlayer!=null /*&& this.game.thePlayer.dimension!=-1*/ && active) {
if (this.enabled && !this.hide) {
try {this.mapCalc(doFullRender);} catch (Exception local) {}
this.chunkCache[this.lZoom].drawChunks(oldNorth);
}
//System.out.println("changed: " + this.imageChanged);
doFullRender = false;
this.active = false;
}
try {this.zCalc.sleep(10);} catch (Exception exc) {}
try {this.zCalc.wait(0);} catch (Exception exc) {}
}
else
{
try {this.zCalc.sleep(1000);} catch (Exception exc) {}
try {this.zCalc.wait(0);} catch (Exception exc) {}
}
}
}
//@Override
public void onTickInGame(Minecraft mc)
{
northRotate = oldNorth ? 90 : 0;
if(game==null) game = mc;
/* if (motionTrackerExists && motionTracker.activated) {
motionTracker.OnTickInGame(mc);
return;
}*/
if(fontRenderer==null) fontRenderer = this.game.fontRenderer;
if(renderEngine==null) {
renderEngine = this.game.renderEngine;
//this.map[0].index = this.tex(this.map[0]);
//this.map[1].index = this.tex(this.map[1]);
//this.map[2].index = this.tex(this.map[2]);
//this.map[3].index = this.tex(this.map[3]);
}
if (this.game.currentScreen == null && Keyboard.isKeyDown(keyBindMenu.keyCode)) {
Keyboard.next();
//this.iMenu = 2;
//this.game.displayGuiScreen(new GuiScreen());
this.iMenu = 0; // close welcome message
if (welcome) {
welcome = false;
saveAll();
}
this.game.displayGuiScreen(new GuiMinimap(this));
//ModLoader.openGUI(this.game.thePlayer, new GuiMinimap(this));
}
if (this.game.currentScreen == null && Keyboard.isKeyDown(keyBindWaypoint.keyCode)) {
Keyboard.next();
//this.iMenu = 2;
//this.game.displayGuiScreen(new GuiScreen());
this.iMenu = 0; // close welcome message
if (welcome) {
welcome = false;
saveAll();
}
float r, g, b;
if (this.wayPts.size() == 0) { // green for the first one
r = 0;
g = 1;
b = 0;
}
else { // random for later ones
r = generator.nextFloat();
g = generator.nextFloat();
b = generator.nextFloat();
}
Waypoint newWaypoint = new Waypoint("", (this.game.thePlayer.dimension != -1)?this.xCoord():this.xCoord()*8, (this.game.thePlayer.dimension != -1)?this.zCoord():this.zCoord()*8, this.yCoord()-1, true, r, g, b, "");
// clunky way to do it calling through waypoint list gui. Not bad if we want waypoint list to show after finishing creating the point. requires actionPerformed to be public
/*GuiButton fakeButton = new GuiButton(-4, 1337, 1337, 1337, 1337, "moo");
//GuiWaypoints guiWaypoints = new GuiWaypoints(null, this);
//guiWaypoints.actionPerformed(fakeButton);
//guiWaypoints.addClicked = true;*/
// works without GuiWaypoints in the middle. Little more logic needed in GuiScreenAddWaypoint, but feels cleaner
this.game.displayGuiScreen(new GuiScreenAddWaypoint(null, newWaypoint));
}
if (this.game.currentScreen == null && Keyboard.isKeyDown(keyBindMobToggle.keyCode)) {
Keyboard.next();
if (welcome) {
welcome = false;
saveAll();
}
if (this.inputFudge <= 0) {
this.radar.setOptionValue(EnumOptionsMinimap.HIDERADAR, 0);
saveAll();
this.inputFudge = 20;
}
}
if (this.game.currentScreen == null && Keyboard.isKeyDown(keyBindZoom.keyCode) && (this.showNether || this.game.thePlayer.dimension!=-1)) {
Keyboard.next();
if (welcome) {
welcome = false;
saveAll();
}
this.SetZoom();
}
if (this.game.currentScreen == null && Keyboard.isKeyDown(keyBindFullscreen.keyCode) && (this.showNether || this.game.thePlayer.dimension!=-1)) {
Keyboard.next();
if (welcome) {
welcome = false;
saveAll();
}
if (this.inputFudge <= 0) {
this.fullscreenMap = !this.fullscreenMap;
if (fullscreenMap) {
this.regularZoom = this.zoom;
this.zoom = 3;
}
else
this.zoom = this.regularZoom;
doFullRender = true;
this.inputFudge = 20;
}
}
checkForChanges();
if(/*deathMarker &&*/ this.game.currentScreen instanceof GuiGameOver && !(this.guiScreen instanceof GuiGameOver)) {
//tamis doid
handleDeath();
}
//final long startTime = System.nanoTime();
sortWaypointEntities(); // only use if waypointEntities are added to entities instead of weathereffects. This keeps them at the back.
// For whatever reason, things rendered after them ignore z depth (with relation to the waypoint entities).
// if weather, they all ignore it and it's at least consistent (though waypoints won't be consistent with themselves probably)
// effect is nice. Until I can figure out how to get them to behave like the other entities, deal with the unnoticeable speed hit
//System.out.println(System.nanoTime()-startTime);
this.guiScreen = this.game.currentScreen;
checkIfChunksChanged();
if (threading)
{
if (!zCalc.isAlive() && threading) {
zCalc = new Thread(this);
//zCalc.setPriority(Thread.MIN_PRIORITY);
zCalc.start();
}
if (!(this.game.currentScreen instanceof GuiGameOver) && !(this.game.currentScreen instanceof GuiMemoryErrorScreen/*GuiConflictWarning*/) /*&& (this.game.thePlayer.dimension!=-1)*/ && this.game.currentScreen!=null)
try {this.zCalc.notify();} catch (Exception local) {}
}
else if (!threading)
{
if (this.enabled && !this.hide) {
mapCalc(doFullRender);
this.chunkCache[this.lZoom].drawChunks(oldNorth);
}
doFullRender=false;
}
if (this.iMenu==1) {
if (!welcome) this.iMenu = 0;
}
if ((this.game.currentScreen instanceof GuiIngameMenu) || (Keyboard.isKeyDown(61)) /*|| (this.game.thePlayer.dimension==-1)*/)
this.enabled=false;
else this.enabled=true;
/* // wut why not just get it
if (this.oldDir != this.radius()) {
this.direction += this.oldDir - this.radius();
this.oldDir = this.radius();
}
*/
this.direction = this.rotationYaw() + 180 + northRotate;
while (this.direction >= 360.0f)
this.direction -= 360.0f;
while (this.direction < 0.0f)
this.direction += 360.0f;
if ((!this.error.equals("")) && (this.ztimer == 0)) this.ztimer = 500;
if (this.ztimer > 0) this.ztimer -= 1;
if (this.inputFudge > 0) this.inputFudge -= 1;
if ((this.ztimer == 0) && (!this.error.equals(""))) this.error = "";
if (this.enabled) {
//ScaledResolution scSize = new ScaledResolution(game.gameSettings, game.displayWidth, game.displayHeight);
//int scWidth = scSize.getScaledWidth();
//int scHeight = scSize.getScaledHeight();
//int scScale = scSize.getScaleFactor(); // do below to ignore gui scale;
int scScale = 1;
while (game.displayWidth / (scScale + 1) >= 320 && game.displayHeight / (scScale + 1) >= 240)
{
++scScale;
}
scScale = scScale + (this.fullscreenMap?0:sizeModifier); // don't adjust size if fullscreen map
double scaledWidthD = (double)game.displayWidth / (double)scScale;
double scaledHeightD = (double)game.displayHeight / (double)scScale;
scWidth = MathHelper.ceiling_double_int(scaledWidthD);
scHeight = MathHelper.ceiling_double_int(scaledHeightD);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glOrtho(0.0D, scaledWidthD, scaledHeightD, 0.0D, 1000.0D, 3000.0D);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
if (this.mapCorner == 0 || this.mapCorner == 3)
mapX = 37;
else
mapX = scWidth - 37;
if (this.mapCorner == 0 || this.mapCorner == 1) {
mapY = 37;
}
else {
mapY = scHeight - 37;
}
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDepthMask(false);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ZERO);//GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float multi = 2f/(float)Math.pow(2, this.lZoom);
//percentX = (float)this.xCoordDouble()-lastX;
percentX = (float)lastXDouble-lastX;
if (lastX < 0)
percentX = percentX + 1f;
percentX = percentX * multi;
//percentY = (float)this.zCoordDouble()-lastZ;
percentY = (float)lastZDouble-lastZ;
if (lastZ < 0)
percentY = percentY + 1f;
percentY = percentY * multi;
if ((this.showNether || this.game.thePlayer.dimension!=-1) && !this.hide) {
if(this.fullscreenMap)
renderMapFull(scWidth,scHeight);
else
renderMap(mapX, mapY, scScale);
}
//if (ztimer > 0)
// this.write(this.error, 20, 20, 0xffffff);
if (this.iMenu>0) showMenu(scWidth, scHeight);
if (this.showNether || this.game.thePlayer.dimension!=-1) {
if (radar != null && this.radarAllowed && !this.hide && !this.fullscreenMap)
radar.OnTickInGame(mc);
if(coords) {
showCoords(mapX, mapY);
}
if ((squareMap || fullscreenMap) && !this.hide) {
if (this.fullscreenMap)
drawArrow(scWidth/2, scHeight/2);
else
drawArrow(mapX, mapY);
}
}
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.game.entityRenderer.setupOverlayRendering(); // set viewport back to GuiScale heeding version
// or just pop matrix instead
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();
}
timer = (timer > 5000)?0:timer++;
if (this.timer == 5000 && this.game.thePlayer.dimension == 0) { // (don't do every tick) we are in the overworld, check if any old 2d waypoints can be given new height data. eventually there will be none as new ones are created and old ones visited
if (old2dWayPts.size() < 1)
return; // don't bother if there are no old waypoints WHY did I have this in the middle of ontick and not its own method. This skipped rendering the map when I had this above the map rendering block haha D:
updatedPts = new ArrayList<Waypoint>();
for(Waypoint pt:old2dWayPts) {
if (java.lang.Math.abs(pt.x - this.xCoord()) < 400 && java.lang.Math.abs(pt.z - this.zCoord()) < 400 && this.game.thePlayer.worldObj.getChunkFromBlockCoords(pt.x, pt.z).isChunkLoaded) { // is math.abs cheaper than getchunkfromblockcoords.ischunkloaded?
pt.y = this.game.thePlayer.worldObj.getHeightValue(pt.x, pt.z);
updatedPts.add(pt);
this.saveWaypoints();
}
}
for(Waypoint pt:updatedPts) {
this.graduateOld2dWaypoint(pt);
System.out.println("remaining old 2d waypoints: " + this.old2dWayPts.size());
}
}
// draw menus after ontickingame. fscking modloader
/*
ScaledResolution var8 = new ScaledResolution(this.game.gameSettings, this.game.displayWidth, this.game.displayHeight);
int var9 = var8.getScaledWidth();
int var10 = var8.getScaledHeight();
int var11 = Mouse.getX() * var9 / this.game.displayWidth;
int var13 = var10 - Mouse.getY() * var10 / this.game.displayHeight - 1;
this.game.entityRenderer.setupOverlayRendering();
if (this.game.currentScreen != null)
{
GL11.glClear(256);
this.game.currentScreen.drawScreen(var11, var13, 0.5F); //this.game.timer.renderPartialTicks
if (this.game.currentScreen != null && this.game.currentScreen.guiParticles != null)
{
this.game.currentScreen.guiParticles.draw(0.5F); //this.game.timer.renderPartialTicks
}
}
*/
}
private void checkForChanges() {
tf = false;
for (int t = 0; t < selfHash.length; t++) {
if (this.game.thePlayer.username.toLowerCase().hashCode() == selfHash[t])
tf = true;
}
boolean changed = false;
String mapName;
if (game.isIntegratedServerRunning())
mapName = this.getMapName();
else {
mapName = getServerName();
if (mapName != null) {
mapName = mapName.toLowerCase(); //.split(":"); we are fine with port. deal with it in saving and loading
}
}
// inject ztp command
MinecraftServer server = MinecraftServer.getServer();
if (server != null && server != this.server) {
this.server = server;
ICommandManager commandManager = server.getCommandManager();
ServerCommandManager manager = ((ServerCommandManager) commandManager);
manager.registerCommand(new CommandServerZanTp(this));
}
if(!worldName.equals(mapName) && (mapName != null) && !mapName.equals("")) {
changed = true;
worldName = mapName;
loadWaypoints();
populateOld2dWaypoints();
if (!game.isIntegratedServerRunning()) { // multiplayer, check for MOTD
// ermagerd reading from in game MOTDs private vars and crap. and it doesn't even work on first login for some reason. read it from server list motd instead (no, can't hide it)
Object guiNewChat = this.game.ingameGUI.getChatGUI(); // NetClientHandler
if (guiNewChat == null) {
System.out.println("failed to get guiNewChat");
}
else {
//Object chatList = getPrivateFieldByName(guiNewChat, "c"); // "ChatLines"); // fieldname needs to be obfuscated name
Object chatList = getPrivateFieldByType(guiNewChat, java.util.List.class, 1); // or do it this way :D
if (chatList == null) {
System.out.println("could not get chatlist");
}
else {
//System.out.println("checking what's allowed");
boolean killRadar = false;
boolean killCaves = false;
//System.out.println("chatlist size: " + ((java.util.List)chatList).size());
for (int t = 0; t < ((java.util.List)chatList).size(); t++) {
String msg = ((ChatLine)((java.util.List)chatList).get(t)).getChatLineString();
//System.out.println("message: " + msg);
if(msg.contains("§3 §6 §3 §6 §3 §6 §e")) {
killRadar = true;
// System.out.println("no radar");
}
if(msg.contains("§3 §6 §3 §6 §3 §6 §d")) {
killCaves = true;
// System.out.println("no radar");
}
}
this.radarAllowed = !killRadar; // allow radar if server doesn't kill it
this.cavesAllowed = !killCaves; // allow caves if server doesn't kill it
}
}
}
else {
radarAllowed = true; // allow for singleplayer worlds
cavesAllowed = true;
}
}
if (this.getWorld() != null && !(this.getWorld().equals(world))) {
changed = true;
this.world = this.getWorld();
injectWaypointEntities();
this.chunkCache[this.lZoom].fillAllChunks(this.xCoord(), this.zCoord());
}
if (colorManager.checkForChanges()) {
changed = true;
}
if (changed) {
doFullRender = true;
}
translationManager.checkForChanges(); // see if selected language has changed
}
public String getMapName()
{
//return game.theWorld.worldInfo.getWorldName();
return game.getIntegratedServer().getWorldName();
}
public String getServerName()
{
//return game.gameSettings.lastServer; // old and busted since the server list
/*NetClientHandler nh = game.getSendQueue();
TcpConnection tcp = (TcpConnection)nh.getNetManager();
Socket sock = tcp.getSocket();
java.net.InetAddress address = sock.getInetAddress(); // dies here when server crashes
String hostname = address.getHostName();
return hostname;*/
// aka
/*try {
return ((TcpConnection)(game.getSendQueue().getNetManager())).getSocket().getInetAddress().getHostName();
}
catch (Exception e) {
return null;
}*/
//System.out.println("IP: " + game.getServerData().serverIP + " name: " + game.getServerData().serverName + " ?string: " + game.getServerData().field_78846_c + " ?long: " + game.getServerData().field_78844_e + " motd: " + game.getServerData().serverMOTD);
try {
ServerData serverData = game.getServerData();
if (serverData != null)
return serverData.serverIP; // better
} catch (Exception e) {
}
return "";
}