mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-22 20:48:25 +01:00
Fix WaterBottleSplashEvent not forwarding hit result (#10203)
This commit is contained in:
parent
a863590fd5
commit
9665ac3903
3 changed files with 51 additions and 7 deletions
|
@ -16,11 +16,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import java.util.Map;
|
+import java.util.Map;
|
||||||
+import java.util.Set;
|
+import java.util.Set;
|
||||||
+import java.util.stream.Collectors;
|
+import java.util.stream.Collectors;
|
||||||
|
+import org.bukkit.block.Block;
|
||||||
|
+import org.bukkit.block.BlockFace;
|
||||||
|
+import org.bukkit.entity.Entity;
|
||||||
+import org.bukkit.entity.LivingEntity;
|
+import org.bukkit.entity.LivingEntity;
|
||||||
+import org.bukkit.entity.ThrownPotion;
|
+import org.bukkit.entity.ThrownPotion;
|
||||||
+import org.bukkit.event.entity.PotionSplashEvent;
|
+import org.bukkit.event.entity.PotionSplashEvent;
|
||||||
+import org.jetbrains.annotations.ApiStatus;
|
+import org.jetbrains.annotations.ApiStatus;
|
||||||
+import org.jetbrains.annotations.NotNull;
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+import org.jetbrains.annotations.Nullable;
|
||||||
+import org.jetbrains.annotations.Unmodifiable;
|
+import org.jetbrains.annotations.Unmodifiable;
|
||||||
+
|
+
|
||||||
+/**
|
+/**
|
||||||
|
@ -35,11 +39,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ @ApiStatus.Internal
|
+ @ApiStatus.Internal
|
||||||
+ public WaterBottleSplashEvent(
|
+ public WaterBottleSplashEvent(
|
||||||
+ final @NotNull ThrownPotion potion,
|
+ final @NotNull ThrownPotion potion,
|
||||||
|
+ final @Nullable Entity hitEntity,
|
||||||
|
+ final @Nullable Block hitBlock,
|
||||||
|
+ final @Nullable BlockFace hitFace,
|
||||||
+ final @NotNull Map<LivingEntity, Double> affectedEntities,
|
+ final @NotNull Map<LivingEntity, Double> affectedEntities,
|
||||||
+ final @NotNull Set<LivingEntity> rehydrate,
|
+ final @NotNull Set<LivingEntity> rehydrate,
|
||||||
+ final @NotNull Set<LivingEntity> extinguish
|
+ final @NotNull Set<LivingEntity> extinguish
|
||||||
+ ) {
|
+ ) {
|
||||||
+ super(potion, affectedEntities);
|
+ super(potion, hitEntity, hitBlock, hitFace, affectedEntities);
|
||||||
+ this.rehydrate = rehydrate;
|
+ this.rehydrate = rehydrate;
|
||||||
+ this.extinguish = extinguish;
|
+ this.extinguish = extinguish;
|
||||||
+ }
|
+ }
|
||||||
|
|
|
@ -19,7 +19,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
- this.applyWater();
|
- this.applyWater();
|
||||||
+ showParticles = this.applyWater(); // Paper - Fix potions splash events
|
+ showParticles = this.applyWater(hitResult); // Paper - Fix potions splash events
|
||||||
} else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
|
} else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
|
||||||
if (this.isLingering()) {
|
if (this.isLingering()) {
|
||||||
- this.makeAreaOfEffectCloud(itemstack, potionregistry, hitResult); // CraftBukkit - Pass MovingObjectPosition
|
- this.makeAreaOfEffectCloud(itemstack, potionregistry, hitResult); // CraftBukkit - Pass MovingObjectPosition
|
||||||
|
@ -41,7 +41,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
- private void applyWater() {
|
- private void applyWater() {
|
||||||
+ private static final Predicate<net.minecraft.world.entity.LivingEntity> APPLY_WATER_GET_ENTITIES_PREDICATE = ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE.or(Axolotl.class::isInstance); // Paper - Fix potions splash events
|
+ private static final Predicate<net.minecraft.world.entity.LivingEntity> APPLY_WATER_GET_ENTITIES_PREDICATE = ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE.or(Axolotl.class::isInstance); // Paper - Fix potions splash events
|
||||||
+ private boolean applyWater() { // Paper - Fix potions splash events
|
+ private boolean applyWater(@Nullable HitResult hitResult) { // Paper - Fix potions splash events
|
||||||
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
|
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
|
||||||
- List<net.minecraft.world.entity.LivingEntity> list = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE);
|
- List<net.minecraft.world.entity.LivingEntity> list = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE);
|
||||||
+ // Paper start - Fix potions splash events
|
+ // Paper start - Fix potions splash events
|
||||||
|
@ -78,10 +78,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
- Axolotl axolotl = (Axolotl) iterator1.next();
|
- Axolotl axolotl = (Axolotl) iterator1.next();
|
||||||
-
|
-
|
||||||
- axolotl.rehydrate();
|
- axolotl.rehydrate();
|
||||||
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = new io.papermc.paper.event.entity.WaterBottleSplashEvent(
|
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callWaterBottleSplashEvent(
|
||||||
+ (org.bukkit.entity.ThrownPotion) this.getBukkitEntity(), affected, rehydrate, extinguish
|
+ this, hitResult, affected, rehydrate, extinguish
|
||||||
+ );
|
+ );
|
||||||
+ if (event.callEvent()) {
|
+ if (!event.isCancelled()) {
|
||||||
+ for (LivingEntity affectedEntity : event.getToDamage()) {
|
+ for (LivingEntity affectedEntity : event.getToDamage()) {
|
||||||
+ ((CraftLivingEntity) affectedEntity).getHandle().hurt(this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
|
+ ((CraftLivingEntity) affectedEntity).getHandle().hurt(this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
|
||||||
+ }
|
+ }
|
||||||
|
@ -153,3 +153,40 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLingering() {
|
public boolean isLingering() {
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper start - Fix potions splash events
|
||||||
|
+ public static io.papermc.paper.event.entity.WaterBottleSplashEvent callWaterBottleSplashEvent(net.minecraft.world.entity.projectile.ThrownPotion potion, @Nullable HitResult hitResult, Map<LivingEntity, Double> affectedEntities, java.util.Set<LivingEntity> rehydrate, java.util.Set<LivingEntity> extinguish) {
|
||||||
|
+ ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();
|
||||||
|
+
|
||||||
|
+ Block hitBlock = null;
|
||||||
|
+ BlockFace hitFace = null;
|
||||||
|
+ org.bukkit.entity.Entity hitEntity = null;
|
||||||
|
+
|
||||||
|
+ if (hitResult != null) {
|
||||||
|
+ if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||||
|
+ BlockHitResult blockHitResult = (BlockHitResult) hitResult;
|
||||||
|
+ hitBlock = CraftBlock.at(potion.level(), blockHitResult.getBlockPos());
|
||||||
|
+ hitFace = CraftBlock.notchToBlockFace(blockHitResult.getDirection());
|
||||||
|
+ } else if (hitResult.getType() == HitResult.Type.ENTITY) {
|
||||||
|
+ hitEntity = ((EntityHitResult) hitResult).getEntity().getBukkitEntity();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = new io.papermc.paper.event.entity.WaterBottleSplashEvent(
|
||||||
|
+ thrownPotion, hitEntity, hitBlock, hitFace, affectedEntities, rehydrate, extinguish
|
||||||
|
+ );
|
||||||
|
+ event.callEvent();
|
||||||
|
+ return event;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - Fix potions splash events
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* BlockFadeEvent
|
||||||
|
*/
|
||||||
|
|
|
@ -30,7 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // Paper start - More projectile API
|
+ // Paper start - More projectile API
|
||||||
+ this.splash(hitResult);
|
+ this.splash(hitResult);
|
||||||
+ }
|
+ }
|
||||||
+ public void splash(@org.jetbrains.annotations.Nullable HitResult hitResult) {
|
+ public void splash(@Nullable HitResult hitResult) {
|
||||||
+ // Paper end - More projectile API
|
+ // Paper end - More projectile API
|
||||||
if (!this.level().isClientSide) {
|
if (!this.level().isClientSide) {
|
||||||
ItemStack itemstack = this.getItem();
|
ItemStack itemstack = this.getItem();
|
||||||
|
|
Loading…
Add table
Reference in a new issue