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
|
2024-01-19 12:30:04 +01:00
|
|
|
index df8c88bfa749e02f633350446101dcce05db7ac1..ed1277fad60992344b94f8a939febaca3edd9702 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
|
2023-03-14 21:25:13 +01:00
|
|
|
@@ -191,4 +191,18 @@ public class DamageSource {
|
|
|
|
public Holder<DamageType> typeHolder() {
|
|
|
|
return this.type;
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
2023-03-14 21:25:13 +01:00
|
|
|
+
|
2021-10-21 00:15:28 +02:00
|
|
|
+ // 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;
|
|
|
|
+ }
|
2024-01-19 12:30:04 +01:00
|
|
|
+ // Paper end - add critical damage API
|
2023-03-14 21:25:13 +01:00
|
|
|
}
|
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
|
2024-01-19 17:54:05 +01:00
|
|
|
index 00c40d6b61a293786ead2dd66daa6d213a341b23..e90bfeca52d74d147616773640517995d98e19bc 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
|
2023-12-06 05:49:31 +01:00
|
|
|
@@ -1263,7 +1263,7 @@ public abstract class Player extends LivingEntity {
|
2021-10-21 00:15:28 +02:00
|
|
|
flag1 = true;
|
|
|
|
}
|
|
|
|
|
2023-06-08 04:12:38 +02:00
|
|
|
- boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity;
|
2024-01-19 12:30:04 +01:00
|
|
|
+ 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; diff on change
|
2021-10-21 00:15:28 +02:00
|
|
|
|
2023-06-08 04:12:38 +02:00
|
|
|
flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper
|
2021-10-21 00:15:28 +02:00
|
|
|
flag2 = flag2 && !this.isSprinting();
|
2023-12-06 05:49:31 +01:00
|
|
|
@@ -1303,7 +1303,7 @@ public abstract class Player extends LivingEntity {
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vec3 vec3d = target.getDeltaMovement();
|
2023-03-14 21:25:13 +01:00
|
|
|
- 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
|
2021-10-21 00:15:28 +02:00
|
|
|
|
|
|
|
if (flag5) {
|
|
|
|
if (i > 0) {
|
2023-12-06 05:49:31 +01:00
|
|
|
@@ -1331,7 +1331,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
|
2023-03-14 21:25:13 +01:00
|
|
|
- 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); // Pa
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
// 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-12-06 05:49:31 +01:00
|
|
|
index 004c130fc03dc01ef75fabdb4ef1ef711e33cb95..ae4319c2532855315bc45995a39d7eb98961b939 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
|
2023-12-06 05:49:31 +01:00
|
|
|
@@ -379,6 +379,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();
|
2023-12-06 05:49:31 +01:00
|
|
|
boolean flag1 = entity.getType().is(EntityTypeTags.DEFLECTS_ARROWS);
|
2021-10-21 00:15:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2024-01-14 13:33:47 +01:00
|
|
|
index 8a7c90014beb5e044abc1fd6f8832bb3c78ffb12..1894fddf867df210d041307d72118eacde9fe5cb 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1043,7 +1043,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);
|
|
|
|
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1075,7 +1075,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
|
2023-06-08 04:12:38 +02:00
|
|
|
} else if (source.is(DamageTypes.FELL_OUT_OF_WORLD)) {
|
2021-10-21 00:15:28 +02:00
|
|
|
EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions);
|
|
|
|
event.setCancelled(cancelled);
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1145,7 +1145,7 @@ public class CraftEventFactory {
|
2021-10-21 00:15:28 +02:00
|
|
|
} else {
|
2023-03-14 21:25:13 +01:00
|
|
|
throw new IllegalStateException(String.format("Unhandled damage of %s by %s from %s", entity, damager.getHandle(), source.getMsgId()));
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
- 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()) {
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1194,20 +1194,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
|
|
|
}
|
|
|
|
|
2023-03-14 21:25:13 +01:00
|
|
|
throw new IllegalStateException(String.format("Unhandled damage of %s from %s", entity, source.getMsgId()));
|
2021-10-21 00:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ @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);
|
|
|
|
}
|