2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 20 May 2021 20:40:53 -0700
Subject: [PATCH] Fix PotionSplashEvent for water splash potions
Fixes SPIGOT-6221: https://hub.spigotmc.org/jira/projects/SPIGOT/issues/SPIGOT-6221
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
2022-12-09 01:33:22 +01:00
index b5e2c391ebcca05db5c960792fcb14991aec4fe2..533aad71202f67206ff4da916b9a8574345aeba3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
2022-12-09 01:33:22 +01:00
@@ -123,33 +123,50 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
2021-12-06 02:56:55 +01:00
}
}
2022-12-08 07:11:20 +01:00
+ 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
2021-06-11 14:02:28 +02:00
private void applyWater() {
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
2022-12-07 21:16:54 +01:00
- List<net.minecraft.world.entity.LivingEntity> list = this.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE);
2022-12-09 01:33:22 +01:00
+ // Paper start
+ List<net.minecraft.world.entity.LivingEntity> list = this.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.APPLY_WATER_GET_ENTITIES_PREDICATE);
+ Map<LivingEntity, Double> affected = new HashMap<>();
+ java.util.Set<LivingEntity> rehydrate = new java.util.HashSet<>();
+ java.util.Set<LivingEntity> extinguish = new java.util.HashSet<>();
2022-12-07 21:16:54 +01:00
Iterator iterator = list.iterator();
2021-06-11 14:02:28 +02:00
2022-12-07 21:16:54 +01:00
while (iterator.hasNext()) {
net.minecraft.world.entity.LivingEntity entityliving = (net.minecraft.world.entity.LivingEntity) iterator.next();
+ if (entityliving instanceof Axolotl axolotl) {
2022-12-09 01:33:22 +01:00
+ rehydrate.add(((org.bukkit.entity.Axolotl) axolotl.getBukkitEntity()));
2022-12-07 21:16:54 +01:00
+ }
double d0 = this.distanceToSqr((Entity) entityliving);
2021-06-11 14:02:28 +02:00
2022-12-07 21:16:54 +01:00
if (d0 < 16.0D) {
if (entityliving.isSensitiveToWater()) {
2021-11-25 00:26:29 +01:00
- entityliving.hurt(DamageSource.indirectMagic(this, this.getOwner()), 1.0F);
2022-12-09 01:33:22 +01:00
+ affected.put(entityliving.getBukkitLivingEntity(), 1.0);
2021-06-11 14:02:28 +02:00
}
2022-12-07 21:16:54 +01:00
if (entityliving.isOnFire() && entityliving.isAlive()) {
2022-12-09 01:33:22 +01:00
- entityliving.extinguishFire();
+ extinguish.add(entityliving.getBukkitLivingEntity());
}
2021-06-11 14:02:28 +02:00
}
}
2021-12-06 02:56:55 +01:00
- List<Axolotl> list1 = this.level.getEntitiesOfClass(Axolotl.class, axisalignedbb);
- Iterator iterator1 = list1.iterator();
-
- while (iterator1.hasNext()) {
- Axolotl axolotl = (Axolotl) iterator1.next();
-
- axolotl.rehydrate();
2022-12-09 01:33:22 +01:00
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = new io.papermc.paper.event.entity.WaterBottleSplashEvent(
+ (org.bukkit.entity.ThrownPotion) this.getBukkitEntity(), affected, rehydrate, extinguish
+ );
+ if (event.callEvent()) {
+ for (LivingEntity affectedEntity : event.getToDamage()) {
+ ((CraftLivingEntity) affectedEntity).getHandle().hurt(DamageSource.indirectMagic(this, this.getOwner()), 1.0F);
+ }
+ for (LivingEntity toExtinguish : event.getToExtinguish()) {
+ ((CraftLivingEntity) toExtinguish).getHandle().extinguishFire();
+ }
+ for (LivingEntity toRehydrate : event.getToRehydrate()) {
+ if (((CraftLivingEntity) toRehydrate).getHandle() instanceof Axolotl axolotl) {
2021-12-06 02:56:55 +01:00
+ axolotl.rehydrate();
+ }
2021-06-11 14:02:28 +02:00
+ }
2021-12-06 02:56:55 +01:00
+ // Paper end
}
2021-06-11 14:02:28 +02:00
2021-12-06 02:56:55 +01:00
}
2022-12-07 21:16:54 +01:00
@@ -170,6 +187,7 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
2021-11-25 00:26:29 +01:00
double d0 = this.distanceToSqr((Entity) entityliving);
2021-06-11 14:02:28 +02:00
if (d0 < 16.0D) {
+ // Paper - diff on change, used when calling the splash event for water splash potions
double d1 = 1.0D - Math.sqrt(d0) / 4.0D;
if (entityliving == entity) {