Files
ParchmentMC/patches/api/0005-Add-origin-location-to-EntityDamageByBlockEvent.patch
Blast-MC 4c2ae38401 1.20.6
2024-05-19 16:31:52 -04:00

62 lines
3.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Fri, 18 Jun 2021 14:06:43 -0400
Subject: [PATCH] Add origin location to EntityDamageByBlockEvent
diff --git a/src/main/java/org/bukkit/event/entity/EntityDamageByBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamageByBlockEvent.java
index 148c4aad384ae8e3b8b22d264a84bddfbcafdf1e..61fcdd178fa5a8f13c889a78f431d2a5529c8c43 100644
--- a/src/main/java/org/bukkit/event/entity/EntityDamageByBlockEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityDamageByBlockEvent.java
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nullable;
public class EntityDamageByBlockEvent extends EntityDamageEvent {
private final Block damager;
private final BlockState damagerState;
+ private final org.bukkit.Location location; // Parchment
@Deprecated(forRemoval = true)
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
@@ -30,19 +31,40 @@ public class EntityDamageByBlockEvent extends EntityDamageEvent {
super(damagee, cause, damageSource, damage);
this.damager = damager;
this.damagerState = damagerState;
+ this.location = damager != null ? damager.getLocation() : null; // Parchment
}
@Deprecated(forRemoval = true)
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
- this(damager, (damager != null) ? damager.getState() : null, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
+ this(damager, (damager != null) ? damager.getState() : null, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions, null);
}
- public EntityDamageByBlockEvent(@Nullable final Block damager, @Nullable final BlockState damagerState, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
+ public EntityDamageByBlockEvent(@Nullable final Block damager, @Nullable final BlockState damagerState, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions, @Nullable final org.bukkit.Location damageLocation) { // Parchment
super(damagee, cause, damageSource, modifiers, modifierFunctions);
this.damager = damager;
this.damagerState = damagerState;
+ // Parchment start
+ if (damageLocation != null)
+ this.location = damageLocation;
+ else if (damager != null)
+ this.location = damager.getLocation();
+ else
+ this.location = null;
+ // Parchment end
}
+ /**
+ * Gets the location of the damage source.
+ *
+ * @return Originating location of the damage source
+ */
+ @Nullable
+ public org.bukkit.Location getLocation() {
+ return location;
+ }
+ // Parchment end
+
+
/**
* Returns the block that damaged the player.
*