Skip to content

Commit

Permalink
increase accuracy of weapon_damage in 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 10, 2019
1 parent 0b7e230 commit 265a3b1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Expand Up @@ -89,6 +89,11 @@ public static Method getMethod(Class<?> clazz, String method, Class<?>... params
catch (Exception ex) {
Debug.echoError(ex);
}
if (f == null) {
String err = "Reflection method missing - Tried to read method '" + method + "' of class '" + clazz.getCanonicalName() + "'.";
DenizenAPI.getCurrentInstance().getLogger().warning(err);
Debug.echoError(err);
}
return f;
}

Expand Down
Expand Up @@ -2559,7 +2559,10 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// @group properties
// @description
// Returns the amount of damage the entity will do based on its held item.
// Optionally, specify a target entity to test how much damage will be done to that specific target (modified based on enchantments).
// Optionally, specify a target entity to test how much damage will be done to that specific target
// (modified based on enchantments and that entity's armor/status/etc).
// Note that the result will not always be completely exact, as it doesn't take into account some specific factors
// (eg sweeping vs single-hit, etc).
// -->
registerSpawnedOnlyTag("weapon_damage", (attribute, object) -> {
Entity target = null;
Expand Down
Expand Up @@ -67,6 +67,36 @@ public double getDamageTo(LivingEntity attacker, Entity target) {
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_14_R1.Entity nmsTarget = ((CraftEntity) target).getHandle();
if (nmsTarget.isInvulnerable(source)) {
return 0;
}
if (!(nmsTarget instanceof EntityLiving)) {
return damage;
}
EntityLiving livingTarget = (EntityLiving) nmsTarget;
try {
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);
}
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
return damage;
}

Expand Down

0 comments on commit 265a3b1

Please sign in to comment.