mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-16 07:35:35 +01:00
112 lines
8.4 KiB
Diff
112 lines
8.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: dodison <kacpik@mapik.eu>
|
|
Date: Mon, 26 Jul 2021 17:32:36 +0200
|
|
Subject: [PATCH] Add critical damage API
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
index 435490f2931dae9d4fc5adb713c47a962684eeb5..ec52c7a75d9988475fbb4fe12ef7f4489ef3d894 100644
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
@@ -238,4 +238,18 @@ public class DamageSource {
|
|
public Holder<DamageType> typeHolder() {
|
|
return this.type;
|
|
}
|
|
+
|
|
+ // Paper start - add critical damage API
|
|
+ private boolean critical;
|
|
+ public boolean isCritical() {
|
|
+ return this.critical;
|
|
+ }
|
|
+ public DamageSource critical() {
|
|
+ return this.critical(true);
|
|
+ }
|
|
+ public DamageSource critical(boolean critical) {
|
|
+ this.critical = critical;
|
|
+ return this;
|
|
+ }
|
|
+ // Paper end - add critical damage API
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 44e2a0f36359ab914c9328b633dd8a360591751d..c3fc0adeafbebaaaab8c155df9829f488e41d8ab 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1274,7 +1274,7 @@ public abstract class Player extends LivingEntity {
|
|
}
|
|
|
|
f += this.getItemInHand(InteractionHand.MAIN_HAND).getItem().getAttackDamageBonus(this, f);
|
|
- boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting();
|
|
+ boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting(); // Paper - Add critical damage API; diff on change
|
|
|
|
flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper - Toggleable player crits
|
|
if (flag2) {
|
|
@@ -1313,7 +1313,7 @@ public abstract class Player extends LivingEntity {
|
|
}
|
|
|
|
Vec3 vec3d = target.getDeltaMovement();
|
|
- boolean flag5 = target.hurt(this.damageSources().playerAttack(this), f);
|
|
+ boolean flag5 = target.hurt(this.damageSources().playerAttack(this).critical(flag2), f); // Paper - add critical damage API
|
|
|
|
if (flag5) {
|
|
if (i > 0) {
|
|
@@ -1341,7 +1341,7 @@ public abstract class Player extends LivingEntity {
|
|
|
|
if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) {
|
|
// CraftBukkit start - Only apply knockback if the damage hits
|
|
- if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) {
|
|
+ if (entityliving.hurt(this.damageSources().playerAttack(this).sweep().critical(flag2), f4)) { // Paper - add critical damage API
|
|
entityliving.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit
|
|
}
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
index 047629405dc67e3bcb5e4b3d5afa0e821f8fde44..8e8258333e181491b2d5b61ebdb80de36e8179a9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
@@ -392,6 +392,7 @@ public abstract class AbstractArrow extends Projectile {
|
|
}
|
|
}
|
|
|
|
+ if (this.isCritArrow()) damagesource = damagesource.critical(); // Paper - add critical damage API
|
|
boolean flag = entity.getType() == EntityType.ENDERMAN;
|
|
int k = entity.getRemainingFireTicks();
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 11f9220c4a5d2481f3a52238b4d845bad1fd0867..28d371e59d8780bf6e154bac56ee189b3b43b201 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1062,7 +1062,7 @@ public class CraftEventFactory {
|
|
return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), entity, DamageCause.BLOCK_EXPLOSION, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
|
|
}
|
|
DamageCause damageCause = (damager.getBukkitEntity() instanceof org.bukkit.entity.TNTPrimed) ? DamageCause.BLOCK_EXPLOSION : DamageCause.ENTITY_EXPLOSION;
|
|
- return CraftEventFactory.callEntityDamageEvent(damager, entity, damageCause, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
|
|
+ return CraftEventFactory.callEntityDamageEvent(damager, entity, damageCause, bukkitDamageSource, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
|
|
} else if (damager != null || source.getDirectEntity() != null) {
|
|
DamageCause cause = (source.isSweep()) ? DamageCause.ENTITY_SWEEP_ATTACK : DamageCause.ENTITY_ATTACK;
|
|
|
|
@@ -1088,7 +1088,7 @@ public class CraftEventFactory {
|
|
cause = DamageCause.MAGIC;
|
|
}
|
|
|
|
- return CraftEventFactory.callEntityDamageEvent(damager, entity, cause, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
|
|
+ return CraftEventFactory.callEntityDamageEvent(damager, entity, cause, bukkitDamageSource, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
|
|
} else if (source.is(DamageTypes.FELL_OUT_OF_WORLD)) {
|
|
return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), entity, DamageCause.VOID, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
|
|
} else if (source.is(DamageTypes.LAVA)) {
|
|
@@ -1146,13 +1146,13 @@ public class CraftEventFactory {
|
|
cause = DamageCause.CUSTOM;
|
|
}
|
|
|
|
- return CraftEventFactory.callEntityDamageEvent((Entity) null, entity, cause, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
|
|
+ return CraftEventFactory.callEntityDamageEvent((Entity) null, entity, cause, bukkitDamageSource, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
|
|
}
|
|
|
|
- private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, org.bukkit.damage.DamageSource bukkitDamageSource, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
|
|
+ private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, org.bukkit.damage.DamageSource bukkitDamageSource, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled, boolean critical) { // Paper - add critical damage API
|
|
EntityDamageEvent event;
|
|
if (damager != null) {
|
|
- event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, bukkitDamageSource, modifiers, modifierFunctions);
|
|
+ event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, bukkitDamageSource, modifiers, modifierFunctions, critical);
|
|
} else {
|
|
event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, bukkitDamageSource, modifiers, modifierFunctions);
|
|
}
|