-
Notifications
You must be signed in to change notification settings - Fork 609
/
AppEng.java
295 lines (238 loc) · 9.73 KB
/
AppEng.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
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import net.minecraft.world.DimensionType;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import appeng.api.AEApi;
import appeng.core.crash.CrashInfo;
import appeng.core.crash.IntegrationCrashEnhancement;
import appeng.core.crash.ModCrashEnhancement;
import appeng.core.features.AEFeature;
import appeng.core.stats.AdvancementTriggers;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.recipes.CustomRecipeConfig;
import appeng.recipes.CustomRecipeForgeConfiguration;
import appeng.server.AECommand;
import appeng.services.VersionChecker;
import appeng.services.export.ExportConfig;
import appeng.services.export.ExportProcess;
import appeng.services.export.ForgeExportConfig;
import appeng.services.version.VersionCheckerConfig;
import appeng.util.Platform;
@Mod( modid = AppEng.MOD_ID, acceptedMinecraftVersions = "[1.12.2]", name = AppEng.MOD_NAME, version = AEConfig.VERSION, dependencies = AppEng.MOD_DEPENDENCIES, guiFactory = "appeng.client.gui.config.AEConfigGuiFactory" )
public final class AppEng
{
@SidedProxy( clientSide = "appeng.client.ClientHelper", serverSide = "appeng.server.ServerHelper", modId = AppEng.MOD_ID )
public static CommonHelper proxy;
public static final String MOD_ID = "appliedenergistics2";
public static final String MOD_NAME = "Applied Energistics 2";
public static final String ASSETS = "appliedenergistics2:";
public static final String MOD_DEPENDENCIES =
// a few mods, AE should load after, probably.
// required-after:AppliedEnergistics2API|all;
// "after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
// depend on version of forge used for build.
"after:appliedenergistics2-core;";// + "required-after:Forge@[" // require forge.
// + net.minecraftforge.common.ForgeVersion.majorVersion + '.' // majorVersion
// + net.minecraftforge.common.ForgeVersion.minorVersion + '.' // minorVersion
// + net.minecraftforge.common.ForgeVersion.revisionVersion + '.' // revisionVersion
// + net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
@Nonnull
private static final AppEng INSTANCE = new AppEng();
private final Registration registration;
private File configDirectory;
private CustomRecipeConfig customRecipeConfig;
/**
* Folder for recipes
*
* used for CSV item names and the recipes
*/
private File recipeDirectory;
/**
* determined in pre-init but used in init
*/
private ExportConfig exportConfig;
private AppEng()
{
FMLCommonHandler.instance().registerCrashCallable( new ModCrashEnhancement( CrashInfo.MOD_VERSION ) );
this.registration = new Registration();
MinecraftForge.EVENT_BUS.register( this.registration );
}
@Nonnull
@Mod.InstanceFactory
public static AppEng instance()
{
return INSTANCE;
}
public Biome getStorageBiome()
{
return this.registration.storageBiome;
}
public DimensionType getStorageDimensionType()
{
return this.registration.storageDimensionType;
}
public int getStorageDimensionID()
{
return this.registration.storageDimensionID;
}
public AdvancementTriggers getAdvancementTriggers()
{
return this.registration.advancementTriggers;
}
@EventHandler
private void preInit( final FMLPreInitializationEvent event )
{
final Stopwatch watch = Stopwatch.createStarted();
this.configDirectory = new File( event.getModConfigurationDirectory().getPath(), "AppliedEnergistics2" );
this.recipeDirectory = new File( this.configDirectory, "aerecipes" );
final File configFile = new File( this.configDirectory, "AppliedEnergistics2.cfg" );
final File facadeFile = new File( this.configDirectory, "Facades.cfg" );
final File versionFile = new File( this.configDirectory, "VersionChecker.cfg" );
final File recipeFile = new File( this.configDirectory, "CustomRecipes.cfg" );
final Configuration recipeConfiguration = new Configuration( recipeFile );
AEConfig.init( configFile );
FacadeConfig.init( facadeFile );
final VersionCheckerConfig versionCheckerConfig = new VersionCheckerConfig( versionFile );
this.customRecipeConfig = new CustomRecipeForgeConfiguration( recipeConfiguration );
this.exportConfig = new ForgeExportConfig( recipeConfiguration );
this.registration.setRecipeInformation( this.recipeDirectory, this.customRecipeConfig );
AELog.info( "Pre Initialization ( started )" );
CreativeTab.init();
if( AEConfig.instance().isFeatureEnabled( AEFeature.FACADES ) )
{
CreativeTabFacade.init();
}
for( final IntegrationType type : IntegrationType.values() )
{
IntegrationRegistry.INSTANCE.add( type );
}
this.registration.preInitialize( event );
if( Platform.isClient() )
{
AppEng.proxy.preinit();
}
if( versionCheckerConfig.isVersionCheckingEnabled() )
{
final VersionChecker versionChecker = new VersionChecker( versionCheckerConfig );
final Thread versionCheckerThread = new Thread( versionChecker );
this.startService( "AE2 VersionChecker", versionCheckerThread );
}
AELog.info( "Pre Initialization ( ended after " + watch.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
// Instantiate all Plugins
List<Object> injectables = Lists.newArrayList(
AEApi.instance() );
new PluginLoader().loadPlugins( injectables, event.getAsmData() );
}
private void startService( final String serviceName, final Thread thread )
{
thread.setName( serviceName );
thread.setPriority( Thread.MIN_PRIORITY );
AELog.info( "Starting " + serviceName );
thread.start();
}
@EventHandler
private void init( final FMLInitializationEvent event )
{
final Stopwatch start = Stopwatch.createStarted();
AELog.info( "Initialization ( started )" );
if( this.exportConfig.isExportingItemNamesEnabled() )
{
if( FMLCommonHandler.instance().getSide().isClient() )
{
final ExportProcess process = new ExportProcess( this.recipeDirectory, this.exportConfig );
final Thread exportProcessThread = new Thread( process );
this.startService( "AE2 CSV Export", exportProcessThread );
}
else
{
AELog.info( "Disabling item.csv export for custom recipes, since creative tab information is only available on the client." );
}
}
this.registration.initialize( event, this.recipeDirectory, this.customRecipeConfig );
IntegrationRegistry.INSTANCE.init();
AELog.info( "Initialization ( ended after " + start.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
}
@EventHandler
private void postInit( final FMLPostInitializationEvent event )
{
final Stopwatch start = Stopwatch.createStarted();
AELog.info( "Post Initialization ( started )" );
this.registration.postInit( event );
IntegrationRegistry.INSTANCE.postInit();
FMLCommonHandler.instance().registerCrashCallable( new IntegrationCrashEnhancement() );
AppEng.proxy.postInit();
AEConfig.instance().save();
NetworkRegistry.INSTANCE.registerGuiHandler( this, GuiBridge.GUI_Handler );
NetworkHandler.init( "AE2" );
AELog.info( "Post Initialization ( ended after " + start.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
}
@EventHandler
private void handleIMCEvent( final FMLInterModComms.IMCEvent event )
{
final IMCHandler imcHandler = new IMCHandler();
imcHandler.handleIMCEvent( event );
}
@EventHandler
private void serverAboutToStart( final FMLServerAboutToStartEvent evt )
{
WorldData.onServerAboutToStart( evt.getServer() );
}
@EventHandler
private void serverStopping( final FMLServerStoppingEvent event )
{
WorldData.instance().onServerStopping();
}
@EventHandler
private void serverStopped( final FMLServerStoppedEvent event )
{
WorldData.instance().onServerStoppped();
TickHandler.INSTANCE.shutdown();
}
@EventHandler
private void serverStarting( final FMLServerStartingEvent evt )
{
evt.registerServerCommand( new AECommand( evt.getServer() ) );
}
}