2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/damagesource/DamageSource.java
|
|
|
|
+++ b/net/minecraft/world/damagesource/DamageSource.java
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -21,6 +21,86 @@
|
2023-03-14 17:30:00 +01:00
|
|
|
private final Entity directEntity;
|
|
|
|
@Nullable
|
|
|
|
private final Vec3D 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
|
|
|
|
+ private boolean withSweep = false;
|
|
|
|
+ private boolean melting = false;
|
|
|
|
+ private boolean poison = false;
|
|
|
|
+ private Entity customCausingEntity = null; // This field is a helper for when causing entity damage is not set by vanilla
|
2016-12-23 12:39:33 +01:00
|
|
|
+
|
|
|
|
+ public DamageSource sweep() {
|
2024-02-10 23:54:25 +01:00
|
|
|
+ this.withSweep = 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() {
|
|
|
|
+ return this.withSweep;
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Entity getCausingEntity() {
|
|
|
|
+ return (this.customCausingEntity != null) ? this.customCausingEntity : this.causingEntity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource customCausingEntity(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
|
|
|
|
+ if (this.customCausingEntity != null || this.directEntity == entity || this.causingEntity == entity) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
2024-02-10 23:54:25 +01:00
|
|
|
+ DamageSource damageSource = this.cloneInstance();
|
|
|
|
+ damageSource.customCausingEntity = entity;
|
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public org.bukkit.block.Block getDirectBlock() {
|
|
|
|
+ return this.directBlock;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DamageSource directBlock(net.minecraft.world.level.World world, net.minecraft.core.BlockPosition blockPosition) {
|
|
|
|
+ if (blockPosition == null || world == null) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ return directBlock(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockPosition));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DamageSource cloneInstance() {
|
|
|
|
+ DamageSource damageSource = new DamageSource(this.type, this.directEntity, this.causingEntity, this.damageSourcePosition);
|
|
|
|
+ damageSource.directBlock = this.getDirectBlock();
|
|
|
|
+ damageSource.withSweep = this.isSweep();
|
|
|
|
+ damageSource.poison = this.isPoison();
|
|
|
|
+ damageSource.melting = this.isMelting();
|
|
|
|
+ return damageSource;
|
|
|
|
+ }
|
2016-12-23 12:39:33 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
|
2023-03-14 17:30:00 +01:00
|
|
|
public String toString() {
|
|
|
|
return "DamageSource (" + this.type().msgId() + ")";
|