Fix crash with vanilla arrows hitting mobs

Fix crash with vanilla arrows hitting mobs
This commit is contained in:
JAWolfe04 2016-03-22 08:42:19 -05:00
parent 0a00fdaa8f
commit 7962e92298
6 changed files with 60 additions and 52 deletions

View File

@ -1,6 +1,6 @@
minecraft_version=1.7.10
forge_version=10.13.4.1558-1.7.10
tfc_version=0.79.27
mod_version=1.08
mod_version=1.09
mod_id=TerraFirmaPunkTweaks
group_name=com.JAWolfe.TerraFirmaPunkTweaks

View File

@ -1,6 +1,11 @@
Changelog
=================================================
-------------------------------------------------
TFP Tweaks 1.09
-------------------------------------------------
Bug Fix
+Fixed crash from improper casting with mob damage from projectiles
-------------------------------------------------
TFP Tweaks 1.08
-------------------------------------------------
New Features

View File

@ -186,64 +186,67 @@ public class PlayerDamageHandler
!event.source.getEntity().getClass().getName().contains("bioxx.tfc") && (!event.source.getEntity().getEntityData().hasKey("Attacking") ||
(event.source.getEntity().getEntityData().hasKey("Attacking") && !event.source.getEntity().getEntityData().getBoolean("Attacking"))))
{
EntityLivingBase attacker = (EntityLivingBase)event.source.getEntity();
Entity target = event.entity;
//Add damage for general damage
if (ConfigSettings.VanillaMobDamageScaling && !"indirectMagic".contentEquals(event.source.damageType)
&& target.canAttackWithItem())
if(event.source.getEntity() instanceof EntityLivingBase && ConfigSettings.VanillaMobDamageScaling)
{
if (!target.hitByEntity(target))
EntityLivingBase attacker = (EntityLivingBase)event.source.getEntity();
Entity target = event.entity;
//Add damage for general damage
if (ConfigSettings.VanillaMobDamageScaling && !"indirectMagic".contentEquals(event.source.damageType)
&& target.canAttackWithItem())
{
float damageAmount = ConfigSettings.VanillaPvPNonWeaponDamageMultipier;
if(attacker.getHeldItem() != null)
if (!target.hitByEntity(target))
{
damageAmount = (float)attacker.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
if(damageAmount <= 1)
damageAmount *= ConfigSettings.VanillaPvPNonWeaponDamageMultipier;
else
damageAmount *= ConfigSettings.VanillaMobDamageMultipier;
}
if (attacker.isPotionActive(Potion.damageBoost))
damageAmount += 3 << attacker.getActivePotionEffect(Potion.damageBoost).getAmplifier();
float enchantmentDamage = 0;
if (target instanceof EntityLiving)
{
enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(attacker, (EntityLiving) target);
}
if (damageAmount > 0 || enchantmentDamage > 0)
{
boolean criticalHit = attacker.fallDistance > 0.0F && !attacker.onGround &&
!attacker.isOnLadder() && !attacker.isInWater() &&
!attacker.isPotionActive(Potion.blindness) && attacker.ridingEntity == null &&
target instanceof EntityLiving;
if (criticalHit && damageAmount > 0)
damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2));
damageAmount += enchantmentDamage;
//Add "Attacking" tag to attacking entity
event.source.getEntity().getEntityData().setBoolean("Attacking", true);
target.attackEntityFrom(event.source, damageAmount);
float damageAmount = ConfigSettings.VanillaPvPNonWeaponDamageMultipier;
if(attacker.getHeldItem() != null)
{
damageAmount = (float)attacker.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
if(damageAmount <= 1)
damageAmount *= ConfigSettings.VanillaPvPNonWeaponDamageMultipier;
else
damageAmount *= ConfigSettings.VanillaMobDamageMultipier;
}
if (attacker.isPotionActive(Potion.damageBoost))
damageAmount += 3 << attacker.getActivePotionEffect(Potion.damageBoost).getAmplifier();
float enchantmentDamage = 0;
if (target instanceof EntityLiving)
{
enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(attacker, (EntityLiving) target);
}
if (damageAmount > 0 || enchantmentDamage > 0)
{
boolean criticalHit = attacker.fallDistance > 0.0F && !attacker.onGround &&
!attacker.isOnLadder() && !attacker.isInWater() &&
!attacker.isPotionActive(Potion.blindness) && attacker.ridingEntity == null &&
target instanceof EntityLiving;
if (criticalHit && damageAmount > 0)
damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2));
damageAmount += enchantmentDamage;
//Add "Attacking" tag to attacking entity
event.source.getEntity().getEntityData().setBoolean("Attacking", true);
target.attackEntityFrom(event.source, damageAmount);
}
}
}
}
//Add damage for indirect magic damage
if(ConfigSettings.VanillaMagicScaling && "indirectMagic".contentEquals(event.source.damageType))
{
event.entity.attackEntityFrom(event.source, ConfigSettings.VanillaPvPNonWeaponDamageMultipier);
if(event.entity instanceof EntityWitch || event.entity.getClass().toString().contains("EntityWitherWitch"))
//Add damage for indirect magic damage
if(ConfigSettings.VanillaMagicScaling && "indirectMagic".contentEquals(event.source.damageType))
{
//Direct hit of a magic bottle kills a witch
event.entity.attackEntityFrom(event.source, 100000);
event.entity.attackEntityFrom(event.source, ConfigSettings.VanillaPvPNonWeaponDamageMultipier);
if(event.entity instanceof EntityWitch || event.entity.getClass().toString().contains("EntityWitherWitch"))
{
//Direct hit of a magic bottle kills a witch
event.entity.attackEntityFrom(event.source, 100000);
}
}
}
}