Java Code Examples for net.minecraft.util.DamageSource#causePlayerDamage()

The following examples show how to use net.minecraft.util.DamageSource#causePlayerDamage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoArmorHack.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
private int getArmorValue(ItemArmor item, ItemStack stack)
{
	int armorPoints = item.damageReduceAmount;
	int prtPoints = 0;
	int armorToughness = (int)item.toughness;
	int armorType = item.getArmorMaterial()
		.getDamageReductionAmount(EntityEquipmentSlot.LEGS);
	
	if(useEnchantments.isChecked())
	{
		Enchantment protection = Enchantments.PROTECTION;
		int prtLvl =
			EnchantmentHelper.getEnchantmentLevel(protection, stack);
		
		EntityPlayerSP player = WMinecraft.getPlayer();
		DamageSource dmgSource = DamageSource.causePlayerDamage(player);
		prtPoints = protection.calcModifierDamage(prtLvl, dmgSource);
	}
	
	return armorPoints * 5 + prtPoints * 3 + armorToughness + armorType;
}
 
Example 2
Source File: CraftLivingEntity.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void damage(double amount, Entity source) {
    DamageSource reason = DamageSource.GENERIC;

    if (source instanceof HumanEntity) {
        reason = DamageSource.causePlayerDamage(((CraftHumanEntity) source).getHandle());
    } else if (source instanceof LivingEntity) {
        reason = DamageSource.causeMobDamage(((CraftLivingEntity) source).getHandle());
    }

    entity.attackEntityFrom(reason, (float) amount);
}