NaturesAura/src/main/java/de/ellpeck/naturesaura/compat/Compat.java

53 lines
1.8 KiB
Java
Raw Normal View History

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;
2020-02-01 17:22:34 +01:00
import de.ellpeck.naturesaura.compat.enchantibility.EnchantibilityCompat;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
2020-01-29 00:40:28 +01:00
import de.ellpeck.naturesaura.data.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)
2020-02-01 17:22:34 +01:00
.put("enchantability", EnchantibilityCompat::new)
2020-01-26 19:26:50 +01:00
.build();
private static final Map<String, ICompat> MODULES = new HashMap<>();
2018-10-19 14:35:25 +02:00
2020-04-26 20:40:28 +02:00
public static void setup() {
2020-01-26 19:26:50 +01:00
populateModules(ModList.get()::isLoaded);
2020-04-26 20:40:28 +02:00
MODULES.values().forEach(ICompat::setup);
}
2020-04-26 20:40:28 +02:00
public static void setupClient() {
MODULES.values().forEach(ICompat::setupClient);
2020-01-26 19:26:50 +01:00
}
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-19 14:35:25 +02:00
}