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

53 lines
1.9 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;
2024-02-03 14:56:07 +01:00
import net.neoforged.fml.ModList;
import net.neoforged.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) {
2022-06-27 15:24:04 +02:00
Compat.populateModules(ModList.get()::isLoaded);
Compat.MODULES.values().forEach(c -> c.setup(event));
}
2020-04-26 20:40:28 +02:00
public static void setupClient() {
2022-06-27 15:24:04 +02:00
Compat.MODULES.values().forEach(ICompat::setupClient);
2020-01-26 19:26:50 +01:00
}
public static boolean hasCompat(String mod) {
2022-06-27 15:24:04 +02:00
return Compat.MODULES.containsKey(mod);
2020-01-26 19:26:50 +01:00
}
public static void addItemTags(ItemTagProvider provider) {
// since other mods don't get loaded in runData, just populate all modules
2022-06-27 15:24:04 +02:00
Compat.populateModules(s -> true);
Compat.MODULES.values().forEach(m -> m.addItemTags(provider));
2020-01-26 19:26:50 +01:00
}
private static void populateModules(Predicate<String> isLoaded) {
2022-06-27 15:24:04 +02:00
for (var entry : Compat.MODULE_TYPES.entrySet()) {
2021-12-15 16:30:22 +01:00
var id = entry.getKey();
2020-01-26 19:26:50 +01:00
if (isLoaded.test(id)) {
2022-06-27 15:24:04 +02:00
Compat.MODULES.put(id, entry.getValue().get());
2020-01-26 19:26:50 +01:00
NaturesAura.LOGGER.info("Loading compat module for mod " + id);
}
}
}
2018-10-19 14:35:25 +02:00
}