#1390: Improve internal handling of damage sources
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/damagesource/DamageSource.java
|
||||
+++ b/net/minecraft/world/damagesource/DamageSource.java
|
||||
@@ -21,6 +21,88 @@
|
||||
@@ -21,6 +21,103 @@
|
||||
private final Entity directEntity;
|
||||
@Nullable
|
||||
private final Vec3D damageSourcePosition;
|
||||
@@ -8,19 +8,19 @@
|
||||
+ @Nullable
|
||||
+ private org.bukkit.block.Block directBlock; // The block that caused the damage. damageSourcePosition is not used for all block damages
|
||||
+ @Nullable
|
||||
+ public org.bukkit.block.BlockState blockState; // The block state of the block relevant to this damage source
|
||||
+ private boolean withSweep = false;
|
||||
+ private org.bukkit.block.BlockState directBlockState; // The block state of the block relevant to this damage source
|
||||
+ private boolean sweep = 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
|
||||
+ private Entity customEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla
|
||||
+
|
||||
+ public DamageSource sweep() {
|
||||
+ this.withSweep = true;
|
||||
+ this.sweep = true;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ public boolean isSweep() {
|
||||
+ return this.withSweep;
|
||||
+ return this.sweep;
|
||||
+ }
|
||||
+
|
||||
+ public DamageSource melting() {
|
||||
@@ -41,18 +41,18 @@
|
||||
+ return this.poison;
|
||||
+ }
|
||||
+
|
||||
+ public Entity getCausingEntity() {
|
||||
+ return (this.customCausingEntity != null) ? this.customCausingEntity : this.causingEntity;
|
||||
+ public Entity getDamager() {
|
||||
+ return (this.customEntityDamager != null) ? this.customEntityDamager : this.directEntity;
|
||||
+ }
|
||||
+
|
||||
+ public DamageSource customCausingEntity(Entity entity) {
|
||||
+ public DamageSource customEntityDamager(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.customCausingEntity != null || this.directEntity == entity || this.causingEntity == entity) {
|
||||
+ if (this.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
|
||||
+ return this;
|
||||
+ }
|
||||
+ DamageSource damageSource = this.cloneInstance();
|
||||
+ damageSource.customCausingEntity = entity;
|
||||
+ damageSource.customEntityDamager = entity;
|
||||
+ return damageSource;
|
||||
+ }
|
||||
+
|
||||
@@ -77,10 +77,25 @@
|
||||
+ return damageSource;
|
||||
+ }
|
||||
+
|
||||
+ 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();
|
||||
+ damageSource.directBlockState = directBlockState;
|
||||
+ 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.directBlockState = this.getDirectBlockState();
|
||||
+ damageSource.sweep = this.isSweep();
|
||||
+ damageSource.poison = this.isPoison();
|
||||
+ damageSource.melting = this.isMelting();
|
||||
+ return damageSource;
|
||||
|
||||
@@ -33,21 +33,32 @@
|
||||
public DamageSource inFire() {
|
||||
return this.inFire;
|
||||
}
|
||||
@@ -250,7 +266,17 @@
|
||||
@@ -242,7 +258,13 @@
|
||||
}
|
||||
|
||||
public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1) {
|
||||
- return this.source(entity1 != null && entity != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION, entity, entity1);
|
||||
+ // CraftBukkit start
|
||||
+ return this.explosion(entity, entity1, entity1 != null && entity != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION);
|
||||
+ }
|
||||
+
|
||||
+ public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1, ResourceKey<DamageType> resourceKey) {
|
||||
+ return this.source(resourceKey, entity, entity1);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public DamageSource sonicBoom(Entity entity) {
|
||||
@@ -250,7 +272,13 @@
|
||||
}
|
||||
|
||||
public DamageSource badRespawnPointExplosion(Vec3D vec3d) {
|
||||
- return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
|
||||
+ // CraftBukkit start
|
||||
+ return badRespawnPointExplosion(vec3d, null, null, null);
|
||||
+ return badRespawnPointExplosion(vec3d, null);
|
||||
+ }
|
||||
+
|
||||
+ public DamageSource badRespawnPointExplosion(Vec3D vec3d, net.minecraft.world.level.World world, net.minecraft.world.level.block.state.IBlockData blockData, net.minecraft.core.BlockPosition position) {
|
||||
+ DamageSource damageSource = new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
|
||||
+ if (world != null && blockData != null && position != null) {
|
||||
+ damageSource.blockState = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(world, position, blockData, null);
|
||||
+ }
|
||||
+ return damageSource;
|
||||
+ public DamageSource badRespawnPointExplosion(Vec3D vec3d, org.bukkit.block.BlockState blockState) {
|
||||
+ return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d).directBlockState(blockState);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user