-
Notifications
You must be signed in to change notification settings - Fork 897
Expand file tree
/
Copy pathTConstruct.java
More file actions
322 lines (294 loc) · 14 KB
/
TConstruct.java
File metadata and controls
322 lines (294 loc) · 14 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
package slimeknights.tconstruct;
import net.minecraft.core.HolderLookup.Provider;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.MissingMappingsEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import slimeknights.mantle.registration.RegistrationHelper;
import slimeknights.tconstruct.common.TinkerModule;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.common.data.AdvancementsProvider;
import slimeknights.tconstruct.common.data.ConfigurationDataProvider;
import slimeknights.tconstruct.common.data.DamageTypeProvider;
import slimeknights.tconstruct.common.data.loot.GlobalLootModifiersProvider;
import slimeknights.tconstruct.common.data.loot.LootTableInjectionProvider;
import slimeknights.tconstruct.common.data.loot.TConstructLootTableProvider;
import slimeknights.tconstruct.common.data.tags.BiomeTagProvider;
import slimeknights.tconstruct.common.data.tags.BlockEntityTypeTagProvider;
import slimeknights.tconstruct.common.data.tags.BlockTagProvider;
import slimeknights.tconstruct.common.data.tags.DamageTypeTagProvider;
import slimeknights.tconstruct.common.data.tags.EnchantmentTagProvider;
import slimeknights.tconstruct.common.data.tags.EntityTypeTagProvider;
import slimeknights.tconstruct.common.data.tags.FluidTagProvider;
import slimeknights.tconstruct.common.data.tags.ItemTagProvider;
import slimeknights.tconstruct.common.data.tags.MenuTypeTagProvider;
import slimeknights.tconstruct.common.data.tags.PotionTagProvider;
import slimeknights.tconstruct.common.network.TinkerNetwork;
import slimeknights.tconstruct.fluids.TinkerFluids;
import slimeknights.tconstruct.gadgets.TinkerGadgets;
import slimeknights.tconstruct.library.TinkerItemDisplays;
import slimeknights.tconstruct.library.materials.MaterialRegistry;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.ComputableDataKey;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.TinkerDataKey;
import slimeknights.tconstruct.library.tools.definition.ToolDefinitionLoader;
import slimeknights.tconstruct.library.tools.layout.StationSlotLayoutLoader;
import slimeknights.tconstruct.library.utils.Util;
import slimeknights.tconstruct.plugin.DietPlugin;
import slimeknights.tconstruct.plugin.DummmmmmyPlugin;
import slimeknights.tconstruct.plugin.ImmersiveEngineeringPlugin;
import slimeknights.tconstruct.plugin.craftingtweaks.CraftingTweaksPlugin;
import slimeknights.tconstruct.plugin.jsonthings.JsonThingsPlugin;
import slimeknights.tconstruct.shared.TinkerAttributes;
import slimeknights.tconstruct.shared.TinkerClient;
import slimeknights.tconstruct.shared.TinkerCommons;
import slimeknights.tconstruct.shared.TinkerEffects;
import slimeknights.tconstruct.shared.TinkerMaterials;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;
import slimeknights.tconstruct.tables.TinkerTables;
import slimeknights.tconstruct.tools.TinkerModifiers;
import slimeknights.tconstruct.tools.TinkerToolParts;
import slimeknights.tconstruct.tools.TinkerTools;
import slimeknights.tconstruct.tools.data.material.TrimMaterialProvider;
import slimeknights.tconstruct.world.TinkerStructures;
import slimeknights.tconstruct.world.TinkerWorld;
import slimeknights.tconstruct.world.data.WorldgenProvider;
import java.util.Locale;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
/**
* TConstruct, the tool mod. Craft your tools with style, then modify until the original is gone!
*
* @author mDiyo
*/
@Mod(TConstruct.MOD_ID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class TConstruct {
public static final String MOD_ID = "tconstruct";
public static final Logger LOG = LogManager.getLogger(MOD_ID);
public static final Random RANDOM = new Random();
/* Instance of this mod, used for grabbing prototype fields */
public static TConstruct instance;
public TConstruct() {
instance = this;
Config.init();
TinkerItemDisplays.init();
MaterialRegistry.init();
// initialize modules, done this way rather than with annotations to give us control over the order
MinecraftForge.EVENT_BUS.addListener(TConstruct::missingMappings);
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
// base
bus.register(new TinkerCommons());
bus.register(new TinkerMaterials());
bus.register(new TinkerEffects());
bus.register(new TinkerGadgets());
bus.register(new TinkerAttributes());
// world
bus.register(new TinkerWorld());
bus.register(new TinkerStructures());
// tools
bus.register(new TinkerTables());
bus.register(new TinkerModifiers());
bus.register(new TinkerToolParts());
bus.register(new TinkerTools());
// smeltery
bus.register(new TinkerSmeltery());
bus.register(new TinkerFluids());
// init deferred registers
TinkerModule.initRegisters();
TinkerNetwork.setup();
TinkerTags.init();
// init client logic
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> TinkerClient::onConstruct);
// compat
ModList modList = ModList.get();
if (modList.isLoaded("immersiveengineering")) {
bus.register(new ImmersiveEngineeringPlugin());
}
if (modList.isLoaded("jsonthings")) {
JsonThingsPlugin.onConstruct();
}
if (modList.isLoaded("diet")) {
DietPlugin.onConstruct();
}
if (modList.isLoaded("craftingtweaks")) {
CraftingTweaksPlugin.onConstruct();
}
if (modList.isLoaded("dummmmmmy")) {
bus.register(new DummmmmmyPlugin());
}
}
@SubscribeEvent
static void commonSetup(final FMLCommonSetupEvent event) {
ToolDefinitionLoader.init();
StationSlotLayoutLoader.init();
}
@SubscribeEvent
static void gatherData(final GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
PackOutput packOutput = generator.getPackOutput();
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
CompletableFuture<Provider> lookupProvider = event.getLookupProvider();
boolean server = event.includeServer();
// its sometimes cleaner to splitup different registry sets to their own classes, combine them here into a single provider
RegistrySetBuilder registrySetBuilder = new RegistrySetBuilder();
DamageTypeProvider.register(registrySetBuilder);
WorldgenProvider.register(registrySetBuilder);
TrimMaterialProvider.register(registrySetBuilder);
DatapackBuiltinEntriesProvider datapackRegistryProvider = new DatapackBuiltinEntriesProvider(packOutput, lookupProvider, registrySetBuilder, Set.of(MOD_ID));
generator.addProvider(server, datapackRegistryProvider);
// tags
BlockTagProvider blockTags = new BlockTagProvider(packOutput, lookupProvider, existingFileHelper);
generator.addProvider(server, blockTags);
generator.addProvider(server, new ItemTagProvider(packOutput, lookupProvider, blockTags.contentsGetter(), existingFileHelper));
generator.addProvider(server, new FluidTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new EntityTypeTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new BlockEntityTypeTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new BiomeTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new EnchantmentTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new MenuTypeTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new PotionTagProvider(packOutput, lookupProvider, existingFileHelper));
generator.addProvider(server, new DamageTypeTagProvider(packOutput, datapackRegistryProvider.getRegistryProvider(), existingFileHelper));
// other datagen
generator.addProvider(server, new TConstructLootTableProvider(packOutput));
generator.addProvider(server, new AdvancementsProvider(packOutput));
generator.addProvider(server, new GlobalLootModifiersProvider(packOutput));
generator.addProvider(server, new LootTableInjectionProvider(packOutput));
generator.addProvider(server, new ConfigurationDataProvider(packOutput));
}
/** Handles missing mappings of all types */
private static void missingMappings(MissingMappingsEvent event) {
RegistrationHelper.handleMissingMappings(event, MOD_ID, Registries.BLOCK, name -> switch (name) {
// silky jewel removal
case "silky_jewel_block" -> Blocks.EMERALD_BLOCK;
// piglin heads are vanilla
case "piglin_head" -> Blocks.PIGLIN_HEAD;
case "piglin_wall_head" -> Blocks.PIGLIN_WALL_HEAD;
default -> null;
});
RegistrationHelper.handleMissingMappings(event, MOD_ID, Registries.ITEM, name -> switch (name) {
// silky jewel removal
case "silky_jewel" -> Items.EMERALD;
case "silky_jewel_block" -> Items.EMERALD_BLOCK;
// piglin heads are vanilla
case "piglin_head" -> Items.PIGLIN_HEAD;
// round plate rename
case "round_plate" -> TinkerToolParts.adzeHead.get();
case "round_plate_cast" -> TinkerSmeltery.adzeHeadCast.get();
case "round_plate_sand_cast" -> TinkerSmeltery.adzeHeadCast.getSand();
case "round_plate_red_sand_cast" -> TinkerSmeltery.adzeHeadCast.getRedSand();
default -> null;
});
}
/* Utils */
/**
* Gets a resource location for Tinkers
* @param name Resource path
* @return Location for tinkers
*/
@SuppressWarnings("removal")
public static ResourceLocation getResource(String name) {
return new ResourceLocation(MOD_ID, name);
}
/**
* Gets a data key for the capability, mainly used for modifier markers
* @param name Resource path
* @return Location for tinkers
*/
public static <T> TinkerDataKey<T> createKey(String name) {
return TinkerDataKey.of(getResource(name));
}
/**
* Gets a data key for the capability, mainly used for modifier markers
* @param name Resource path
* @param constructor Constructor for compute if absent
* @return Location for tinkers
*/
public static <T> ComputableDataKey<T> createKey(String name, Supplier<T> constructor) {
return ComputableDataKey.of(getResource(name), constructor);
}
/**
* Returns the given Resource prefixed with tinkers resource location. Use this function instead of hardcoding
* resource locations.
*/
public static String resourceString(String res) {
return String.format("%s:%s", MOD_ID, res);
}
/**
* Prefixes the given unlocalized name with tinkers prefix. Use this when passing unlocalized names for a uniform
* namespace.
*/
public static String prefix(String name) {
return MOD_ID + "." + name.toLowerCase(Locale.US);
}
/** Makes a Tinker's description ID */
public static String makeDescriptionId(String type, String name) {
return type + "." + MOD_ID + "." + name;
}
/**
* Makes a translation key for the given name
* @param base Base name, such as "block" or "gui"
* @param name Object name
* @return Translation key
*/
public static String makeTranslationKey(String base, String name) {
return Util.makeTranslationKey(base, getResource(name));
}
/**
* Makes a translation text component for the given name
* @param base Base name, such as "block" or "gui"
* @param name Object name
* @return Translation key
*/
public static MutableComponent makeTranslation(String base, String name) {
return Component.translatable(makeTranslationKey(base, name));
}
/**
* Makes a translation text component for the given name
* @param base Base name, such as "block" or "gui"
* @param name Object name
* @param arguments Additional arguments to the translation
* @return Translation key
*/
public static MutableComponent makeTranslation(String base, String name, Object... arguments) {
return Component.translatable(makeTranslationKey(base, name), arguments);
}
/**
* This function is called in the constructor in some internal classes that are a common target for addons to wrongly extend.
* These classes will cause issues if blindly used by the addon, and are typically trivial for the addon to implement
* the parts they need if they just put in some effort understanding the code they are copying.
*
* As a reminder for addon devs, anything that is not in the library package can and will change arbitrarily. If you need to use a feature outside library, request it on our github.
* @param self Class to validate
*/
public static void sealTinkersClass(Object self, String base, String solution) {
// note for future maintainers: this does not use Java 9's sealed classes as unless you use modules those are restricted to the same package.
// Dumb restriction but not like we can change it.
String name = self.getClass().getName();
if (!name.startsWith("slimeknights.tconstruct.")) {
throw new IllegalStateException(base + " being extended from invalid package " + name + ". " + solution);
}
}
}