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;
}
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;
}
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);
}
}
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;
}
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();
}
Aggregations