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:
Nick 2016-02-01 17:05:39 -08:00
parent 6b6c78477c
commit 7e8b469349
7 changed files with 123 additions and 109 deletions

View file

@ -20,7 +20,6 @@ import java.util.*;
public class ConfigHandler
{
@Getter
@Setter
private static Configuration config;
// Teleposer
@ -38,6 +37,32 @@ public class ConfigHandler
public static String[] entitySacrificeValuesList;
public static Map<String, Integer> entitySacrificeValues = new HashMap<String, Integer>();
// Rituals
public static boolean ritualAnimalGrowth;
public static boolean ritualContainment;
public static boolean ritualCrushing;
public static boolean ritualExpulsion;
public static boolean ritualFeatheredKnife;
public static boolean ritualFullStomach;
public static boolean ritualGreenGrove;
public static boolean ritualHarvest;
public static boolean ritualInterdiction;
public static boolean ritualJumping;
public static boolean ritualLava;
public static boolean ritualMagnetic;
public static boolean ritualRegeneration;
public static boolean ritualSpeed;
public static boolean ritualSuppression;
public static boolean ritualWater;
public static boolean ritualWellOfSuffering;
public static boolean ritualZephyr;
// Imperfect Rituals
public static boolean imperfectRitualNight;
public static boolean imperfectRitualRain;
public static boolean imperfectRitualResistance;
public static boolean imperfectRitualZombie;
// Potion ID's
public static int customPotionDrowningID;
public static int customPotionBoostID;
@ -189,6 +214,31 @@ public class ConfigHandler
category = "Rituals";
config.addCustomCategoryComment(category, "Ritual toggling");
config.setCategoryRequiresMcRestart(category, true);
ritualAnimalGrowth = config.get(category, "ritualAnimalGrowth", true).getBoolean();
ritualContainment = config.get(category, "ritualContainment", true).getBoolean();
ritualCrushing = config.get(category, "ritualCrushing", true).getBoolean();
ritualExpulsion = config.get(category, "ritualExpulsion", true).getBoolean();
ritualFeatheredKnife = config.get(category, "ritualFeatheredKnife", true).getBoolean();
ritualFullStomach = config.get(category, "ritualFullStomach", true).getBoolean();
ritualGreenGrove = config.get(category, "ritualGreenGrove", true).getBoolean();
ritualHarvest = config.get(category, "ritualHarvest", true).getBoolean();
ritualInterdiction = config.get(category, "ritualInterdiction", true).getBoolean();
ritualJumping = config.get(category, "ritualJumping", true).getBoolean();
ritualLava = config.get(category, "ritualLava", true).getBoolean();
ritualMagnetic = config.get(category, "ritualMagnetic", true).getBoolean();
ritualRegeneration = config.get(category, "ritualRegeneration", true).getBoolean();
ritualSpeed = config.get(category, "ritualSpeed", true).getBoolean();
ritualSuppression = config.get(category, "ritualSuppression", true).getBoolean();
ritualWater = config.get(category, "ritualWater", true).getBoolean();
ritualWellOfSuffering = config.get(category, "ritualWellOfSuffering", true).getBoolean();
ritualZephyr = config.get(category, "ritualZephyr", true).getBoolean();
category = "Rituals.Imperfect";
imperfectRitualNight = config.get(category, "imperfectRitualNight", true).getBoolean();
imperfectRitualRain = config.get(category, "imperfectRitualRain", true).getBoolean();
imperfectRitualResistance = config.get(category, "imperfectRitualResistance", true).getBoolean();
imperfectRitualZombie = config.get(category, "imperfectRitualZombie", true).getBoolean();
category = "General";
config.addCustomCategoryComment(category, "General settings");
@ -250,11 +300,4 @@ public class ConfigHandler
entitySacrificeValues.put(split[0], amount);
}
}
public static void checkRituals()
{
RitualHelper.checkRituals(config, "WayofTime.bloodmagic.ritual", "Rituals");
RitualHelper.checkImperfectRituals(config, "WayofTime.bloodmagic.ritual.imperfect", "Rituals.imperfect");
config.save();
}
}

View file

