2018-10-19 14:35:25 +02:00
|
|
|
package de.ellpeck.naturesaura.compat;
|
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-11-11 16:50:51 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat;
|
2019-03-01 18:27:24 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
|
2020-01-26 19:26:50 +01:00
|
|
|
import de.ellpeck.naturesaura.misc.ItemTagProvider;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.fml.ModList;
|
2018-10-19 14:35:25 +02:00
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2018-10-19 14:35:25 +02:00
|
|
|
public final class Compat {
|
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
private static final Map<String, Supplier<ICompat>> MODULE_TYPES = ImmutableMap.<String, Supplier<ICompat>>builder()
|
|
|
|
.put("patchouli", PatchouliCompat::new)
|
|
|
|
.put("curios", CuriosCompat::new)
|
|
|
|
.put("crafttweaker", CraftTweakerCompat::new)
|
|
|
|
.build();
|
|
|
|
private static final Map<String, ICompat> MODULES = new HashMap<>();
|
2018-10-19 14:35:25 +02:00
|
|
|
|
2018-11-11 16:50:51 +01:00
|
|
|
public static void preInit() {
|
2020-01-26 19:26:50 +01:00
|
|
|
populateModules(ModList.get()::isLoaded);
|
|
|
|
MODULES.values().forEach(ICompat::preInit);
|
2019-03-01 18:27:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:33:38 +01:00
|
|
|
public static void preInitClient() {
|
2020-01-26 19:26:50 +01:00
|
|
|
MODULES.values().forEach(ICompat::preInitClient);
|
2019-03-03 23:33:38 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 16:50:51 +01:00
|
|
|
public static void postInit() {
|
2020-01-26 19:26:50 +01:00
|
|
|
MODULES.values().forEach(ICompat::postInit);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasCompat(String mod) {
|
|
|
|
return MODULES.containsKey(mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addItemTags(ItemTagProvider provider) {
|
|
|
|
// since other mods don't get loaded in runData, just populate all modules
|
|
|
|
populateModules(s -> true);
|
|
|
|
MODULES.values().forEach(m -> m.addItemTags(provider));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void populateModules(Predicate<String> isLoaded) {
|
|
|
|
for (Map.Entry<String, Supplier<ICompat>> entry : MODULE_TYPES.entrySet()) {
|
|
|
|
String id = entry.getKey();
|
|
|
|
if (isLoaded.test(id)) {
|
|
|
|
MODULES.put(id, entry.getValue().get());
|
|
|
|
NaturesAura.LOGGER.info("Loading compat module for mod " + id);
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 12:03:42 +02:00
|
|
|
}
|
2018-10-19 14:35:25 +02:00
|
|
|
}
|