2021-10-21 00:15:28 +02:00
|
|
|
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
|
2022-12-07 21:16:54 +01:00
|
|
|
index ed8bad446a1845befa6d5d75c40cf281fa47a9d9..8795c94e6b6474addddbb0b337a962e8fac46b2b 100644
|
2021-10-21 00:15:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -61,6 +61,19 @@ public class DamageSource {
|
2021-10-21 00:15:28 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - add critical damage API
|
|
|
|
+ private boolean critical;
|
2021-10-21 16:11:19 +02:00
|
|
|
+ public boolean isCritical() {
|
2021-10-21 00:15:28 +02:00
|
|
|
+ return this.critical;
|
|
|
|
+ }
|
|
|
|
+ public DamageSource critical() {
|
|
|
|
+ return this.critical(true);
|
|
|
|
+ }
|
|
|
|
+ public DamageSource critical(boolean critical) {
|
|
|
|
+ this.critical = critical;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2022-12-07 21:16:54 +01:00
|
|
|
public static DamageSource fallingBlock(Entity attacker) {
|
|
|
|
return (new EntityDamageSource("fallingBlock", attacker)).damageHelmet();
|
2021-10-21 00:15:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2023-02-13 18:52:27 +01:00
|
|
|
index 9c9c7dd62a747f6d6597b01839b63840080eac82..59cead9833b7d0266a0c19fdbebd42256e4f54c4 100644
|
2021-10-21 00:15:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -1256,7 +1256,7 @@ public abstract class Player extends LivingEntity {
|
2021-10-21 00:15:28 +02:00
|
|
|
flag1 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
- boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity;
|
|
|
|
+ boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity; // Paper - Add critical damage API - conflict on change
|
|
|
|
|
2022-06-09 10:51:45 +02:00
|
|
|
flag2 = flag2 && !level.paperConfig().entities.behavior.disablePlayerCrits; // Paper
|
2021-10-21 00:15:28 +02:00
|
|
|
flag2 = flag2 && !this.isSprinting();
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -1296,7 +1296,7 @@ public abstract class Player extends LivingEntity {
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vec3 vec3d = target.getDeltaMovement();
|
|
|
|
- boolean flag5 = target.hurt(DamageSource.playerAttack(this), f);
|
|
|
|
+ boolean flag5 = target.hurt(DamageSource.playerAttack(this).critical(flag2), f); // Paper - add critical damage API
|
|
|
|
|
|
|
|
if (flag5) {
|
|
|
|
if (i > 0) {
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -1324,7 +1324,7 @@ public abstract class Player extends LivingEntity {
|
2021-10-21 00:15:28 +02:00
|
|
|
|
2021-11-25 02:24:51 +01:00
|
|
|
if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) {
|
2021-10-21 00:15:28 +02:00
|
|
|
// CraftBukkit start - Only apply knockback if the damage hits
|
|
|
|
- if (entityliving.hurt(DamageSource.playerAttack(this).sweep(), f4)) {
|
|
|
|
+ if (entityliving.hurt(DamageSource.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); // Paper
|
|
|
|
}
|
|
|
|
// 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
|
2023-02-13 18:52:27 +01:00
|
|
|
index f427ad266a1e00adb661b9e4bc7cfe2a7ec52caa..11e0601c08e66ff7fe4febc2c38b38fec8d48c91 100644
|
2021-10-21 00:15:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
2022-12-23 06:20:44 +01:00
|
|
|
@@ -372,6 +372,7 @@ public abstract class AbstractArrow extends Projectile {
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ 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
|
2023-01-27 21:52:04 +01:00
|
|
|
index 49693aa4d136701c822ab4b386ab7ed8b061a156..4143f72b8df92bee25399f90a759c8a8fb567cba 100644
|
2021-10-21 00:15:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-12-14 06:03:57 +01:00
|
|
|
@@ -970,7 +970,7 @@ public class CraftEventFactory {
|
2021-10-21 00:15:28 +02:00
|
|
|
} else {
|
|
|
|
damageCause = DamageCause.ENTITY_EXPLOSION;
|
|
|
|
}
|
|
|
|
- event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions);
|
2021-10-21 16:11:19 +02:00
|
|
|
+ event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions, source.isCritical()); // Paper - add critical damage API
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
event.setCancelled(cancelled);
|
|
|
|
|
2022-12-14 06:03:57 +01:00
|
|
|
@@ -999,7 +999,7 @@ public class CraftEventFactory {
|
2022-06-09 13:55:33 +02:00
|
|
|
cause = DamageCause.SONIC_BOOM;
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- return CraftEventFactory.callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled);
|
2021-10-21 16:11:19 +02:00
|
|
|
+ return CraftEventFactory.callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
|
2021-10-21 00:15:28 +02:00
|
|
|
} else if (source == DamageSource.OUT_OF_WORLD) {
|
|
|
|
EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions);
|
|
|
|
event.setCancelled(cancelled);
|
2022-12-14 06:03:57 +01:00
|
|
|
@@ -1069,7 +1069,7 @@ public class CraftEventFactory {
|
2021-10-21 00:15:28 +02:00
|
|
|
} else {
|
|
|
|
throw new IllegalStateException(String.format("Unhandled damage of %s by %s from %s", entity, damager.getHandle(), source.msgId));
|
|
|
|
}
|
|
|
|
- EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
|
2021-10-21 16:11:19 +02:00
|
|
|
+ EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions, source.isCritical()); // Paper - add critical damage API
|
2021-10-21 00:15:28 +02:00
|
|
|
event.setCancelled(cancelled);
|
|
|
|
CraftEventFactory.callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2022-12-14 06:03:57 +01:00
|
|
|
@@ -1114,20 +1114,28 @@ public class CraftEventFactory {
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cause != null) {
|
|
|
|
- return CraftEventFactory.callEntityDamageEvent(null, entity, cause, modifiers, modifierFunctions, cancelled);
|
2021-10-21 16:11:19 +02:00
|
|
|
+ return CraftEventFactory.callEntityDamageEvent(null, entity, cause, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException(String.format("Unhandled damage of %s from %s", entity, source.msgId));
|
|
|
|
}
|
|
|
|
|
|
|
|
+ @Deprecated // Paper - Add critical damage API
|
|
|
|
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
|
|
|
|
return CraftEventFactory.callEntityDamageEvent(damager, damagee, cause, modifiers, modifierFunctions, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Add critical damage API
|
|
|
|
+ @Deprecated
|
|
|
|
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
|
|
|
|
+ return CraftEventFactory.callEntityDamageEvent(damager, damagee, cause, modifiers, modifierFunctions, false, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled, boolean critical) {
|
|
|
|
+ // Paper end
|
|
|
|
EntityDamageEvent event;
|
|
|
|
if (damager != null) {
|
|
|
|
- event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
|
|
|
|
+ event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions, critical); // Paper - add critical damage API
|
|
|
|
} else {
|
|
|
|
event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
|
|
|
|
}
|