Search in sources :

Example 16 with AttributeInstance

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

the class EntityAttributeBaseValues method attributeBaseValues.

public MapTag attributeBaseValues() {
    MapTag result = new MapTag();
    Attributable ent = getAttributable();
    for (Attribute attr : Attribute.values()) {
        AttributeInstance instance = ent.getAttribute(attr);
        if (instance != null) {
            result.putObject(attr.name(), new ElementTag(instance.getBaseValue()));
        }
    }
    return result;
}
Also used : Attributable(org.bukkit.attribute.Attributable) Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 17 with AttributeInstance

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

the class EntityAttributeBaseValues method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("attribute_base_values") && mechanism.requireObject(MapTag.class)) {
        MapTag input = mechanism.valueAsType(MapTag.class);
        Attributable ent = getAttributable();
        for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
            Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
            AttributeInstance instance = ent.getAttribute(attr);
            if (instance == null) {
                mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
                continue;
            }
            ElementTag value = subValue.getValue().asElement();
            if (!value.isDouble()) {
                mechanism.echoError("Invalid input '" + value + "': must be a decimal number.");
                continue;
            }
            instance.setBaseValue(value.asDouble());
        }
    }
}
Also used : Attributable(org.bukkit.attribute.Attributable) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Map(java.util.Map) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 18 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.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 19 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project solinia3-core by mixxit.

the class SoliniaLivingEntity method updateMaxHp.

@Override
public void updateMaxHp() {
    double calculatedhp = getMaxHP();
    AttributeInstance healthAttribute = getBukkitLivingEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH);
    healthAttribute.setBaseValue(calculatedhp);
}
Also used : AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 20 with AttributeInstance

use of org.bukkit.attribute.AttributeInstance in project solinia3-core by mixxit.

the class EntityManager method SpawnPet.

@Override
public LivingEntity SpawnPet(Player owner, ISoliniaSpell spell) {
    if (owner.isDead())
        return null;
    try {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner.getUniqueId());
        if (pet != null) {
            // insta kill old pet
            pet.damage(10000000);
        // ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
        // solLivingEntity.get
        // StateManager.getInstance().getEntityManager().removePet(owner.getUniqueId(), !solLivingEntity.isCharmed());
        }
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
        if (npc == null)
            return null;
        if (npc.isCorePet() == false)
            return null;
        // 
        // PET FOCUS ITEM
        // If owner is wearing a focus item at this point, and it is valid then we should record the mob is now
        // part of this focus
        LivingEntity spawnedMob = (LivingEntity) MythicMobs.inst().getAPIHelper().spawnMythicMob("NPCID_" + npc.getId(), owner.getLocation());
        spawnedMob.setCollidable(false);
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
        int petFocus = solplayer.getPetFocus(npc);
        if (petFocus > 0) {
            StateManager.getInstance().getEntityManager().setPetFocus(spawnedMob.getUniqueId(), petFocus);
            solplayer.getBukkitPlayer().sendMessage("Your pet focus shimmers with a bright light");
        }
        ISoliniaLivingEntity solPet = SoliniaLivingEntityAdapter.Adapt((LivingEntity) spawnedMob);
        StateManager.getInstance().getEntityManager().setPet(owner.getUniqueId(), spawnedMob);
        spawnedMob.setCustomName(solplayer.getForename() + "s_Pet");
        spawnedMob.setCustomNameVisible(true);
        spawnedMob.setCanPickupItems(false);
        spawnedMob.setRemoveWhenFarAway(false);
        double maxHp = solPet.getMaxHP();
        if (npc.getForcedMaxHp() > 0) {
            maxHp = (double) npc.getForcedMaxHp();
        }
        AttributeInstance healthAttribute = spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH);
        healthAttribute.setBaseValue(maxHp);
        if (!spawnedMob.isDead())
            spawnedMob.setHealth(maxHp);
        net.minecraft.server.v1_15_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_15_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) spawnedMob).getHandle();
        entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) npc.getBaseDamage());
        entityhandle.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((double) 0.4D);
        owner.sendMessage("New Pet spawned with HP: " + spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() + " and " + npc.getBaseDamage() + " dmg");
        Disguise disg = new MobDisguise(DisguiseType.WOLF);
        if (npc.getDisguiseId() > 0 && npc.getDisguise() != null)
            disg = npc.getDisguise().getLibsDisguise(0);
        if (npc.isRacialPet() && solplayer.getRace() != null && solplayer.getRace().getRacePetDisguiseId() > 0 && solplayer.getRace().getRacePetDisguise() != null)
            disg = solplayer.getRace().getRacePetDisguise().getLibsDisguise(0);
        DisguiseAPI.disguiseEntity(spawnedMob, disg);
        return spawnedMob;
    } catch (CoreStateInitException e) {
        return null;
    } catch (InvalidMobTypeException e) {
        return null;
    }
}
Also used : MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) Disguise(me.libraryaddict.disguise.disguisetypes.Disguise) InvalidMobTypeException(io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException) MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) AttributeInstance(org.bukkit.attribute.AttributeInstance) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

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