use of net.minecraft.server.v1_16_R3.DamageSource in project MechanicsMain by WeaponMechanics.
the class v1_13_R2 method logDamage.
@Override
public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) {
DamageSource damageSource;
if (isMelee) {
if (source instanceof Player) {
damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) source).getHandle());
} else {
damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle());
}
} else {
damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle());
}
EntityLiving nms = ((CraftLivingEntity) victim).getHandle();
nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health);
}
use of net.minecraft.server.v1_16_R3.DamageSource in project MechanicsMain by WeaponMechanics.
the class v1_14_R1 method logDamage.
@Override
public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) {
DamageSource damageSource;
if (isMelee) {
if (source instanceof Player) {
damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) source).getHandle());
} else {
damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle());
}
} else {
damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle());
}
EntityLiving nms = ((CraftLivingEntity) victim).getHandle();
nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health);
}
use of net.minecraft.server.v1_16_R3.DamageSource in project PaperDev by Kamillaova.
the class CraftLivingEntity method damage.
public void damage(double amount, org.bukkit.entity.Entity source) {
DamageSource reason = DamageSource.GENERIC;
if (source instanceof HumanEntity) {
reason = DamageSource.playerAttack(((CraftHumanEntity) source).getHandle());
} else if (source instanceof LivingEntity) {
reason = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle());
}
entity.damageEntity(reason, (float) amount);
}
use of net.minecraft.server.v1_16_R3.DamageSource in project solinia3-core by mixxit.
the class EntityUtils method PSetHPChange.
public static void PSetHPChange(LivingEntity targetToDamage, Double hpchange, LivingEntity sourceEntityOfChange, boolean playHurtSound) {
if (targetToDamage instanceof ArmorStand || sourceEntityOfChange instanceof ArmorStand)
return;
if (hpchange == 0)
return;
// This will check both their invulnerability from minecraft and godmode from essentials
if (hpchange < 0 && EntityUtils.IsInvulnerable(targetToDamage))
return;
float cur_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth();
float max_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getMaxHealth();
float hp = cur_hp + hpchange.floatValue();
if (hp >= max_hp)
cur_hp = max_hp;
else
cur_hp = hp;
((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).setHealth(cur_hp);
float soundVolume = 1.0F;
if (hpchange < 0) {
DamageSource damagesource = net.minecraft.server.v1_15_R1.DamageSource.mobAttack(((EntityLiving) ((CraftLivingEntity) sourceEntityOfChange).getHandle()));
DamageCause damagecause = DamageCause.ENTITY_ATTACK;
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(sourceEntityOfChange, targetToDamage, damagecause, hpchange);
((CraftLivingEntity) targetToDamage).setLastDamage(hpchange.doubleValue());
((CraftLivingEntity) targetToDamage).setLastDamageCause(event);
((CraftLivingEntity) targetToDamage).setNoDamageTicks(20);
((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration = 10;
((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtTicks = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration;
((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getCombatTracker().trackDamage(damagesource, cur_hp, hpchange.floatValue());
if (((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth() <= 0.0F) {
targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_DEATH, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).die(damagesource);
} else {
if (targetToDamage instanceof Player) {
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(((CraftPlayer) targetToDamage).getHandle(), 1);
((CraftPlayer) targetToDamage).getHandle().playerConnection.sendPacket(packet);
}
if (playHurtSound)
targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_HURT, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
}
}
}
use of net.minecraft.server.v1_16_R3.DamageSource in project Denizen by DenizenScript.
the class EntityHelperImpl method damage.
@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (target == null) {
return;
}
EntityLiving nmsTarget = ((CraftLivingEntity) target).getHandle();
net.minecraft.server.v1_16_R3.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
CraftEventFactory.entityDamage = nmsSource;
try {
DamageSource src = DamageSource.GENERIC;
if (nmsSource != null) {
if (nmsSource instanceof EntityHuman) {
src = DamageSource.playerAttack((EntityHuman) nmsSource);
} else if (nmsSource instanceof EntityLiving) {
src = DamageSource.mobAttack((EntityLiving) nmsSource);
}
}
if (cause != null) {
switch(cause) {
case CONTACT:
src = DamageSource.CACTUS;
break;
case ENTITY_ATTACK:
src = DamageSource.mobAttack(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case ENTITY_SWEEP_ATTACK:
if (src != DamageSource.GENERIC) {
src.sweep();
}
break;
case PROJECTILE:
src = DamageSource.projectile(nmsSource, source instanceof Projectile && ((Projectile) source).getShooter() instanceof Entity ? ((CraftEntity) ((Projectile) source).getShooter()).getHandle() : null);
break;
case SUFFOCATION:
src = DamageSource.STUCK;
break;
case FALL:
src = DamageSource.FALL;
break;
case FIRE:
src = DamageSource.FIRE;
break;
case FIRE_TICK:
src = DamageSource.BURN;
break;
case MELTING:
src = CraftEventFactory.MELTING;
break;
case LAVA:
src = DamageSource.LAVA;
break;
case DROWNING:
src = DamageSource.DROWN;
break;
case BLOCK_EXPLOSION:
src = DamageSource.d(nmsSource instanceof TNTPrimed && ((TNTPrimed) nmsSource).getSource() instanceof EntityLiving ? (EntityLiving) ((TNTPrimed) nmsSource).getSource() : null);
break;
case ENTITY_EXPLOSION:
src = DamageSource.d(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case VOID:
src = DamageSource.OUT_OF_WORLD;
break;
case LIGHTNING:
src = DamageSource.LIGHTNING;
break;
case STARVATION:
src = DamageSource.STARVE;
break;
case POISON:
src = CraftEventFactory.POISON;
break;
case MAGIC:
src = DamageSource.MAGIC;
break;
case WITHER:
src = DamageSource.WITHER;
break;
case FALLING_BLOCK:
src = DamageSource.FALLING_BLOCK;
break;
case THORNS:
src = DamageSource.a(nmsSource);
break;
case DRAGON_BREATH:
src = DamageSource.DRAGON_BREATH;
break;
case CUSTOM:
src = DamageSource.GENERIC;
break;
case FLY_INTO_WALL:
src = DamageSource.FLY_INTO_WALL;
break;
case HOT_FLOOR:
src = DamageSource.HOT_FLOOR;
break;
case CRAMMING:
src = DamageSource.CRAMMING;
break;
case DRYOUT:
src = DamageSource.DRYOUT;
break;
// case SUICIDE:
default:
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (ede.isCancelled()) {
return;
}
break;
}
}
nmsTarget.damageEntity(src, amount);
} finally {
CraftEventFactory.entityDamage = null;
}
}
Aggregations