MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / ClassProxy

Class ClassProxy

Minecraft-Utils/1.8.9/src/ClassProxy.java:23–408  ·  view source on GitHub ↗

Created by 5zig. All rights reserved © 2015

Source from the content-addressed store, hash-verified

21 * All rights reserved © 2015
22 */
23public class ClassProxy {
24
25 private static final Field byteBuf;
26 private static Field buttonList;
27 private static final Field serverList;
28
29 private static boolean tryFix = false;
30
31 private static final UUID SPRINT_MODIFIER_UUID = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
32
33 private ClassProxy() {
34 }
35
36 static {
37 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
38 try {
39 Class<?> c = classLoader.loadClass(Names.packetBuffer.getName());
40 byteBuf = Transformer.FORGE ? c.getDeclaredField("field_150794_a") : c.getDeclaredField("a");
41 byteBuf.setAccessible(true);
42 if (Transformer.FORGE) {
43 buttonList = classLoader.loadClass(Names.guiScreen.getName()).getDeclaredField("field_146292_n");
44 buttonList.setAccessible(true);
45 }
46 Class<azl> aClass = azl.class;
47 if (Transformer.FORGE) {
48 serverList = aClass.getDeclaredField("field_148198_l");
49 } else {
50 serverList = aClass.getDeclaredField("v");
51 }
52 serverList.setAccessible(true);
53 } catch (Exception e) {
54 throw new RuntimeException(e);
55 }
56
57 /*if (Transformer.FORGE) {
58 // Forge mod list
59 try {
60 Class<?> metadataClass = classLoader.loadClass("net.minecraftforge.fml.common.ModMetadata");
61 Object metadata = metadataClass.newInstance();
62 metadataClass.getField("modId").set(metadata, "the5zigmod");
63 metadataClass.getField("name").set(metadata, "The 5zig Mod");
64 metadataClass.getField("version").set(metadata, Version.VERSION);
65 metadataClass.getField("description").set(metadata, "A mod that enhances your Minecraft PvP experience by displaying all kinds of useful stats.");
66 metadataClass.getField("url").set(metadata, "https://5zig.eu");
67 metadataClass.getField("authorList").set(metadata, Collections.singletonList("5zig"));
68 Class<?> modContainerClass = classLoader.loadClass("net.minecraftforge.fml.common.DummyModContainer");
69 Object modContainer = modContainerClass.getConstructor(metadataClass).newInstance(metadata);
70
71 Class<?> loaderClass = classLoader.loadClass("net.minecraftforge.fml.common.Loader");
72 Object loader = loaderClass.getMethod("instance").invoke(null);
73 Field modListField = loaderClass.getDeclaredField("mods");
74 modListField.setAccessible(true);
75 List list = Lists.newArrayList((List) modListField.get(loader));
76 list.add(modContainer);
77 modListField.set(loader, ImmutableList.copyOf(list));
78 Class<?> loadControllerClass = classLoader.loadClass("net.minecraftforge.fml.common.LoadController");
79 Field modControllerField = loaderClass.getDeclaredField("modController");
80 modControllerField.setAccessible(true);

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.45

Tested by

no test coverage detected