diff --git a/patches/api/0394-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch b/patches/api/0394-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch new file mode 100644 index 0000000000..bec7a5d015 --- /dev/null +++ b/patches/api/0394-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MelnCat +Date: Mon, 19 Sep 2022 14:04:13 -0700 +Subject: [PATCH] Add a consumer parameter to ProjectileSource#launchProjectile + + +diff --git a/src/main/java/org/bukkit/projectiles/ProjectileSource.java b/src/main/java/org/bukkit/projectiles/ProjectileSource.java +index eabd8b926ec1c934cd7e77b7cc6adfae16771021..6cb28e65b82198b19f159f8e8334208f7f62d394 100644 +--- a/src/main/java/org/bukkit/projectiles/ProjectileSource.java ++++ b/src/main/java/org/bukkit/projectiles/ProjectileSource.java +@@ -31,4 +31,24 @@ public interface ProjectileSource { + */ + @NotNull + public T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity); ++ ++ // Paper start ++ /** ++ * Launches a {@link Projectile} from the ProjectileSource with an ++ * initial velocity, with the supplied function run before the ++ * entity is added to the world. ++ *
++ * Note that when the function is run, the entity will not be actually in ++ * the world. Any operation involving such as teleporting the entity is undefined ++ * until after this function returns. ++ * ++ * @param a projectile subclass ++ * @param projectile class of the projectile to launch ++ * @param velocity the velocity with which to launch ++ * @param function the function to be run before the entity is spawned ++ * @return the launched projectile ++ */ ++ @NotNull ++ public T launchProjectile(@NotNull Class projectile, @Nullable Vector velocity, @Nullable org.bukkit.util.Consumer function); ++ // Paper end + } diff --git a/patches/server/0943-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch b/patches/server/0943-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch new file mode 100644 index 0000000000..8e7053e1f5 --- /dev/null +++ b/patches/server/0943-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MelnCat +Date: Mon, 19 Sep 2022 14:16:10 -0700 +Subject: [PATCH] Add a consumer parameter to ProjectileSource#launchProjectile + + +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +index 1994dd3c272395a27474ec1b37a924a24fc50fd6..e807ef287136e7b3931197e45434a3f618cf3054 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +@@ -482,8 +482,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { + } + + @Override +- @SuppressWarnings("unchecked") + public T launchProjectile(Class projectile, Vector velocity) { ++ // Paper start - launchProjectile consumer ++ return this.launchProjectile(projectile, velocity, null); ++ } ++ ++ @Override ++ @SuppressWarnings("unchecked") ++ public T launchProjectile(Class projectile, Vector velocity, org.bukkit.util.Consumer function) { ++ // Paper end - launchProjectile consumer + Preconditions.checkState(!this.getHandle().generation, "Cannot launch projectile during world generation"); + + net.minecraft.world.level.Level world = ((CraftWorld) getWorld()).getHandle(); +@@ -566,6 +573,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { + if (velocity != null) { + ((T) launch.getBukkitEntity()).setVelocity(velocity); + } ++ // Paper start - launchProjectile consumer ++ if (function != null) { ++ function.accept((T) launch.getBukkitEntity()); ++ } ++ // Paper end - launchProjectile consumer + + world.addFreshEntity(launch); + return (T) launch.getBukkitEntity(); +diff --git a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +index 388647c2ef814270942f4e6c6eb57a3abaf84212..2afb7af0a90959edd3b0ead2fe4d9018b5560aa4 100644 +--- a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java ++++ b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +@@ -57,6 +57,13 @@ public class CraftBlockProjectileSource implements BlockProjectileSource { + + @Override + public T launchProjectile(Class projectile, Vector velocity) { ++ // Paper start - launchProjectile consumer ++ return this.launchProjectile(projectile, velocity, null); ++ } ++ ++ @Override ++ public T launchProjectile(Class projectile, Vector velocity, org.bukkit.util.Consumer function) { ++ // Paper end - launchProjectile consumer + Validate.isTrue(this.getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser"); + // Copied from BlockDispenser.dispense() + BlockSourceImpl isourceblock = new BlockSourceImpl((ServerLevel) this.dispenserBlock.getLevel(), this.dispenserBlock.getBlockPos()); +@@ -147,6 +154,11 @@ public class CraftBlockProjectileSource implements BlockProjectileSource { + if (velocity != null) { + ((T) launch.getBukkitEntity()).setVelocity(velocity); + } ++ // Paper start ++ if (function != null) { ++ function.accept((T) launch.getBukkitEntity()); ++ } ++ // Paper end + + world.addFreshEntity(launch); + return (T) launch.getBukkitEntity();