diff --git a/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java b/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java index d96e146d..79c0ba83 100644 --- a/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java +++ b/src/main/java/WayofTime/bloodmagic/api/livingArmour/LivingArmourUpgrade.java @@ -3,6 +3,7 @@ package WayofTime.bloodmagic.api.livingArmour; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; import net.minecraft.world.World; import com.google.common.collect.HashMultimap; @@ -32,6 +33,17 @@ public abstract class LivingArmourUpgrade this.level = Math.min(level, getMaxTier() - 1); } + /** + * Percentage of damage blocked. This stacks multiplicatively with other + * upgrades. + * + * @return 0 for no damage blocked, 1 for full damage blocked + */ + public double getArmourProtection(DamageSource source) + { + return 0; + } + public int getUpgradeLevel() { return this.level; diff --git a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java index 7c546354..007d8743 100644 --- a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java @@ -6,12 +6,15 @@ import java.util.Map; import java.util.Map.Entry; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; import net.minecraft.world.World; +import net.minecraftforge.common.ISpecialArmor; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import WayofTime.bloodmagic.BloodMagic; @@ -23,7 +26,7 @@ import WayofTime.bloodmagic.util.helper.TextHelper; import com.google.common.collect.Multimap; -public class ItemLivingArmour extends ItemArmor +public class ItemLivingArmour extends ItemArmor implements ISpecialArmor { public static String[] names = { "helmet", "chest", "legs", "boots" }; @@ -38,6 +41,124 @@ public class ItemLivingArmour extends ItemArmor setCreativeTab(BloodMagic.tabBloodMagic); } + @Override + public ArmorProperties getProperties(EntityLivingBase player, ItemStack stack, DamageSource source, double damage, int slot) + { + double armourReduction = 0.0; + double damageAmount = 0.25; + + if (this == ModItems.livingArmourBoots || this == ModItems.livingArmourHelmet) + { + damageAmount = 3f / 25f; + } else if (this == ModItems.livingArmourLegs) + { + damageAmount = 6f / 25f; + } else if (this == ModItems.livingArmourChest) + { + damageAmount = 0.52; + } + + double armourPenetrationReduction = 0; + + int maxAbsorption = 100000; + + if (source.equals(DamageSource.drown)) + { + return new ArmorProperties(-1, 0, 0); + } + + if (source.equals(DamageSource.outOfWorld)) + { + return new ArmorProperties(-1, 0, 0); + } + + if (this == ModItems.livingArmourChest) + { + armourReduction = 0.32 / 0.52; // This values puts it at about iron level + + ItemStack helmet = player.getEquipmentInSlot(4); + ItemStack leggings = player.getEquipmentInSlot(2); + ItemStack boots = player.getEquipmentInSlot(1); + + if (helmet == null || leggings == null || boots == null) + { + damageAmount *= (armourReduction); + + return new ArmorProperties(-1, damageAmount, maxAbsorption); + } + + if (helmet.getItem() instanceof ItemLivingArmour && leggings.getItem() instanceof ItemLivingArmour && boots.getItem() instanceof ItemLivingArmour) + { + double remainder = 1; // Multiply this number by the armour upgrades for protection + + if (armourMap.containsKey(stack)) + { + LivingArmour armour = armourMap.get(stack); + if (armour != null) + { + for (Entry entry : armour.upgradeMap.entrySet()) + { + LivingArmourUpgrade upgrade = entry.getValue(); + remainder *= (1 - upgrade.getArmourProtection(source)); + } + } + } + + armourReduction = armourReduction + (1 - remainder) * (1 - armourReduction); + damageAmount *= (armourReduction); + + if (source.isUnblockable()) + { + return new ArmorProperties(-1, damageAmount * armourPenetrationReduction, maxAbsorption); + } + + return new ArmorProperties(-1, damageAmount, maxAbsorption); + } + } else + { + if (source.isUnblockable()) + { + return new ArmorProperties(-1, damageAmount * armourPenetrationReduction, maxAbsorption); + } + + return new ArmorProperties(-1, damageAmount, maxAbsorption); + } + + return new ArmorProperties(-1, 0, 0); + } + + @Override + public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) + { + if (armor.getItem() == ModItems.livingArmourHelmet) + { + return 3; + } + + if (armor.getItem() == ModItems.livingArmourChest) + { + return 8; + } + + if (armor.getItem() == ModItems.livingArmourLegs) + { + return 6; + } + + if (armor.getItem() == ModItems.livingArmourBoots) + { + return 3; + } + + return 5; + } + + @Override + public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) + { + return; // Armour shouldn't get damaged... for now + } + @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) diff --git a/src/main/java/WayofTime/bloodmagic/util/Utils.java b/src/main/java/WayofTime/bloodmagic/util/Utils.java index 3515542c..f2f28c55 100644 --- a/src/main/java/WayofTime/bloodmagic/util/Utils.java +++ b/src/main/java/WayofTime/bloodmagic/util/Utils.java @@ -1,10 +1,14 @@ package WayofTime.bloodmagic.util; import net.minecraft.block.Block; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.util.DamageSource; import WayofTime.bloodmagic.api.altar.EnumAltarComponent; import WayofTime.bloodmagic.registry.ModBlocks; import WayofTime.bloodmagic.tile.TileInventory; @@ -110,4 +114,61 @@ public class Utils return Blocks.air; } } + + public static float getModifiedDamage(EntityLivingBase attackedEntity, DamageSource source, float amount) + { + if (!attackedEntity.isEntityInvulnerable(source)) + { + if (amount <= 0) + return 0; + + amount = net.minecraftforge.common.ISpecialArmor.ArmorProperties.applyArmor(attackedEntity, attackedEntity.getInventory(), source, amount); + if (amount <= 0) + return 0; + amount = applyPotionDamageCalculations(attackedEntity, source, amount); + + return amount; + } + + return 0; + } + + public static float applyPotionDamageCalculations(EntityLivingBase attackedEntity, DamageSource source, float damage) + { + if (source.isDamageAbsolute()) + { + return damage; + } else + { + if (attackedEntity.isPotionActive(Potion.resistance) && source != DamageSource.outOfWorld) + { + int i = (attackedEntity.getActivePotionEffect(Potion.resistance).getAmplifier() + 1) * 5; + int j = 25 - i; + float f = damage * (float) j; + damage = f / 25.0F; + } + + if (damage <= 0.0F) + { + return 0.0F; + } else + { + int k = EnchantmentHelper.getEnchantmentModifierDamage(attackedEntity.getInventory(), source); + + if (k > 20) + { + k = 20; + } + + if (k > 0 && k <= 20) + { + int l = 25 - k; + float f1 = damage * (float) l; + damage = f1 / 25.0F; + } + + return damage; + } + } + } } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java index 68647409..b87c4526 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java @@ -16,7 +16,6 @@ import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import WayofTime.bloodmagic.ConfigHandler; -import WayofTime.bloodmagic.api.BlockStack; import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.event.SacrificeKnifeUsedEvent; @@ -35,6 +34,7 @@ import WayofTime.bloodmagic.livingArmour.StatTrackerSelfSacrifice; import WayofTime.bloodmagic.registry.ModBlocks; import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.util.ChatUtil; +import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.helper.TextHelper; public class EventHandler @@ -177,6 +177,11 @@ public class EventHandler Entity sourceEntity = event.source.getEntity(); EntityLivingBase attackedEntity = event.entityLiving; + if (attackedEntity.hurtResistantTime > 0) + { + return; + } + if (sourceEntity != null && attackedEntity instanceof EntityPlayer) { EntityPlayer attackedPlayer = (EntityPlayer) attackedEntity; @@ -192,9 +197,12 @@ public class EventHandler } } + float amount = Math.min(Utils.getModifiedDamage(attackedPlayer, event.source, event.ammount), attackedPlayer.getHealth()); + if (hasFullSet) { -// System.out.println(event.ammount); + System.out.println(amount); + } } }