Added necessary framework for damage reduction upgrades.

This commit is contained in:
WayofTime 2016-01-06 07:13:56 -05:00
parent b736fd3eaa
commit 72ac385861
4 changed files with 205 additions and 3 deletions

View file

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

View file

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