From 95354ad5574d0fba204c8f1990382bb8a65423ea Mon Sep 17 00:00:00 2001 From: WayofTime Date: Thu, 11 Feb 2016 17:53:20 -0500 Subject: [PATCH] Added Runic Shielding upgrade to the Living Armour. --- changelog.txt | 1 + .../api/livingArmour/LivingArmourUpgrade.java | 5 + .../compat/jei/CompatibilityThaumcraft.java | 32 +++++++ ...ivingArmourUpgradeThaumRunicShielding.java | 58 ++++++++++++ .../StatTrackerThaumRunicShielding.java | 91 +++++++++++++++++++ .../item/armour/ItemLivingArmour.java | 36 +++++++- .../bloodmagic/registry/ModCompatibility.java | 8 +- .../assets/bloodmagic/lang/en_US.lang | 3 +- 8 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/compat/jei/CompatibilityThaumcraft.java create mode 100644 src/main/java/WayofTime/bloodmagic/compat/thaumcraft/LivingArmourUpgradeThaumRunicShielding.java create mode 100644 src/main/java/WayofTime/bloodmagic/compat/thaumcraft/StatTrackerThaumRunicShielding.java diff --git a/changelog.txt b/changelog.txt index d2b184d1..777857d3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ Version 2.0.0-17 - Added Living Armour Upgrades - Solar Powered - Grim Reaper's Sprint + - [Thaumcraft] Runic Shielding - Fixed Blood Altar's progress resetting when clicking with another item - Fixed Divination and Seer sigils crashing when clicking on an altar while not bound diff --git a/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java b/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java index 587a22d1..28781588 100644 --- a/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java +++ b/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java @@ -73,4 +73,9 @@ public abstract class LivingArmourUpgrade public abstract void writeToNBT(NBTTagCompound tag); public abstract void readFromNBT(NBTTagCompound tag); + + public int getRunicShielding() + { + return 0; + } } diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/CompatibilityThaumcraft.java b/src/main/java/WayofTime/bloodmagic/compat/jei/CompatibilityThaumcraft.java new file mode 100644 index 00000000..1ac41213 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/CompatibilityThaumcraft.java @@ -0,0 +1,32 @@ +package WayofTime.bloodmagic.compat.jei; + +import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler; +import WayofTime.bloodmagic.compat.ICompatibility; +import WayofTime.bloodmagic.compat.thaumcraft.LivingArmourUpgradeThaumRunicShielding; +import WayofTime.bloodmagic.compat.thaumcraft.StatTrackerThaumRunicShielding; + +public class CompatibilityThaumcraft implements ICompatibility +{ + @Override + public void loadCompatibility(InitializationPhase phase) + { + if (phase == InitializationPhase.POST_INIT) + { + LivingArmourHandler.registerStatTracker(StatTrackerThaumRunicShielding.class); + + LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeThaumRunicShielding(0)); + } + } + + @Override + public String getModId() + { + return "Thaumcraft"; + } + + @Override + public boolean enableCompat() + { + return true; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/LivingArmourUpgradeThaumRunicShielding.java b/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/LivingArmourUpgradeThaumRunicShielding.java new file mode 100644 index 00000000..ad34571d --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/LivingArmourUpgradeThaumRunicShielding.java @@ -0,0 +1,58 @@ +package WayofTime.bloodmagic.compat.thaumcraft; + +import net.minecraft.nbt.NBTTagCompound; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; + +public class LivingArmourUpgradeThaumRunicShielding extends LivingArmourUpgrade +{ + public static final int[] costs = new int[] { 5, 12, 20, 35, 49, 78, 110, 160, 215, 320 }; + public static final int[] healthModifier = new int[] { 2, 4, 6, 8, 10, 13, 16, 19, 22, 25 }; + + public LivingArmourUpgradeThaumRunicShielding(int level) + { + super(level); + } + + @Override + public String getUniqueIdentifier() + { + return Constants.Mod.MODID + ".upgrade.thaumRunicShielding"; + } + + @Override + public int getMaxTier() + { + return 10; + } + + @Override + public int getCostOfUpgrade() + { + return costs[this.level]; + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + // EMPTY + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + // EMPTY + } + + @Override + public String getUnlocalizedName() + { + return tooltipBase + "thaumRunicShielding"; + } + + @Override + public int getRunicShielding() + { + return healthModifier[this.level]; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/StatTrackerThaumRunicShielding.java b/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/StatTrackerThaumRunicShielding.java new file mode 100644 index 00000000..f470563f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/thaumcraft/StatTrackerThaumRunicShielding.java @@ -0,0 +1,91 @@ +package WayofTime.bloodmagic.compat.thaumcraft; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.world.World; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; +import WayofTime.bloodmagic.api.livingArmour.StatTracker; +import WayofTime.bloodmagic.livingArmour.LivingArmour; + +public class StatTrackerThaumRunicShielding extends StatTracker +{ + public float totalShieldDamage = 0; + + public static HashMap changeMap = new HashMap(); + public static int[] healthedRequired = new int[] { 80, 200, 340, 540, 800, 1600, 2800, 5000, 7600, 10000 }; + + @Override + public String getUniqueIdentifier() + { + return Constants.Mod.MODID + ".tracker.thaumRunicShielding"; + } + + @Override + public void resetTracker() + { + this.totalShieldDamage = 0; + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + totalShieldDamage = tag.getFloat(Constants.Mod.MODID + ".tracker.thaumRunicShielding"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + tag.setFloat(Constants.Mod.MODID + ".tracker.thaumRunicShielding", totalShieldDamage); + } + + @Override + public boolean onTick(World world, EntityPlayer player, LivingArmour livingArmour) + { + if (changeMap.containsKey(livingArmour)) + { + float lastCharge = Math.abs(changeMap.get(livingArmour)); + float currentCharge = player.getAbsorptionAmount(); + if (currentCharge < lastCharge) + { + totalShieldDamage += lastCharge - currentCharge; + + this.markDirty(); + + changeMap.put(livingArmour, currentCharge); + return true; + } + + if (currentCharge != lastCharge && !player.isPotionActive(Potion.absorption)) //Charge is only updated if the "shielding" isn't caused by Absorption. + { + changeMap.put(livingArmour, currentCharge); + } + } else + { + changeMap.put(livingArmour, 0f); + } + + return false; + } + + @Override + public List getUpgrades() + { + List upgradeList = new ArrayList(); + + for (int i = 0; i < 10; i++) + { + if (totalShieldDamage >= healthedRequired[i]) + { + upgradeList.add(new LivingArmourUpgradeThaumRunicShielding(i)); + } + } + + return upgradeList; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java index 03af02aa..9e40729d 100644 --- a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import WayofTime.bloodmagic.api.util.helper.NBTHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.ai.attributes.AttributeModifier; @@ -19,19 +18,21 @@ import net.minecraftforge.common.ISpecialArmor; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import thaumcraft.api.items.IGoggles; +import thaumcraft.api.items.IRevealer; +import thaumcraft.api.items.IRunicArmor; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; +import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.livingArmour.LivingArmour; import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.util.helper.TextHelper; import com.google.common.collect.Multimap; -import thaumcraft.api.items.IGoggles; -import thaumcraft.api.items.IRevealer; -@Optional.InterfaceList({ @Optional.Interface(iface = "thaumcraft.api.items.IRevealer", modid = "Thaumcraft"), @Optional.Interface(iface = "thaumcraft.api.items.IGoggles", modid = "Thaumcraft") }) -public class ItemLivingArmour extends ItemArmor implements ISpecialArmor, IRevealer, IGoggles +@Optional.InterfaceList({ @Optional.Interface(iface = "thaumcraft.api.items.IRevealer", modid = "Thaumcraft"), @Optional.Interface(iface = "thaumcraft.api.items.IGoggles", modid = "Thaumcraft"), @Optional.Interface(iface = "thaumcraft.api.items.IRunicArmor", modid = "Thaumcraft") }) +public class ItemLivingArmour extends ItemArmor implements ISpecialArmor, IRevealer, IGoggles, IRunicArmor { public static String[] names = { "helmet", "chest", "legs", "boots" }; @@ -336,4 +337,29 @@ public class ItemLivingArmour extends ItemArmor implements ISpecialArmor, IRevea return armor.upgradeMap.containsKey(Constants.Mod.MODID + ".upgrade.revealing") && LivingArmour.hasFullSet((EntityPlayer) entityLivingBase); } + + @Override + public int getRunicCharge(ItemStack stack) + { + if (this == ModItems.livingArmourChest) + { + stack = NBTHelper.checkNBT(stack); + LivingArmour armour = getLivingArmour(stack); + + int shielding = 0; + + if (armour != null) + { + for (Entry entry : armour.upgradeMap.entrySet()) + { + LivingArmourUpgrade upgrade = entry.getValue(); + shielding += upgrade.getRunicShielding(); + } + } + + return shielding; + } + + return 0; + } } diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModCompatibility.java b/src/main/java/WayofTime/bloodmagic/registry/ModCompatibility.java index dd8d5a76..74646507 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModCompatibility.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModCompatibility.java @@ -1,11 +1,12 @@ package WayofTime.bloodmagic.registry; +import java.util.ArrayList; + +import net.minecraftforge.fml.common.Loader; import WayofTime.bloodmagic.compat.ICompatibility; import WayofTime.bloodmagic.compat.jei.CompatibilityJustEnoughItems; +import WayofTime.bloodmagic.compat.jei.CompatibilityThaumcraft; import WayofTime.bloodmagic.compat.waila.CompatibilityWaila; -import net.minecraftforge.fml.common.Loader; - -import java.util.ArrayList; public class ModCompatibility { @@ -15,6 +16,7 @@ public class ModCompatibility { compatibilities.add(new CompatibilityJustEnoughItems()); compatibilities.add(new CompatibilityWaila()); + compatibilities.add(new CompatibilityThaumcraft()); } public static void loadCompat(ICompatibility.InitializationPhase phase) diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index dcdb2d00..52153ccf 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -282,7 +282,8 @@ tooltip.BloodMagic.livingArmour.upgrade.meleeDamage=Fierce Strike tooltip.BloodMagic.livingArmour.upgrade.arrowShot=Trick Shot tooltip.BloodMagic.livingArmour.upgrade.stepAssist=Step Assist tooltip.BloodMagic.livingArmour.upgrade.grimReaper=Grim Reaper's Sprint -tooltip.BloodMagic.livingArmour.upgrade.grimReaper=Solar Powered +tooltip.BloodMagic.livingArmour.upgrade.solarPowered=Solar Powered +tooltip.BloodMagic.livingArmour.upgrade.thaumRunicShielding=Runic Shielding tooltip.BloodMagic.livingArmour.upgrade.revealing=Revealing tooltip.BloodMagic.livingArmour.upgrade.level=%s (Level %d)