forked from ReikaKalseki/DragonAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DragonAPICore.java
192 lines (152 loc) · 5.75 KB
/
DragonAPICore.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
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2016
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.DragonAPI;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
import java.util.UUID;
import net.minecraftforge.common.ForgeVersion;
import Reika.DragonAPI.Exception.MisuseException;
import Reika.DragonAPI.Instantiable.Event.Client.GameFinishedLoadingEvent;
import Reika.DragonAPI.Libraries.Java.ReikaJavaLibrary;
import Reika.DragonAPI.Libraries.Java.ReikaObfuscationHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.FMLInjectionData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class DragonAPICore {
protected DragonAPICore() {throw new MisuseException("The class "+this.getClass()+" cannot be instantiated!");}
public static final Random rand = new Random();
private static final boolean reika = calculateReikasComputer();
public static final String last_API_Version = "@MAJOR_VERSION@"+"@MINOR_VERSION@";
public static boolean debugtest = false;
private static boolean loaded;
private static final long launchTime = ManagementFactory.getRuntimeMXBean().getStartTime();
private static final String MINFORGE = "required-after:Forge@[10.13.4.1558,);"; //was 1205/1231/1291
public static final String dependencies = MINFORGE+"after:BuildCraft|Energy;after:IC2;after:ThermalExpansion;after:Thaumcraft;"+
"after:powersuits;after:GalacticCraft;after:Mystcraft;after:UniversalElectricity;after:Forestry;after:MagicBees;"+
"after:BinnieCore;after:Natura;after:TConstruct;after:ProjRed|Core;after:bluepower;after:Waila;after:funkylocomotion;after:chisel;"+
"after:ComputerCraft;after:ThermalFoundation;after:CarpentersBlocks";
public static final String FORUM_PAGE = "http://www.minecraftforum.net/topic/1969694-";
public static final UUID Reika_UUID = UUID.fromString("e5248026-6874-4954-9a02-aa8910d08f31");
public static URL getReikaForumPage() {
try {
return new URL(FORUM_PAGE);
}
catch (MalformedURLException e) {
DragonAPICore.logError("Reika's mods provided a malformed URL for their documentation site!");
e.printStackTrace();
return null;
}
}
public static final boolean hasAllClasses() {
return true;
}
public static File getMinecraftDirectory() {
return (File)FMLInjectionData.data()[6];
}
public static String getMinecraftDirectoryString() {
String s = getMinecraftDirectory().getAbsolutePath();
if (s.endsWith("/.") || s.endsWith("\\.")) {
s = s.substring(0, s.length()-2);
}
s = s.replaceAll("\\\\", "/");
return s;
}
private static boolean calculateReikasComputer() {
try {
String username = System.getProperty("user.name");
boolean win = System.getProperty("os.name").equals("Windows 7");
int cpus = Runtime.getRuntime().availableProcessors();
String cpu = System.getProperty("os.arch");
long diskSize = new File("c:").getTotalSpace();
if (win && "amd64".equals(cpu)) {
if (diskSize == 484964069376L && cpus == 4 && "RadicalOne".equals(username))
return true;
if (diskSize == 119926681600L && cpus == 8 && "Reika".equals(username))
return true;
}
return false;
}
catch (Throwable e) {
return false;
}
}
public static boolean isReikasComputer() {
return reika;
}
static {
if (isReikasComputer())
ReikaJavaLibrary.pConsole("DRAGONAPI: Loading on Reika's computer; Dev features enabled.");
//ReikaMathCacher.initalize();
validateForgeVersions();
}
protected static Side getSide() {
return FMLCommonHandler.instance().getEffectiveSide();
}
private static void validateForgeVersions() {
int major = ForgeVersion.majorVersion;
int minor = ForgeVersion.minorVersion;
int rev = ForgeVersion.revisionVersion;
int build = ForgeVersion.buildVersion;
int recbuild = 1291;
if (build < recbuild) {
log("The version of Forge you are using is compatible but not recommended.");
log(String.format("Consider updating to at least %d.%d.%d.%d.", major, minor, rev, recbuild));
}
}
public static boolean isOnActualServer() {
return getSide() == Side.SERVER && FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
}
public static boolean isSinglePlayer() {
return getSide() == Side.SERVER && !FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
}
public static void debugPrint(Object o) {
ReikaJavaLibrary.pConsole(o);
if (!ReikaObfuscationHelper.isDeObfEnvironment())
Thread.dumpStack();
}
public static void debug(Object s) {
DragonAPIInit.instance.getModLogger().debug(s);
}
public static void log(Object s) {
DragonAPIInit.instance.getModLogger().log(s);
}
public static void logError(Object s) {
DragonAPIInit.instance.getModLogger().logError(s);
}
public static void logError(Object o, Side side) {
if (FMLCommonHandler.instance().getEffectiveSide() == side)
logError(o);
}
public static class DragonAPILoadWatcher {
public static final DragonAPILoadWatcher instance = new DragonAPILoadWatcher();
private DragonAPILoadWatcher() {
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void load(GameFinishedLoadingEvent evt) {
loaded = true;
}
}
public static boolean hasGameLoaded() {
return loaded;
}
public static long getLaunchTime() {
return launchTime;
}
public static int getSystemTimeAsInt() {
long t = System.currentTimeMillis();
return (int)(t%(Integer.MAX_VALUE+1));
}
}