Paper/patches/server/0628-Fix-potions-splash-events.patch

156 lines
8.4 KiB
Diff
Raw Normal View History

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 potions splash events
2021-06-11 14:02:28 +02:00
Fix PotionSplashEvent for water splash potions
2021-06-11 14:02:28 +02:00
Fixes SPIGOT-6221: https://hub.spigotmc.org/jira/projects/SPIGOT/issues/SPIGOT-6221
Fix splash events cancellation that still show particles/sound
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9440) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
2023-07-04 10:22:56 +02:00
index 089b5fbb240d494bf86a05078d534165bfc2f7ee..135cd9c154a90d5c2351d8bdd8217134114af5a0 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
2023-03-14 21:25:13 +01:00
@@ -104,56 +104,77 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
Potion potionregistry = PotionUtils.getPotion(itemstack);
List<MobEffectInstance> list = PotionUtils.getMobEffects(itemstack);
boolean flag = potionregistry == Potions.WATER && list.isEmpty();
+ boolean showParticles = true; // Paper
if (flag) {
- this.applyWater();
+ showParticles = this.applyWater(); // Paper
} else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
if (this.isLingering()) {
- this.makeAreaOfEffectCloud(itemstack, potionregistry);
+ showParticles = this.makeAreaOfEffectCloud(itemstack, potionregistry); // Paper
} else {
- this.applySplash(list, hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null);
+ showParticles = this.applySplash(list, hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null); // Paper
}
}
+ if (showParticles) { // Paper
int i = potionregistry.hasInstantEffects() ? 2007 : 2002;
2023-06-08 04:04:01 +02:00
this.level().levelEvent(i, this.blockPosition(), PotionUtils.getColor(itemstack));
+ } // Paper
this.discard();
}
}
- private void applyWater() {
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
+ private boolean applyWater() { // Paper
2021-06-11 14:02:28 +02:00
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
2023-06-08 04:04:01 +02:00
- 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
2023-06-08 04:04:01 +02:00
+ 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) {
+ 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()) {
2023-03-14 21:25:13 +01:00
- entityliving.hurt(this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
+ 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()) {
- entityliving.extinguishFire();
+ extinguish.add(entityliving.getBukkitLivingEntity());
}
2021-06-11 14:02:28 +02:00
}
}
2023-06-08 04:04:01 +02:00
- List<Axolotl> list1 = this.level().getEntitiesOfClass(Axolotl.class, axisalignedbb);
- Iterator iterator1 = list1.iterator();
-
- while (iterator1.hasNext()) {
- Axolotl axolotl = (Axolotl) iterator1.next();
-
- axolotl.rehydrate();
+ 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()) {
2023-03-14 21:25:13 +01:00
+ ((CraftLivingEntity) affectedEntity).getHandle().hurt(this.damageSources().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) {
+ axolotl.rehydrate();
+ }
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
+ return !event.isCancelled(); // Paper
2021-06-11 14:02:28 +02:00
}
- private void applySplash(List<MobEffectInstance> statusEffects, @Nullable Entity entity) {
+ private boolean applySplash(List<MobEffectInstance> statusEffects, @Nullable Entity entity) { // Paper
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
2023-06-08 04:04:01 +02:00
List<net.minecraft.world.entity.LivingEntity> list1 = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb);
Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // CraftBukkit
2023-03-14 21:25:13 +01:00
@@ -171,6 +192,7 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
2021-06-11 14:02:28 +02:00
if (d0 < 16.0D) {
2023-03-14 21:25:13 +01:00
double d1;
2021-06-11 14:02:28 +02:00
2023-03-14 21:25:13 +01:00
+ // Paper - diff on change, used when calling the splash event for water splash potions
2021-06-11 14:02:28 +02:00
if (entityliving == entity) {
2023-03-14 21:25:13 +01:00
d1 = 1.0D;
} else {
@@ -226,10 +248,11 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
}
}
}
+ return !event.isCancelled(); // Paper
}
- private void makeAreaOfEffectCloud(ItemStack stack, Potion potion) {
+ private boolean makeAreaOfEffectCloud(ItemStack stack, Potion potion) { // Paper
2023-06-08 04:04:01 +02:00
AreaEffectCloud entityareaeffectcloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
Entity entity = this.getOwner();
2023-03-14 21:25:13 +01:00
@@ -244,10 +267,12 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
entityareaeffectcloud.setPotion(potion);
Iterator iterator = PotionUtils.getCustomEffects(stack).iterator();
+ boolean noEffects = potion.getEffects().isEmpty(); // Paper
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
entityareaeffectcloud.addEffect(new MobEffectInstance(mobeffect));
+ noEffects = false; // Paper
}
CompoundTag nbttagcompound = stack.getTag();
2023-03-14 21:25:13 +01:00
@@ -258,12 +283,13 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
// CraftBukkit start
org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, entityareaeffectcloud);
- if (!(event.isCancelled() || entityareaeffectcloud.isRemoved())) {
+ if (!(event.isCancelled() || entityareaeffectcloud.isRemoved() || (noEffects && entityareaeffectcloud.effects.isEmpty() && entityareaeffectcloud.getPotion().getEffects().isEmpty()))) { // Paper - don't spawn area effect cloud if the effects were empty and not changed during the event handling
2023-06-08 04:04:01 +02:00
this.level().addFreshEntity(entityareaeffectcloud);
} else {
entityareaeffectcloud.discard();
}
// CraftBukkit end
+ return !event.isCancelled(); // Paper
}
public boolean isLingering() {