Skip to content

Instantly share code, notes, and snippets.

@riking
Created March 7, 2013 04:51
Show Gist options
  • Save riking/5105644 to your computer and use it in GitHub Desktop.
Save riking/5105644 to your computer and use it in GitHub Desktop.
Heroes: Skill.damageEntity(LivingEntity target, LivingEntity attacker, int damage, DamageCause cause, boolean knockback)
int oldHealth = target.getHealth();
int newHealth = oldHealth - edbe.getDamage();
if (newHealth < 0) {
newHealth = 0;
}
EntityLiving el = ((CraftLivingEntity) target).getHandle();
target.setLastDamage(edbe.getDamage());
el.aS = oldHealth;
el.hurtTicks = (el.aW = 10);
el.aX = 0.0F;
if (knockback) {
knockBack(target, attacker, edbe.getDamage());
}
el.world.broadcastEntityEffect(el, (byte) 2);
el.lastDamager = ((CraftLivingEntity) attacker).getHandle();
if ((attacker instanceof Player))
try {
ldbpt.set(el, Integer.valueOf(60));
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
el.setHealth(newHealth);
if (newHealth <= 0) {
if ((attacker instanceof Player)) {
EntityPlayer p = ((CraftPlayer) attacker).getHandle();
el.killer = p;
el.die(DamageSource.playerAttack(p));
} else {
EntityLiving att = ((CraftLivingEntity) attacker).getHandle();
el.die(DamageSource.mobAttack(att));
}
} else {
((CraftLivingEntity) target).setNoDamageTicks(0);
EntityLiving attackEntity = ((CraftLivingEntity) attacker)
.getHandle();
if ((el instanceof EntityMonster)) {
if (((el instanceof EntityBlaze))
|| ((el instanceof EntityEnderman))
|| ((el instanceof EntitySpider))
|| ((el instanceof EntityGiantZombie))
|| ((el instanceof EntitySilverfish))) {
EntityMonster em = (EntityMonster) el;
EntityTargetEvent event = CraftEventFactory
.callEntityTargetEvent(
em,
attackEntity,
EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY);
if (!event.isCancelled())
em.setTarget(attackEntity);
}
} else if ((el instanceof EntityGolem)) {
EntityGolem eg = (EntityGolem) el;
eg.setTarget(((CraftLivingEntity) attacker).getHandle());
} else if (((target instanceof Wolf))
&& (((Wolf) target).getTarget() == null)) {
Wolf wolf = (Wolf) target;
wolf.setAngry(true);
wolf.setTarget(attacker);
}
if ((target instanceof PigZombie)) {
((PigZombie) target).setAngry(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment