forked from MamiyaOtaru/voxelmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_ZanMinimap.java
92 lines (79 loc) · 3.05 KB
/
mod_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
package net.minecraft.src;
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.MinimapGuiInGame;
import net.minecraft.src.mamiyaotaru.RenderWaypoint;
public class mod_ZanMinimap extends BaseMod {
ZanMinimap minimap;
GuiIngame realGui;
MinimapGuiInGame fakeGui;
boolean haveRenderManager = false;
MinecraftServer server = null;
public String getVersion()
{
return "3.1.4.2.0";
}
public void load() {
minimap = new ZanMinimap();
ModLoader.setInGameHook(this, true, false);
realGui = ModLoader.getMinecraftInstance().ingameGUI;
fakeGui = new MinimapGuiInGame(ModLoader.getMinecraftInstance(), minimap, realGui);
}
public String ModName()
{
return "Zan's Minimap";
}
public boolean onTickInGame(float f, Minecraft var1) {
if (!haveRenderManager) { // only run once. we do go through onTick multiple times to catch when advancedHUD gets called after this and takes over ingameGUI
Object renderManager = RenderManager.instance; // NetClientHandler
if (renderManager == null) {
// System.out.println("failed to get render manager");
}
else {
//Object entityRenderMap = getPrivateFieldByName(renderManager, "o" /*"entityRenderMap"*/); // Map - fieldname needs to be obfuscated name
Object entityRenderMap = getPrivateFieldByType(renderManager, java.util.Map.class); // Map - fieldname needs to be obfuscated name
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);
haveRenderManager = true; // don't do again
}
}
}
if (var1.ingameGUI.getClass() != MinimapGuiInGame.class) {
realGui = var1.ingameGUI;
fakeGui.realGui = realGui;
var1.ingameGUI = fakeGui;
}
//if (ModLoader.getMinecraftInstance().currentScreen == null) // if we give up on controlling ingamegui
// minimap.onTickInGame(var1); return true; }
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;
}
}