2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.api.util.helper;
|
2015-11-01 00:58:47 +00:00
|
|
|
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
2015-11-01 00:58:47 +00:00
|
|
|
import net.minecraftforge.common.config.Configuration;
|
|
|
|
import sun.misc.Launcher;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
public class RitualHelper {
|
|
|
|
|
|
|
|
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel) {
|
|
|
|
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getNextRitualKey(String currentKey) {
|
|
|
|
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
|
|
|
int nextIndex = RitualRegistry.getRituals().listIterator(currentIndex).nextIndex();
|
|
|
|
|
|
|
|
return RitualRegistry.getIds().get(nextIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPrevRitualKey(String currentKey) {
|
|
|
|
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
|
|
|
int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex();
|
|
|
|
|
|
|
|
return RitualRegistry.getIds().get(previousIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
|
|
|
* This is used to determine whether your effect is enabled or not.
|
|
|
|
*
|
|
|
|
* The config option will be created as {@code B:ClassName=true} with a comment of
|
|
|
|
* {@code Enables the ClassName ritual}.
|
|
|
|
*
|
|
|
|
* Should be safe to modify at any point.
|
|
|
|
*
|
|
|
|
* @param config - Your mod's Forge {@link Configuration} object.
|
|
|
|
* @param packageName - The package your Rituals are located in.
|
|
|
|
* @param category - The config category to write to.
|
|
|
|
*/
|
|
|
|
public static void checkRituals(Configuration config, String packageName, String category) {
|
|
|
|
String name = packageName;
|
|
|
|
if (!name.startsWith("/"))
|
|
|
|
name = "/" + name;
|
|
|
|
|
|
|
|
name = name.replace('.', '/');
|
|
|
|
URL url = Launcher.class.getResource(name);
|
|
|
|
File directory = new File(url.getFile());
|
|
|
|
|
|
|
|
if (directory.exists()) {
|
|
|
|
String[] files = directory.list();
|
|
|
|
|
|
|
|
for (String file : files) {
|
|
|
|
if (file.endsWith(".class")) {
|
|
|
|
String className = file.substring(0, file.length() - 6);
|
|
|
|
|
|
|
|
try {
|
|
|
|
Object o = Class.forName(packageName + "." + className).newInstance();
|
|
|
|
|
|
|
|
if (o instanceof Ritual)
|
|
|
|
RitualRegistry.enabledRituals.put((Ritual) o, config.get(category, className, true).getBoolean());
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|