From d2239c40a5176c78d94bfdd1b0a85e2fa33649a3 Mon Sep 17 00:00:00 2001 From: Melncat <37024464+MelnCat@users.noreply.github.com> Date: Mon, 19 Sep 2022 17:03:59 -0700 Subject: [PATCH] Add a consumer parameter to ProjectileSource#launchProjectile (#8374) Co-authored-by: MelnCat --- ...arameter-to-ProjectileSource-launchP.patch | 35 ++++++++++ ...arameter-to-ProjectileSource-launchP.patch | 69 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 patches/api/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch create mode 100644 patches/server/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch diff --git a/patches/api/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch b/patches/api/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch new file mode 100644 index 0000000000..ae16830f5b --- /dev/null +++ b/patches/api/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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/projectiles/ProjectileSource.java ++++ b/src/main/java/org/bukkit/projectiles/ProjectileSource.java +@@ -0,0 +0,0 @@ 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/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch b/patches/server/Add-a-consumer-parameter-to-ProjectileSource-launchP.patch new file mode 100644 index 0000000000..c1ab1466ec --- /dev/null +++ b/patches/server/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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +@@ -0,0 +0,0 @@ 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(); +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java ++++ b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +@@ -0,0 +0,0 @@ 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()); +@@ -0,0 +0,0 @@ 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();