Java Code Examples for net.minecraft.entity.EntityLivingBase#hasCapability()

The following examples show how to use net.minecraft.entity.EntityLivingBase#hasCapability() . 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: ModToolLeveling.java    From TinkersToolLeveling with MIT License 5 votes vote down vote up
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damageDealt, boolean wasCritical, boolean wasHit) {
  if(!target.getEntityWorld().isRemote && wasHit && player instanceof EntityPlayer) {
    // if we killed it the event for distributing xp was already fired and we just do it manually here
    EntityPlayer entityPlayer = (EntityPlayer) player;
    if(!target.isEntityAlive()) {
      addXp(tool, Math.round(damageDealt), entityPlayer);
    }
    else if(target.hasCapability(CapabilityDamageXp.CAPABILITY, null)) {
      target.getCapability(CapabilityDamageXp.CAPABILITY, null).addDamageFromTool(damageDealt, tool, entityPlayer);
    }
  }
}