From 073873960c9e0ec5eb9e99cd5c085f15c8ef921e Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 Jan 2016 19:46:49 -0800 Subject: [PATCH] Allow modifying of entity sacrificial values Done via API or Config. API values take precedence over Config values. --- changelog.txt | 4 +- .../WayofTime/bloodmagic/ConfigHandler.java | 30 ++++++++++++-- .../bloodmagic/api/BloodMagicAPI.java | 40 +++++++++++++++++++ .../item/ItemDaggerOfSacrifice.java | 18 ++++----- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/changelog.txt b/changelog.txt index 9f143d03..6258e55d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,9 +1,11 @@ ------------------------------------------------------ Version 2.0.0-7 ------------------------------------------------------ -- [API] Method to easily get instances of Items and Blocks - JEI now displays more information for Altar recipes. Hover over the Altar image to view it. - Added particles to the Blood Altar on the server-side. +- Allow configuration of entity sacrificial values +- [API] Allow setting of entity sacrificial values via API. Takes precedence over config values. +- [API] Method to easily get instances of Items and Blocks ------------------------------------------------------ Version 2.0.0-6 diff --git a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java index 367cbe73..b3d21531 100644 --- a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java +++ b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java @@ -15,9 +15,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.io.File; import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; public class ConfigHandler { @@ -36,6 +34,10 @@ public class ConfigHandler // Well of Suffering Blacklist public static List wellOfSufferingBlacklist; + // Blood Altar Sacrificial Values + public static String[] entitySacrificeValuesList; + public static Map entitySacrificeValues = new HashMap(); + // Potion ID's public static int customPotionDrowningID; public static int customPotionBoostID; @@ -120,6 +122,11 @@ public class ConfigHandler config.addCustomCategoryComment(category, "Entity blacklisting from WoS"); wellOfSufferingBlacklist = Arrays.asList(config.getStringList("wellOfSufferingBlacklist", category, new String[] {}, "Use the class name of the Entity to blacklist it from usage.\nIE: EntityWolf, EntityWitch, etc")); + category = "Blood Altar Sacrificial Values"; + config.addCustomCategoryComment(category, "Entity Sacrificial Value Settings"); + entitySacrificeValuesList = config.getStringList("entitySacrificeValues", category, new String[] {"EntityVillager;2000", "EntitySlime;150", "EntityEnderman;200", "EntityCow;250", "EntityChicken;250", "EntityHorse;250", "EntitySheep;250", "EntityWolf;250", "EntityOcelot;250", "EntityPig;250", "EntityRabbit;250"}, "Used to edit the amount of LP gained per sacrifice of the given entity.\nSetting an entity to 0 effectively blacklists it.\nIf a mod modifies an entity via the API, it will take precedence over this config.\nSyntax: EntityClassName;LPPerSacrifice"); + buildEntitySacrificeValues(); + category = "Potions"; config.addCustomCategoryComment(category, "Potion settings"); config.addCustomCategoryComment(category + ".id", "Potion ID settings"); @@ -224,6 +231,23 @@ public class ConfigHandler } } + private static void buildEntitySacrificeValues() + { + entitySacrificeValues.clear(); + + for (String entityData : entitySacrificeValuesList) + { + String[] split = entityData.split(";"); + + int amount = 500; + if (Utils.isInteger(split[1])) + amount = Integer.parseInt(split[1]); + + if (!entitySacrificeValues.containsKey(split[0])) + entitySacrificeValues.put(split[0], amount); + } + } + public static void checkRituals() { RitualHelper.checkRituals(config, "WayofTime.bloodmagic.ritual", "Rituals"); diff --git a/src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java b/src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java index d13a3291..6e086d09 100644 --- a/src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java +++ b/src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java @@ -4,19 +4,26 @@ import WayofTime.bloodmagic.api.util.helper.LogHelper; import lombok.Getter; import lombok.Setter; import net.minecraft.block.Block; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.util.DamageSource; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fml.common.registry.GameRegistry; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class BloodMagicAPI { @Getter private static final List teleposerBlacklist = new ArrayList(); + @Getter + private static final Map entitySacrificeValues = new HashMap(); + @Getter @Setter private static boolean loggingEnabled; @@ -119,4 +126,37 @@ public class BloodMagicAPI { addToTeleposerBlacklist(block, 0); } + + /** + * Used to set the sacrifice value of an Entity. The value provided is how much + * LP will be gained when the entity is sacrificed at a Blood Altar. + * + * Setting a sacrificeValue of 0 will effectively blacklist the entity. + * + * The default value for any unset Entity is 500 LP per sacrifice. + * + * @param entityClass + * - The class of the entity to blacklist. + * @param sacrificeValue + * - The Amount of LP to provide per each entity sacrificed. + */ + public static void setEntitySacrificeValue(Class entityClass, int sacrificeValue) + { + if (!entitySacrificeValues.containsKey(entityClass.getSimpleName())) + entitySacrificeValues.put(entityClass.getSimpleName(), sacrificeValue); + } + + /** + * @see #setEntitySacrificeValue(Class, int) + * + * @param entityClassName + * - The name of the class of the entity to blacklist. + * @param sacrificeValue + * - The Amount of LP to provide per each entity sacrificed. + */ + public static void setEntitySacrificeValue(String entityClassName, int sacrificeValue) + { + if (!entitySacrificeValues.containsKey(entityClassName)) + entitySacrificeValues.put(entityClassName, sacrificeValue); + } } diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java b/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java index 30ccd141..18a63a45 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemDaggerOfSacrifice.java @@ -1,6 +1,8 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ConfigHandler; +import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.DamageSourceBloodMagic; import WayofTime.bloodmagic.api.altar.IBloodAltar; @@ -42,16 +44,14 @@ public class ItemDaggerOfSacrifice extends Item if (target.isDead || target.getHealth() < 0.5F) return false; - // TODO Make these configurable + String entityName = target.getClass().getSimpleName(); int lifeEssence = 500; - if (target instanceof EntityVillager) - lifeEssence = 2000; - else if (target instanceof EntitySlime) - lifeEssence = 150; - else if (target instanceof EntityEnderman) - lifeEssence = 200; - else if (target instanceof EntityAnimal) - lifeEssence = 250; + + if (ConfigHandler.entitySacrificeValues.containsKey(entityName)) + lifeEssence = ConfigHandler.entitySacrificeValues.get(entityName); + + if (BloodMagicAPI.getEntitySacrificeValues().containsKey(entityName)) + lifeEssence = BloodMagicAPI.getEntitySacrificeValues().get(entityName); if (findAndFillAltar(attacker.worldObj, target, lifeEssence)) {