From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Mon, 10 May 2021 22:10:23 -0400 Subject: [PATCH] Add origin location to EntityDamageByBlockEvent diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java index e6bf78f46acc37d9515d58cec3587e236ac0733c..1cea7c5bf99e0c99e8160658df0eab065cca2841 100644 --- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java +++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java @@ -46,6 +46,16 @@ public class DamageSource { private boolean D; private boolean E; public final String translationIndex; + // Parchment start + private @Nullable org.bukkit.Location location; + public @Nullable org.bukkit.Location getLocation() { + return location; + } + public DamageSource location(@Nullable org.bukkit.Location location) { + this.location = location; + return this; + } + // Parchment end // CraftBukkit start private boolean sweep; @@ -109,11 +119,11 @@ public class DamageSource { } public static DamageSource explosion(@Nullable Explosion explosion) { - return d(explosion != null ? explosion.getSource() : null); + return d(explosion != null ? explosion.getSource() : null).location(explosion != null ? explosion.getBukkitLocation() : null); // Parchment } public static DamageSource d(@Nullable EntityLiving entityliving) { - return entityliving != null ? (new EntityDamageSource("explosion.player", entityliving)).r().setExplosion() : (new DamageSource("explosion")).r().setExplosion(); + return (entityliving != null ? (new EntityDamageSource("explosion.player", entityliving)) : (new DamageSource("explosion"))).r().setExplosion(); // Parchment } public static DamageSource a() { @@ -234,8 +244,9 @@ public class DamageSource { return entity instanceof EntityHuman && ((EntityHuman) entity).abilities.canInstantlyBuild; } + public Vec3D getPosition() {return w();} // Parchment - OBFHELPER @Nullable public Vec3D w() { - return null; + return location == null ? null : new Vec3D(location.getX(), location.getY(), location.getZ()); // Parchment } } diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java index 79008bda42558ea7d28ccf51b66405a3bdb52da7..8fd81f4238416fd6a5d09e3307aebe785f8e28e1 100644 --- a/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java @@ -85,6 +85,13 @@ public class Explosion { this.l = explosiondamagecalculator == null ? this.a(entity) : explosiondamagecalculator; } + // Parchment start + public @Nullable org.bukkit.Location getBukkitLocation() { + if (this.world == null) return null; + return new org.bukkit.Location(world.getWorld(), posX, posY, posZ); + } + // Parchment end + private ExplosionDamageCalculator a(@Nullable Entity entity) { return (ExplosionDamageCalculator) (entity == null ? Explosion.a : new ExplosionDamageCalculatorEntity(entity)); } diff --git a/src/main/java/net/minecraft/world/level/block/BlockBed.java b/src/main/java/net/minecraft/world/level/block/BlockBed.java index 00a01a157deec004bcf2f8587723a0ecd0bfef85..ece4648bf133621b644291390f5743f9c48c750d 100644 --- a/src/main/java/net/minecraft/world/level/block/BlockBed.java +++ b/src/main/java/net/minecraft/world/level/block/BlockBed.java @@ -89,7 +89,12 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity { world.a(blockposition1, false); } - world.createExplosion((Entity) null, DamageSource.a(), (ExplosionDamageCalculator) null, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, 5.0F, true, Explosion.Effect.DESTROY); + // Parchment start + double posX = blockposition.getX() + 0.5D; + double posY = blockposition.getY() + 0.5D; + double posZ = blockposition.getZ() + 0.5D; + world.createExplosion((Entity) null, DamageSource.a().location(new org.bukkit.Location(world.getWorld(), posX, posY, posZ)), (ExplosionDamageCalculator) null, posX, posY, posZ, 5.0F, true, Explosion.Effect.DESTROY); + // Parchment end return EnumInteractionResult.SUCCESS; } else if ((Boolean) iblockdata.get(BlockBed.OCCUPIED)) { if (!this.a(world, blockposition)) { @@ -138,7 +143,12 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity { world.a(blockposition1, false); } - world.createExplosion((Entity) null, DamageSource.a(), (ExplosionDamageCalculator) null, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, 5.0F, true, Explosion.Effect.DESTROY); + // Parchment start + double posX = blockposition.getX() + 0.5D; + double posY = blockposition.getY() + 0.5D; + double posZ = blockposition.getZ() + 0.5D; + world.createExplosion((Entity) null, DamageSource.a().location(new org.bukkit.Location(world.getWorld(), posX, posY, posZ)), (ExplosionDamageCalculator) null, posX, posY, posZ, 5.0F, true, Explosion.Effect.DESTROY); + // Parchment end return EnumInteractionResult.SUCCESS; } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index a678277416cd71e01cd6980bcfaf9a9803e7ea17..0df40bc18dcd66a367b82e435316851eb99d077c 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -941,7 +941,7 @@ public class CraftEventFactory { entityDamage = null; EntityDamageEvent event; if (damager == null) { - event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, modifiers, modifierFunctions); + event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, source.getLocation(), modifiers, modifierFunctions); // Parchment } else if (entity instanceof EntityEnderDragon && /*PAIL FIXME ((EntityEnderDragon) entity).target == damager*/ false) { event = new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.ENTITY_EXPLOSION, modifiers, modifierFunctions); } else { @@ -977,7 +977,7 @@ public class CraftEventFactory { return callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled); } else if (source == DamageSource.OUT_OF_WORLD) { - EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions); + EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, entity.getBukkitEntity().getLocation(), modifiers, modifierFunctions); // Parchment event.setCancelled(cancelled); callEvent(event); if (!event.isCancelled()) {