2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/damagesource/DamageSource.java
|
|
|
|
+++ b/net/minecraft/world/damagesource/DamageSource.java
|
2024-12-11 22:26:55 +01:00
|
|
|
@@ -21,7 +21,120 @@
|
2023-03-14 17:30:00 +01:00
|
|
|
private final Entity directEntity;
|
|
|
|
@Nullable
|
2024-12-11 22:26:55 +01:00
|
|
|
private final Vec3 damageSourcePosition;
|
2016-12-23 12:39:33 +01:00
|
|
|
+ // CraftBukkit start
|
2024-02-10 23:54:25 +01:00
|
|
|
+ @Nullable
|
|
|
|
+ private org.bukkit.block.Block directBlock; // The block that caused the damage. damageSourcePosition is not used for all block damages
|
2024-04-29 12:08:56 +02:00
|
|
|
+ @Nullable
|
2024-05-04 00:15:51 +02:00
|
|
|
+ private org.bukkit.block.BlockState directBlockState; // The block state of the block relevant to this damage source
|
|
|
|
+ private boolean sweep = false;
|
2024-02-10 23:54:25 +01:00
|
|
|
+ private boolean melting = false;
|
|
|
|
+ private boolean poison = false;
|
2024-06-14 22:47:48 +02:00
|
|
|
+ private Entity customEntityDamager = null; // This field is a helper for when direct entity damage is not set by vanilla
|
|
|
|
+ private Entity customCausingEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla
|
2024-12-11 22:26:55 +01:00
|
|
|
|
2016-12-23 12:39:33 +01:00
|
|
|
+ public DamageSource sweep() {
|
2024-05-04 00:15:51 +02:00
|
|
|
+ this.sweep = true;
|
2016-12-23 12:39:33 +01:00
|
|
|
+ return this;
|
|
|
|
+ }
|
2023-03-14 17:30:00 +01:00
|
|
|
+
|
2024-02-10 23:54:25 +01:00
|
|
|
+ public boolean isSweep() {
|
2024-05-04 00:15:51 +02:00
|
|
|
+ return this.sweep;
|
2023-03-14 17:30:00 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource melting() {
|
|
|
|
+ this.melting = true;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
2024-02-10 23:54:25 +01:00
|
|
|
+ public boolean isMelting() {
|
|
|
|
+ return this.melting;
|
2023-03-14 17:30:00 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource poison() {
|
|
|
|
+ this.poison = true;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
2024-02-10 23:54:25 +01:00
|
|
|
+
|
|
|
|
+ public boolean isPoison() {
|
|
|
|
+ return this.poison;
|
|
|
|
+ }
|
|
|
|
+
|
2024-05-04 00:15:51 +02:00
|
|
|
+ public Entity getDamager() {
|
|
|
|
+ return (this.customEntityDamager != null) ? this.customEntityDamager : this.directEntity;
|
2024-02-10 23:54:25 +01:00
|
|
|
+ }
|
|
|
|
+
|
2024-06-14 22:47:48 +02:00
|
|
|
+ public Entity getCausingDamager() {
|
|
|
|
+ return (this.customCausingEntityDamager != null) ? this.customCausingEntityDamager : this.causingEntity;
|
|
|
|
+ }
|
|
|
|
+
|
2024-05-04 00:15:51 +02:00
|
|
|
+ public DamageSource customEntityDamager(Entity entity) {
|
2024-04-07 03:49:28 +02:00
|
|
|
+ // This method is not intended for change the causing entity if is already set
|
|
|
|
+ // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity
|
2024-05-04 00:15:51 +02:00
|
|
|
+ if (this.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
|
2024-04-07 03:49:28 +02:00
|
|
|
+ return this;
|
|
|
|
+ }
|
2024-02-10 23:54:25 +01:00
|
|
|
+ DamageSource damageSource = this.cloneInstance();
|
2024-05-04 00:15:51 +02:00
|
|
|
+ damageSource.customEntityDamager = entity;
|
2024-06-14 22:47:48 +02:00
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource customCausingEntityDamager(Entity entity) {
|
|
|
|
+ // This method is not intended for change the causing entity if is already set
|
|
|
|
+ // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity
|
|
|
|
+ if (this.customCausingEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ DamageSource damageSource = this.cloneInstance();
|
|
|
|
+ damageSource.customCausingEntityDamager = entity;
|
2024-02-10 23:54:25 +01:00
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public org.bukkit.block.Block getDirectBlock() {
|
|
|
|
+ return this.directBlock;
|
|
|
|
+ }
|
|
|
|
+
|
2024-12-11 22:26:55 +01:00
|
|
|
+ public DamageSource directBlock(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos blockPosition) {
|
2024-02-10 23:54:25 +01:00
|
|
|
+ if (blockPosition == null || world == null) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
2024-12-11 22:26:55 +01:00
|
|
|
+ return this.directBlock(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockPosition));
|
2024-02-10 23:54:25 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource directBlock(org.bukkit.block.Block block) {
|
|
|
|
+ if (block == null) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ // Cloning the instance lets us return unique instances of DamageSource without affecting constants defined in DamageSources
|
|
|
|
+ DamageSource damageSource = this.cloneInstance();
|
|
|
|
+ damageSource.directBlock = block;
|
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
|
|
|
+
|
2024-05-04 00:15:51 +02:00
|
|
|
+ public org.bukkit.block.BlockState getDirectBlockState() {
|
|
|
|
+ return this.directBlockState;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource directBlockState(org.bukkit.block.BlockState blockState) {
|
|
|
|
+ if (blockState == null) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ // Cloning the instance lets us return unique instances of DamageSource without affecting constants defined in DamageSources
|
|
|
|
+ DamageSource damageSource = this.cloneInstance();
|
2024-05-04 03:58:56 +02:00
|
|
|
+ damageSource.directBlockState = blockState;
|
2024-05-04 00:15:51 +02:00
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
|
|
|
+
|
2024-02-10 23:54:25 +01:00
|
|
|
+ private DamageSource cloneInstance() {
|
|
|
|
+ DamageSource damageSource = new DamageSource(this.type, this.directEntity, this.causingEntity, this.damageSourcePosition);
|
|
|
|
+ damageSource.directBlock = this.getDirectBlock();
|
2024-05-04 00:15:51 +02:00
|
|
|
+ damageSource.directBlockState = this.getDirectBlockState();
|
|
|
|
+ damageSource.sweep = this.isSweep();
|
2024-02-10 23:54:25 +01:00
|
|
|
+ damageSource.poison = this.isPoison();
|
|
|
|
+ damageSource.melting = this.isMelting();
|
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
2016-12-23 12:39:33 +01:00
|
|
|
+ // CraftBukkit end
|
2024-12-11 22:26:55 +01:00
|
|
|
+
|
2023-03-14 17:30:00 +01:00
|
|
|
public String toString() {
|
|
|
|
return "DamageSource (" + this.type().msgId() + ")";
|
2024-12-11 22:26:55 +01:00
|
|
|
}
|
2021-07-26 17:32:36 +02:00
|
|
|
@@ -163,4 +276,18 @@
|
|
|
|
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
|
|
|
|
}
|