@ -23,17 +23,30 @@ public class ImperfectRitualRegistry
* @param id
* - The ID for the imperfect ritual. Cannot be duplicated.
*/
public static void registerRitual(ImperfectRitual imperfectRitual, String id)
public static void registerRitual(ImperfectRitual imperfectRitual, String id, boolean enabled)
{
if (imperfectRitual != null)
{
if (registry.containsKey(id))
BloodMagicAPI.getLogger().error("Duplicate imperfect ritual id: %s", id);
else
{
registry.put(id, imperfectRitual);
enabledRituals.put(imperfectRitual, enabled);
}
}
}
public static void registerRitual(ImperfectRitual imperfectRitual, String id)
{
registerRitual(imperfectRitual, id, true);
}
public static void registerRitual(ImperfectRitual imperfectRitual, boolean enabled)
{
registerRitual(imperfectRitual, imperfectRitual.getName(), enabled);
}
public static void registerRitual(ImperfectRitual imperfectRitual)
{
registerRitual(imperfectRitual, imperfectRitual.getName());
@ -72,7 +85,7 @@ public class ImperfectRitualRegistry
{
try
{
return true;
return enabledRituals.get(imperfectRitual);
} catch (NullPointerException e)
{
BloodMagicAPI.getLogger().error("Invalid Imperfect Ritual was called");
@ -80,6 +93,10 @@ public class ImperfectRitualRegistry
}
}
public static boolean ritualEnabled(String id) {
return ritualEnabled(getRitualForId(id));
}
public static BiMap<String, ImperfectRitual> getRegistry()
{
return HashBiMap.create(registry);

View file

@ -28,7 +28,7 @@ public class RitualRegistry
* @param id
* - The ID for the ritual. Cannot be duplicated.
*/
public static void registerRitual(Ritual ritual, String id)
public static void registerRitual(Ritual ritual, String id, boolean enabled)
{
if (ritual != null)
{
@ -37,11 +37,27 @@ public class RitualRegistry
else
{
registry.put(id, ritual);
enabledRituals.put(ritual, enabled);
orderedIdList.add(id);
}
}
}
public static void registerRitual(Ritual ritual, boolean enabled)
{
registerRitual(ritual, ritual.getName(), enabled);
}
public static void registerRitual(Ritual ritual, String id)
{
registerRitual(ritual, id, true);
}
public static void registerRitual(Ritual ritual)
{
registerRitual(ritual, ritual.getName());
}
public static Ritual getRitualForId(String id)
{
Ritual ritual = registry.get(id);
@ -67,7 +83,7 @@ public class RitualRegistry
{
try
{
return true;
return enabledRituals.get(ritual);
} catch (NullPointerException e)
{
BloodMagicAPI.getLogger().error("Invalid Ritual was called");
@ -75,6 +91,10 @@ public class RitualRegistry
}
}
public static boolean ritualEnabled(String id) {
return ritualEnabled(getRitualForId(id));
}
public static BiMap<String, Ritual> getRegistry()
{
return HashBiMap.create(registry);

View file

@ -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();
}
}
}
}
}
}

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.compat.waila.provider;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
import WayofTime.bloodmagic.api.registry.RitualRegistry;
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import WayofTime.bloodmagic.block.BlockRitualController;
@ -55,6 +56,8 @@ public class DataProviderRitualController implements IWailaDataProvider
{
currenttip.add(TextHelper.localizeEffect(mrs.getCurrentRitual().getUnlocalizedName()));
currenttip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentOwner", PlayerHelper.getUsernameFromUUID(mrs.getOwner())));
if (!RitualRegistry.ritualEnabled(mrs.getCurrentRitual()))
currenttip.add(TextHelper.localizeEffect("tooltip.BloodMagic.config.disabled"));
} else
{
currenttip.add(TextHelper.localizeEffect("tooltip.BloodMagic.deactivated"));
@ -71,7 +74,11 @@ public class DataProviderRitualController implements IWailaDataProvider
ImperfectRitual ritual = ImperfectRitualRegistry.getRitualForBlock(blockStack);
if (ritual != null)
{
currenttip.add(TextHelper.localizeEffect(ritual.getUnlocalizedName()));
if (!ImperfectRitualRegistry.ritualEnabled(ritual))
currenttip.add(TextHelper.localizeEffect("tooltip.BloodMagic.config.disabled"));
}
}
}
}

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
@ -42,54 +43,54 @@ public class ModRituals
public static void initRituals()
{
waterRitual = new RitualWater();
RitualRegistry.registerRitual(waterRitual, waterRitual.getName());
RitualRegistry.registerRitual(waterRitual, ConfigHandler.ritualWater);
lavaRitual = new RitualLava();
RitualRegistry.registerRitual(lavaRitual, lavaRitual.getName());
RitualRegistry.registerRitual(lavaRitual, ConfigHandler.ritualLava);
greenGroveRitual = new RitualGreenGrove();
RitualRegistry.registerRitual(greenGroveRitual, greenGroveRitual.getName());
RitualRegistry.registerRitual(greenGroveRitual, ConfigHandler.ritualGreenGrove);
jumpRitual = new RitualJumping();
RitualRegistry.registerRitual(jumpRitual, jumpRitual.getName());
RitualRegistry.registerRitual(jumpRitual, ConfigHandler.ritualJumping);
sufferingRitual = new RitualWellOfSuffering();
RitualRegistry.registerRitual(sufferingRitual, sufferingRitual.getName());
RitualRegistry.registerRitual(sufferingRitual, ConfigHandler.ritualWellOfSuffering);
featheredKnifeRitual = new RitualFeatheredKnife();
RitualRegistry.registerRitual(featheredKnifeRitual, featheredKnifeRitual.getName());
RitualRegistry.registerRitual(featheredKnifeRitual, ConfigHandler.ritualFeatheredKnife);
regenerationRitual = new RitualRegeneration();
RitualRegistry.registerRitual(regenerationRitual, regenerationRitual.getName());
RitualRegistry.registerRitual(regenerationRitual, ConfigHandler.ritualRegeneration);
animalGrowthRitual = new RitualAnimalGrowth();
RitualRegistry.registerRitual(animalGrowthRitual, animalGrowthRitual.getName());
RitualRegistry.registerRitual(animalGrowthRitual, ConfigHandler.ritualAnimalGrowth);
harvestRitual = new RitualHarvest();
RitualRegistry.registerRitual(harvestRitual, harvestRitual.getName());
RitualRegistry.registerRitual(harvestRitual, ConfigHandler.ritualHarvest);
initHarvestHandlers();
magneticRitual = new RitualMagnetic();
RitualRegistry.registerRitual(magneticRitual, magneticRitual.getName());
RitualRegistry.registerRitual(magneticRitual, ConfigHandler.ritualMagnetic);
crushingRitual = new RitualCrushing();
RitualRegistry.registerRitual(crushingRitual, crushingRitual.getName());
RitualRegistry.registerRitual(crushingRitual, ConfigHandler.ritualCrushing);
stomachRitual = new RitualFullStomach();
RitualRegistry.registerRitual(stomachRitual, stomachRitual.getName());
RitualRegistry.registerRitual(stomachRitual, ConfigHandler.ritualFullStomach);
interdictionRitual = new RitualInterdiction();
RitualRegistry.registerRitual(interdictionRitual, interdictionRitual.getName());
RitualRegistry.registerRitual(interdictionRitual, ConfigHandler.ritualInterdiction);
containmentRitual = new RitualContainment();
RitualRegistry.registerRitual(containmentRitual, containmentRitual.getName());
RitualRegistry.registerRitual(containmentRitual, ConfigHandler.ritualContainment);
speedRitual = new RitualSpeed();
RitualRegistry.registerRitual(speedRitual, speedRitual.getName());
RitualRegistry.registerRitual(speedRitual, ConfigHandler.ritualSpeed);
suppressionRitual = new RitualSuppression();
RitualRegistry.registerRitual(suppressionRitual, suppressionRitual.getName());
RitualRegistry.registerRitual(suppressionRitual, ConfigHandler.ritualSuppression);
zephyrRitual = new RitualZephyr();
RitualRegistry.registerRitual(zephyrRitual, zephyrRitual.getName());
RitualRegistry.registerRitual(zephyrRitual, ConfigHandler.ritualZephyr);
expulsionRitual = new RitualExpulsion();
RitualRegistry.registerRitual(expulsionRitual, expulsionRitual.getName());
RitualRegistry.registerRitual(expulsionRitual, ConfigHandler.ritualExpulsion);
}
public static void initImperfectRituals()
{
imperfectNight = new ImperfectRitualNight();
ImperfectRitualRegistry.registerRitual(imperfectNight);
ImperfectRitualRegistry.registerRitual(imperfectNight, ConfigHandler.imperfectRitualNight);
imperfectRain = new ImperfectRitualRain();
ImperfectRitualRegistry.registerRitual(imperfectRain);
ImperfectRitualRegistry.registerRitual(imperfectRain, ConfigHandler.imperfectRitualRain);
imperfectResistance = new ImperfectRitualResistance();
ImperfectRitualRegistry.registerRitual(imperfectResistance);
ImperfectRitualRegistry.registerRitual(imperfectResistance, ConfigHandler.imperfectRitualResistance);
imperfectZombie = new ImperfectRitualZombie();
ImperfectRitualRegistry.registerRitual(imperfectZombie);
ImperfectRitualRegistry.registerRitual(imperfectZombie, ConfigHandler.imperfectRitualZombie);
}
public static void initHarvestHandlers()

View file

@ -188,6 +188,7 @@ tooltip.BloodMagic.orb.desc=Stores raw Life Essence
tooltip.BloodMagic.orb.owner=Added by: %s
tooltip.BloodMagic.currentOwner=Current owner: %s
tooltip.BloodMagic.currentTier=Current tier: %d
tooltip.BloodMagic.config.disabled=Currently disabled in the Config
tooltip.BloodMagic.activated=Activated
tooltip.BloodMagic.deactivated=Deactivated