Search in sources :

Example 1 with DamageSource

use of net.minecraft.server.v1_16_R3.DamageSource in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getDamageTo.

@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
    EnumMonsterType monsterType;
    if (target instanceof LivingEntity) {
        monsterType = ((CraftLivingEntity) target).getHandle().getMonsterType();
    } else {
        monsterType = EnumMonsterType.UNDEFINED;
    }
    double damage = 0;
    AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
    if (attrib != null) {
        damage = attrib.getValue();
    }
    if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
        damage += EnchantmentManager.a(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
    }
    if (damage <= 0) {
        return 0;
    }
    if (target != null) {
        DamageSource source;
        if (attacker instanceof Player) {
            source = DamageSource.playerAttack(((CraftPlayer) attacker).getHandle());
        } else {
            source = DamageSource.mobAttack(((CraftLivingEntity) attacker).getHandle());
        }
        net.minecraft.server.v1_16_R3.Entity nmsTarget = ((CraftEntity) target).getHandle();
        if (nmsTarget.isInvulnerable(source)) {
            return 0;
        }
        if (!(nmsTarget instanceof EntityLiving)) {
            return damage;
        }
        EntityLiving livingTarget = (EntityLiving) nmsTarget;
        damage = CombatMath.a((float) damage, (float) livingTarget.getArmorStrength(), (float) livingTarget.getAttributeInstance(GenericAttributes.ARMOR_TOUGHNESS).getValue());
        int enchantDamageModifier = EnchantmentManager.a(livingTarget.getArmorItems(), source);
        if (enchantDamageModifier > 0) {
            damage = CombatMath.a((float) damage, (float) enchantDamageModifier);
        }
    }
    return damage;
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 2 with DamageSource

use of net.minecraft.server.v1_16_R3.DamageSource in project Denizen-For-Bukkit 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;
    }
}
Also used : Entity(org.bukkit.entity.Entity) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 3 with DamageSource

use of net.minecraft.server.v1_16_R3.DamageSource in project MechanicsMain by WeaponMechanics.

the class v1_9_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_9_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);
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) DamageSource(net.minecraft.server.v1_9_R2.DamageSource) EntityLiving(net.minecraft.server.v1_9_R2.EntityLiving) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftLivingEntity)

Example 4 with DamageSource

use of net.minecraft.server.v1_16_R3.DamageSource in project MechanicsMain by WeaponMechanics.

the class v1_11_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_11_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);
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) DamageSource(net.minecraft.server.v1_11_R1.DamageSource) EntityLiving(net.minecraft.server.v1_11_R1.EntityLiving) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity)

Example 5 with DamageSource

use of net.minecraft.server.v1_16_R3.DamageSource in project MechanicsMain by WeaponMechanics.

the class v1_12_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_12_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);
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) DamageSource(net.minecraft.server.v1_12_R1.DamageSource) EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)

Aggregations

Player (org.bukkit.entity.Player)9 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)4 DamageSource (net.minecraft.server.v1_12_R1.DamageSource)2 DamageSource (net.minecraft.server.v1_15_R1.DamageSource)2 EntityLiving (net.minecraft.server.v1_15_R1.EntityLiving)2 AttributeInstance (org.bukkit.attribute.AttributeInstance)2 CraftLivingEntity (org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity)2 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)2 Entity (org.bukkit.entity.Entity)2 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)2 DamageSource (net.minecraft.server.v1_10_R1.DamageSource)1 EntityLiving (net.minecraft.server.v1_10_R1.EntityLiving)1 DamageSource (net.minecraft.server.v1_11_R1.DamageSource)1 EntityLiving (net.minecraft.server.v1_11_R1.EntityLiving)1 EntityLiving (net.minecraft.server.v1_12_R1.EntityLiving)1 DamageSource (net.minecraft.server.v1_13_R2.DamageSource)1 EntityLiving (net.minecraft.server.v1_13_R2.EntityLiving)1 DamageSource (net.minecraft.server.v1_14_R1.DamageSource)1 EntityLiving (net.minecraft.server.v1_14_R1.EntityLiving)1 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)1