Search in sources :

Example 6 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance 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 7 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getDamageTo.

@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
    MobType monsterType;
    if (target instanceof LivingEntity) {
        monsterType = ((CraftLivingEntity) target).getHandle().getMobType();
    } else {
        monsterType = MobType.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 += EnchantmentHelper.getDamageBonus(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.world.entity.Entity nmsTarget = ((CraftEntity) target).getHandle();
        if (nmsTarget.isInvulnerableTo(source)) {
            return 0;
        }
        if (!(nmsTarget instanceof net.minecraft.world.entity.LivingEntity)) {
            return damage;
        }
        net.minecraft.world.entity.LivingEntity livingTarget = (net.minecraft.world.entity.LivingEntity) nmsTarget;
        damage = CombatRules.getDamageAfterAbsorb((float) damage, (float) livingTarget.getArmorValue(), (float) livingTarget.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
        int enchantDamageModifier = EnchantmentHelper.getDamageProtection(livingTarget.getArmorSlots(), source);
        if (enchantDamageModifier > 0) {
            damage = CombatRules.getDamageAfterMagicAbsorb((float) damage, (float) enchantDamageModifier);
        }
    }
    return damage;
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) DamageSource(net.minecraft.world.damagesource.DamageSource) LivingEntity(org.bukkit.entity.LivingEntity) AttributeInstance(org.bukkit.attribute.AttributeInstance) org.bukkit.entity(org.bukkit.entity) org.bukkit.craftbukkit.v1_18_R1.entity(org.bukkit.craftbukkit.v1_18_R1.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 8 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project Prism-Bukkit by prism.

the class AbstractHorseSerializer method deserializer.

@Override
protected void deserializer(Entity entity) {
    final AbstractHorse h = (AbstractHorse) entity;
    if (entity.getType() == EntityType.HORSE) {
        Horse horse = (Horse) h;
        Horse.Color color = MiscUtils.getEnum(horseColor, Horse.Color.WHITE);
        Horse.Style vstyle = MiscUtils.getEnum(style, Horse.Style.NONE);
        horse.setColor(color);
        horse.setStyle(vstyle);
        horse.getInventory().setSaddle(ItemUtils.itemOf(saddle));
        horse.getInventory().setArmor(ItemUtils.itemOf(armor));
    } else if (entity.getType() == EntityType.LLAMA) {
        Llama llama = (Llama) h;
        Llama.Color color = MiscUtils.getEnum(horseColor, Llama.Color.CREAMY);
        llama.setColor(color);
        llama.getInventory().setDecor(ItemUtils.itemOf(saddle));
    } else if (entity.getType() == EntityType.DONKEY || entity.getType() == EntityType.MULE || entity.getType() == EntityType.ZOMBIE_HORSE || entity.getType() == EntityType.SKELETON_HORSE) {
        h.getInventory().setItem(0, ItemUtils.itemOf(saddle));
    }
    if (entity instanceof ChestedHorse) {
        ((ChestedHorse) h).setCarryingChest(Boolean.TRUE.equals(chest));
    }
    maxDom = Math.max(1, maxDom);
    dom = Math.min(Math.max(0, dom), maxDom);
    jump = Math.min(Math.max(0.0, jump), 2.0);
    h.setDomestication(dom);
    h.setMaxDomestication(maxDom);
    h.setJumpStrength(jump);
    h.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
    AttributeInstance attributeInstance = h.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
    if (attributeInstance != null) {
        attributeInstance.setBaseValue(movementSpeed);
    }
}
Also used : AbstractHorse(org.bukkit.entity.AbstractHorse) Llama(org.bukkit.entity.Llama) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) AbstractHorse(org.bukkit.entity.AbstractHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 9 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project MagicPlugin by elBukkit.

the class BaseMageModifier method deactivateAttributes.

protected void deactivateAttributes() {
    if (attributeModifiers == null)
        return;
    LivingEntity entity = mage.getLivingEntity();
    if (entity == null)
        return;
    // Remove in reverse-order in case a base attribute was changed twice
    ListIterator<EntityAttributeModifier> it = attributeModifiers.listIterator(attributeModifiers.size());
    while (it.hasPrevious()) {
        EntityAttributeModifier modifier = it.previous();
        AttributeInstance attribute = entity.getAttribute(modifier.attribute);
        if (attribute == null)
            continue;
        if (modifier.modifier != null) {
            attribute.removeModifier(modifier.modifier);
        }
        if (modifier.previous != null) {
            attribute.setBaseValue(modifier.previous);
        }
    }
    attributeModifiers = null;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 10 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project MagicPlugin by elBukkit.

the class CastContext method getVanillaAttribute.

@Nullable
private Double getVanillaAttribute(Attribute attribute) {
    LivingEntity living = getTargetLivingEntity();
    if (living == null) {
        return null;
    }
    AttributeInstance instance = living.getAttribute(attribute);
    return instance == null ? null : instance.getValue();
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) AttributeInstance(org.bukkit.attribute.AttributeInstance) Nullable(javax.annotation.Nullable)

Aggregations

AttributeInstance (org.bukkit.attribute.AttributeInstance)23 LivingEntity (org.bukkit.entity.LivingEntity)8 Attribute (org.bukkit.attribute.Attribute)5 AttributeModifier (org.bukkit.attribute.AttributeModifier)5 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)4 MapTag (com.denizenscript.denizencore.objects.core.MapTag)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 Attributable (org.bukkit.attribute.Attributable)3 Horse (org.bukkit.entity.Horse)3 Player (org.bukkit.entity.Player)3 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2 net.minecraft.world.entity (net.minecraft.world.entity)2