Allow rituals to be disabled via config (#545)
Not automated like the old method, but works. Requires an MC restart. Might look at making it reload-able while ingame at a later date.
This commit is contained in:
parent
6b6c78477c
commit
7e8b469349
7 changed files with 123 additions and 109 deletions
|
@ -1,23 +1,16 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
||||
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.api.ritual.IRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
|
||||
public class RitualHelper
|
||||
{
|
||||
|
@ -116,72 +109,4 @@ public class RitualHelper
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void checkImperfectRituals(Configuration config, String packageName, String category)
|
||||
{
|
||||
checkRituals(config, packageName, category, ImperfectRitual.class, ImperfectRitualRegistry.enabledRituals);
|
||||
}
|
||||
|
||||
public static void checkRituals(Configuration config, String packageName, String category)
|
||||
{
|
||||
checkRituals(config, packageName, category, Ritual.class, RitualRegistry.enabledRituals);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void checkRituals(Configuration config, String packageName, String category, Class ritualClass, Map enabledMap)
|
||||
{
|
||||
String name = packageName;
|
||||
if (!name.startsWith("/"))
|
||||
name = "/" + name;
|
||||
|
||||
name = name.replace('.', '/');
|
||||
URL url = BloodMagic.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 (ritualClass.isInstance(o))
|
||||
enabledMap.put(ritualClass.cast(o), config.get(category, className, true).getBoolean());
|
||||
|
||||
} catch (ClassNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue