-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathGTCEu.java
More file actions
247 lines (206 loc) · 7.77 KB
/
GTCEu.java
File metadata and controls
247 lines (206 loc) · 7.77 KB
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
package com.gregtechceu.gtceu;
import com.gregtechceu.gtceu.api.GTCEuAPI;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.client.ClientProxy;
import com.gregtechceu.gtceu.common.CommonProxy;
import com.gregtechceu.gtceu.utils.FormattingUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.server.ServerLifecycleHooks;
import dev.emi.emi.config.EmiConfig;
import me.shedaniel.rei.api.client.REIRuntime;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.nio.file.Path;
@Mod(GTCEu.MOD_ID)
public class GTCEu {
public static final String MOD_ID = "gtceu";
private static final ResourceLocation TEMPLATE_LOCATION = new ResourceLocation(MOD_ID, "");
public static final String NAME = "GregTechCEu";
public static final Logger LOGGER = LogManager.getLogger(NAME);
public static final Path GTCEU_FOLDER = getGameDir().resolve("gtceu");
/**
* Only used for datafixers. Bump whenever a block changes id, save data layout changes, etc.<br>
* Should be bumped up to the next multiple of 10 the first time it is bumped after a release, then by 1 for each
* subsequent change.
*
* <p>
* Example versions:
* <ul>
* <li>0: 7.5.3</li>
* <li>10: 8.0.0-SNAPSHOT+HASH1</li> // TODO set the correct hash here
* <li>11: 8.0.0-SNAPSHOT+HASH2</li>
* <li>20: 8.0.1-SNAPSHOT+HASH2</li>
* </ul>
*/
public static final int GT_DATA_VERSION = 10;
public GTCEu() {
GTCEu.init();
GTCEuAPI.instance = this;
DistExecutor.unsafeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
}
public static void init() {
LOGGER.info("{} is initializing...", NAME);
}
public static ResourceLocation id(String path) {
if (path.isBlank()) {
return TEMPLATE_LOCATION;
}
int i = path.indexOf(':');
if (i > 0) {
return new ResourceLocation(path);
} else if (i == 0) {
path = path.substring(i + 1);
}
// only convert it to camel_case if it has any uppercase to begin with
if (FormattingUtil.hasUpperCase(path)) {
path = FormattingUtil.toLowerCaseUnderscore(path);
}
return TEMPLATE_LOCATION.withPath(path);
}
public static String appendIdString(String id) {
int i = id.indexOf(':');
if (i > 0) {
return id;
} else if (i == 0) {
return MOD_ID + id;
} else {
return MOD_ID + ":" + id;
}
}
/**
* @return if we're running in a production environment
*/
public static boolean isProd() {
return FMLLoader.isProduction();
}
/**
* @return if we're not running in a production environment
*/
public static boolean isDev() {
return !isProd();
}
/**
* @return if we're running data generation
*/
public static boolean isDataGen() {
return FMLLoader.getLaunchHandler().isData();
}
/**
* A friendly reminder that the server instance is populated on the server side only, so null/side check it!
*
* @return the current minecraft server instance
*/
public static MinecraftServer getMinecraftServer() {
return ServerLifecycleHooks.getCurrentServer();
}
/**
* @param modId the mod id to check for
* @return if the mod whose id is {@code modId} is loaded or not
*/
public static boolean isModLoaded(String modId) {
return ModList.get().isLoaded(modId);
}
/**
* For async stuff use this, otherwise use {@link GTCEu isClientSide}
*
* @return if the current thread is the client thread
*/
public static boolean isClientThread() {
return isClientSide() && Minecraft.getInstance().isSameThread();
}
/**
* @return if the game is the <strong>PHYSICAL</strong> client, e.g. not a dedicated server.
* @apiNote Do not use this to check if you're currently on the server thread for side-specific actions!
* It does <strong>NOT</strong> work for that. Use {@link #isClientThread()} instead.
* @see #isClientThread()
*/
public static boolean isClientSide() {
return FMLEnvironment.dist.isClient();
}
/**
* This check isn't the same for client and server!
*
* @return if it's safe to access the current instance {@link net.minecraft.world.level.Level Level} on client or if
* it's safe to access any level on server.
*/
public static boolean canGetServerLevel() {
if (isClientSide()) {
return Minecraft.getInstance().level != null;
}
var server = getMinecraftServer();
return server != null &&
!(server.isStopped() || server.isShutdown() || !server.isRunning() || server.isCurrentlySaving());
}
/**
* @return the path to the minecraft instance directory
*/
public static Path getGameDir() {
return FMLPaths.GAMEDIR.get();
}
public static class Mods {
public static boolean isJEILoaded() {
return !(isModLoaded(GTValues.MODID_EMI) || isModLoaded(GTValues.MODID_REI)) &&
isModLoaded(GTValues.MODID_JEI);
}
public static boolean isREILoaded() {
return isModLoaded(GTValues.MODID_REI) && (!isClientSide() || REIRuntime.getInstance().isOverlayVisible());
}
public static boolean isEMILoaded() {
return isModLoaded(GTValues.MODID_EMI) && (!isClientSide() || EmiConfig.enabled);
}
public static boolean isKubeJSLoaded() {
return isModLoaded(GTValues.MODID_KUBEJS);
}
public static boolean isIrisOculusLoaded() {
return isModLoaded(GTValues.MODID_IRIS) || isModLoaded(GTValues.MODID_OCULUS);
}
public static boolean isSodiumRubidiumEmbeddiumLoaded() {
return isModLoaded(GTValues.MODID_SODIUM) || isModLoaded(GTValues.MODID_RUBIDIUM) ||
isModLoaded(GTValues.MODID_EMBEDDIUM);
}
public static boolean isAE2Loaded() {
return isModLoaded(GTValues.MODID_APPENG);
}
public static boolean isCuriosLoaded() {
return isModLoaded(GTValues.MODID_CURIOS);
}
public static boolean isShimmerLoaded() {
return isModLoaded(GTValues.MODID_SHIMMER);
}
public static boolean isModernFixLoaded() {
return isModLoaded(GTValues.MODID_MODERNFIX);
}
public static boolean isJAVDLoaded() {
return isModLoaded(GTValues.MODID_JAVD);
}
public static boolean isFTBTeamsLoaded() {
return isModLoaded(GTValues.MODID_FTB_TEAMS);
}
public static boolean isHeraclesLoaded() {
return isModLoaded(GTValues.MODID_HERACLES);
}
public static boolean isFTBQuestsLoaded() {
return isModLoaded(GTValues.MODID_FTB_QUEST);
}
public static boolean isArgonautsLoaded() {
return isModLoaded(GTValues.MODID_ARGONAUTS);
}
public static boolean isGameStagesLoaded() {
return isModLoaded(GTValues.MODID_GAMESTAGES);
}
public static boolean isCCTweakedLoaded() {
return isModLoaded(GTValues.MODID_CCTWEAKED);
}
public static boolean isCreateLoaded() {
return isModLoaded(GTValues.MODID_CREATE);
}
}
}