-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathCommonProxy.java
More file actions
355 lines (308 loc) · 16.6 KB
/
CommonProxy.java
File metadata and controls
355 lines (308 loc) · 16.6 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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package com.gregtechceu.gtceu.common;
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTCEuAPI;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.addon.AddonFinder;
import com.gregtechceu.gtceu.api.addon.IGTAddon;
import com.gregtechceu.gtceu.api.capability.GTCapability;
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
import com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialEvent;
import com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialRegistryEvent;
import com.gregtechceu.gtceu.api.data.chemical.material.event.PostMaterialEvent;
import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconSet;
import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconType;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.data.worldgen.WorldGenLayers;
import com.gregtechceu.gtceu.api.data.worldgen.generator.IndicatorGenerators;
import com.gregtechceu.gtceu.api.data.worldgen.generator.VeinGenerators;
import com.gregtechceu.gtceu.api.gui.factory.GTUIEditorFactory;
import com.gregtechceu.gtceu.api.gui.factory.MachineUIFactory;
import com.gregtechceu.gtceu.api.mui.factory.CoverUIFactory;
import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic;
import com.gregtechceu.gtceu.api.recipe.ingredient.*;
import com.gregtechceu.gtceu.api.recipe.lookup.ingredient.*;
import com.gregtechceu.gtceu.api.recipe.lookup.ingredient.fluid.*;
import com.gregtechceu.gtceu.api.recipe.lookup.ingredient.item.*;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.*;
import com.gregtechceu.gtceu.common.data.GTPlaceholders;
import com.gregtechceu.gtceu.common.data.machines.GTMachineUtils;
import com.gregtechceu.gtceu.common.data.materials.GTFoods;
import com.gregtechceu.gtceu.common.item.tool.rotation.CustomBlockRotations;
import com.gregtechceu.gtceu.common.machine.multiblock.electric.FusionReactorMachine;
import com.gregtechceu.gtceu.common.machine.owner.MachineOwner;
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.common.registry.GTRegistration;
import com.gregtechceu.gtceu.common.unification.material.MaterialRegistryManager;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.core.mixins.registrate.AbstractRegistrateAccessor;
import com.gregtechceu.gtceu.data.GregTechDatagen;
import com.gregtechceu.gtceu.data.lang.MaterialLangGenerator;
import com.gregtechceu.gtceu.data.loot.ChestGenHooks;
import com.gregtechceu.gtceu.data.loot.DungeonLootLoader;
import com.gregtechceu.gtceu.data.pack.GTDynamicDataPack;
import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack;
import com.gregtechceu.gtceu.data.pack.GTPackSource;
import com.gregtechceu.gtceu.data.recipe.GTCraftingComponents;
import com.gregtechceu.gtceu.integration.ae2.GTAEPlaceholders;
import com.gregtechceu.gtceu.integration.cctweaked.CCTweakedPlugin;
import com.gregtechceu.gtceu.integration.create.GTCreateIntegration;
import com.gregtechceu.gtceu.integration.kjs.GTCEuStartupEvents;
import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo;
import com.gregtechceu.gtceu.integration.kjs.events.MaterialModificationEventJS;
import com.gregtechceu.gtceu.integration.map.WaypointManager;
import com.gregtechceu.gtceu.utils.input.KeyBind;
import com.gregtechceu.gtceu.utils.input.SyncedKeyMappings;
import com.lowdragmc.lowdraglib.gui.factory.UIFactory;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IntersectionIngredient;
import net.minecraftforge.common.crafting.PartialNBTIngredient;
import net.minecraftforge.common.crafting.StrictNBTIngredient;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
import net.minecraftforge.registries.RegisterEvent;
import brachy.modularui.factory.GuiManager;
import com.google.common.collect.Multimaps;
import com.tterrag.registrate.providers.ProviderType;
import com.tterrag.registrate.providers.RegistrateLangProvider;
import com.tterrag.registrate.providers.RegistrateProvider;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import java.util.List;
public class CommonProxy {
public CommonProxy() {
// used for forge events (ClientProxy + CommonProxy)
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
eventBus.register(this);
// must be set here because of KubeJS compat
// trying to read this before the pre-init stage
GTCEuAPI.materialManager = MaterialRegistryManager.getInstance();
ConfigHolder.init();
GTCEuAPI.initializeHighTier();
// MUI stuff
GTGuiTextures.init();
GuiManager.registerFactory(com.gregtechceu.gtceu.api.mui.factory.MachineUIFactory.INSTANCE);
GuiManager.registerFactory(CoverUIFactory.INSTANCE);
if (GTCEu.isDev()) {
ConfigHolder.INSTANCE.recipes.generateLowQualityGems = true;
ConfigHolder.INSTANCE.compat.energy.enableFEConverters = true;
}
GTValueProviderTypes.init(eventBus);
GTRegistries.init(eventBus);
GTFeatures.init(eventBus);
GTCommandArguments.init(eventBus);
GTMobEffects.init(eventBus);
GTParticleTypes.init(eventBus);
}
public static void init() {
GTCEu.LOGGER.info("GTCEu common proxy init!");
GTNetwork.init();
UIFactory.register(MachineUIFactory.INSTANCE);
UIFactory.register(GTUIEditorFactory.INSTANCE);
// Initialize the model generator before any content is loaded so machine models can use the generated data
GregTechDatagen.initPre();
GTRecipeCapabilities.init();
GTRecipeConditions.init();
GTToolTiers.init();
GTElements.init();
MaterialIconSet.init();
MaterialIconType.init();
initMaterials();
TagPrefix.init();
GTSoundEntries.init();
GTDamageTypes.init();
GTPlaceholders.initPlaceholders();
if (ConfigHolder.INSTANCE.compat.createCompat && GTCEu.Mods.isCreateLoaded()) {
GTCreateIntegration.init();
}
if (GTCEu.Mods.isAE2Loaded()) {
GTAEPlaceholders.init();
}
GTCovers.init();
GTCreativeModeTabs.init();
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
GTMenuTypes.init(modBus);
GTBlocks.init();
GTFluids.init();
GTEntityTypes.init();
GTBlockEntities.init();
GTRecipeTypes.init();
GTRecipeCategories.init();
GTMachineUtils.init();
GTMachines.init();
GTFoods.init();
GTItems.init();
GTDimensionMarkers.init();
ChanceLogic.init();
WaypointManager.init();
AddonFinder.getAddons().forEach(IGTAddon::initializeAddon);
GTRegistration.REGISTRATE.registerRegistrate();
GregTechDatagen.initPost();
// Register all material manager registries, for materials with mod ids.
GTCEuAPI.materialManager.getRegistries().forEach(registry -> {
// Force the material lang generator to be at index 0, so that addons' lang generators can override it.
AbstractRegistrateAccessor accessor = (AbstractRegistrateAccessor) registry.getRegistrate();
if (accessor.getDoDatagen().get()) {
// noinspection UnstableApiUsage
List<NonNullConsumer<? extends RegistrateProvider>> providers = Multimaps.asMap(accessor.getDatagens())
.get(ProviderType.LANG);
NonNullConsumer<? extends RegistrateProvider> generator = (provider) -> MaterialLangGenerator
.generate((RegistrateLangProvider) provider, registry);
if (providers == null) {
accessor.getDatagens().put(ProviderType.LANG, generator);
} else {
providers.add(0, generator);
}
}
registry.getRegistrate()
.registerEventListeners(ModList.get().getModContainerById(registry.getModid())
.filter(FMLModContainer.class::isInstance)
.map(FMLModContainer.class::cast)
.map(FMLModContainer::getEventBus)
.orElse(FMLJavaModLoadingContext.get().getModEventBus()));
});
WorldGenLayers.registerAll();
VeinGenerators.registerAddonGenerators();
IndicatorGenerators.registerAddonGenerators();
GTFeatures.init();
GTFeatures.register();
CustomBlockRotations.init();
KeyBind.init();
SyncedKeyMappings.init();
MachineOwner.init();
FusionReactorMachine.registerFusionTier(GTValues.LuV, " (MKI)");
FusionReactorMachine.registerFusionTier(GTValues.ZPM, " (MKII)");
FusionReactorMachine.registerFusionTier(GTValues.UV, " (MKIII)");
}
@SubscribeEvent
public void preInit(FMLConstructModEvent event) {}
private static void initMaterials() {
// First, register other mods' Registries
MaterialRegistryManager managerInternal = (MaterialRegistryManager) GTCEuAPI.materialManager;
GTCEu.LOGGER.info("Registering material registries");
ModLoader.get().postEvent(new MaterialRegistryEvent());
// First, register CEu Materials
managerInternal.unfreezeRegistries();
GTCEu.LOGGER.info("Registering GTCEu Materials");
GTMaterials.init();
MaterialRegistryManager.getInstance()
.getRegistry(GTCEu.MOD_ID)
.setFallbackMaterial(GTMaterials.Aluminium);
// Then, register addon Materials
GTCEu.LOGGER.info("Registering addon Materials");
MaterialEvent materialEvent = new MaterialEvent();
ModLoader.get().postEvent(materialEvent);
if (GTCEu.Mods.isKubeJSLoaded()) {
KJSEventWrapper.materialRegistry();
}
// Fire Post-Material event, intended for when Materials need to be iterated over in-full before freezing
// Block entirely new Materials from being added in the Post event
managerInternal.closeRegistries();
ModLoader.get().postEvent(new PostMaterialEvent());
if (GTCEu.Mods.isKubeJSLoaded()) {
KJSEventWrapper.materialModification();
}
// Freeze Material Registry before processing Items, Blocks, and Fluids
managerInternal.freezeRegistries();
/* End Material Registration */
}
@SubscribeEvent
public void register(RegisterEvent event) {
if (event.getRegistryKey().equals(BuiltInRegistries.LOOT_FUNCTION_TYPE.key()))
ChestGenHooks.RandomWeightLootFunction.init();
}
@SubscribeEvent
public void modConstruct(FMLConstructModEvent event) {
// this is done to delay initialization of content to be after KJS has set up.
event.enqueueWork(CommonProxy::init);
}
@SubscribeEvent
public void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
CraftingHelper.register(SizedIngredient.TYPE, SizedIngredient.SERIALIZER);
CraftingHelper.register(IntCircuitIngredient.TYPE, IntCircuitIngredient.SERIALIZER);
CraftingHelper.register(IntProviderIngredient.TYPE, IntProviderIngredient.SERIALIZER);
CraftingHelper.register(NBTPredicateIngredient.TYPE, NBTPredicateIngredient.Serializer.INSTANCE);
CraftingHelper.register(FluidContainerIngredient.TYPE, FluidContainerIngredient.SERIALIZER);
// register the map ingredient converters for all of our ingredients
MapIngredientTypeManager.registerMapIngredient(FluidIngredient.class, FluidTagMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(FluidIngredient.class, FluidStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(FluidStack.class, FluidTagMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(FluidStack.class, FluidStackMapIngredient::from);
// spotless:off
MapIngredientTypeManager.registerMapIngredient(SizedIngredient.class,
(ingredient) -> MapIngredientTypeManager.getFrom(ingredient.getInner(), ItemRecipeCapability.CAP));
MapIngredientTypeManager.registerMapIngredient(IntProviderIngredient.class,
(ingredient) -> MapIngredientTypeManager.getFrom(ingredient.getInner(), ItemRecipeCapability.CAP));
MapIngredientTypeManager.registerMapIngredient(StrictNBTIngredient.class, StrictNBTItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(PartialNBTIngredient.class, PartialNBTItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(NBTPredicateIngredient.class, NBTPredicateItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(IntersectionIngredient.class, IntersectionMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(Ingredient.class, ItemTagMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(Ingredient.class, ItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, ItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, ItemTagMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, StrictNBTItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, PartialNBTItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, NBTPredicateItemStackMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, IntersectionMapIngredient::from);
MapIngredientTypeManager.registerMapIngredient(ItemStack.class, CustomMapIngredient::from);
// spotless:on
if (GTCEu.Mods.isCCTweakedLoaded()) {
GTCEu.LOGGER.info("CC: Tweaked found. Enabling integration...");
CCTweakedPlugin.init();
}
});
}
@SubscribeEvent
public void registerCapabilities(RegisterCapabilitiesEvent event) {
GTCapability.register(event);
}
@SubscribeEvent
public void registerPackFinders(AddPackFindersEvent event) {
if (event.getPackType() == PackType.CLIENT_RESOURCES) {
// Clear old data
GTDynamicResourcePack.clearClient();
event.addRepositorySource(new GTPackSource("gtceu:dynamic_assets",
event.getPackType(),
Pack.Position.BOTTOM,
GTDynamicResourcePack::new));
} else if (event.getPackType() == PackType.SERVER_DATA) {
// Clear old data
GTDynamicDataPack.clearServer();
long startTime = System.currentTimeMillis();
GTCraftingComponents.init();
GTRecipes.recipeRemoval();
GTRecipes.recipeAddition(GTDynamicDataPack::addRecipe);
// Initialize dungeon loot additions
DungeonLootLoader.init();
GTCEu.LOGGER.info("GregTech Data loading took {}ms", System.currentTimeMillis() - startTime);
event.addRepositorySource(new GTPackSource("gtceu:dynamic_data",
event.getPackType(),
Pack.Position.BOTTOM,
GTDynamicDataPack::new));
}
}
public static final class KJSEventWrapper {
public static void materialRegistry() {
GTRegistryInfo.registerFor(GTCEuAPI.materialManager.getRegistry(GTCEu.MOD_ID).getRegistryName());
}
public static void materialModification() {
GTCEuStartupEvents.MATERIAL_MODIFICATION.post(new MaterialModificationEventJS());
}
}
}