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;
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;
2021-03-30 16:22:40 +02:00
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
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)
2021-12-19 16:35:03 +01:00
.put("curios", CuriosCompat::new)
//.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
2021-03-30 16:22:40 +02:00
public static void setup(FMLCommonSetupEvent event) {
2020-01-26 19:26:50 +01:00
populateModules(ModList.get()::isLoaded);
2021-03-30 16:22:40 +02:00
MODULES.values().forEach(c -> c.setup(event));
}
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) {
2021-12-15 16:30:22 +01:00
for (var entry : MODULE_TYPES.entrySet()) {
var id = entry.getKey();
2020-01-26 19:26:50 +01:00
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
}