diff options
author | Melncat <[email protected]> | 2022-09-19 17:03:59 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-20 01:03:59 +0100 |
commit | ea777c345b301a758c561e64d9ba29852e8097db (patch) | |
tree | 5deea043803d8d0feebe637dc5d615d9e8404e3d | |
parent | 63cb7472acb69d5a53bb806408d692e4df17cc32 (diff) | |
download | Paper-ea777c345b301a758c561e64d9ba29852e8097db.tar.gz Paper-ea777c345b301a758c561e64d9ba29852e8097db.zip |
Add a consumer parameter to ProjectileSource#launchProjectile (#8374)
Co-authored-by: MelnCat <[email protected]>
-rw-r--r-- | patches/api/0394-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch | 35 | ||||
-rw-r--r-- | patches/server/0943-Add-a-consumer-parameter-to-ProjectileSource-launchP.patch | 69 |
2 files changed, 104 insertions, 0 deletions
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 <[email protected]> +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 extends Projectile> T launchProjectile(@NotNull Class<? extends T> 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. ++ * <br> ++ * 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 <T> 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 extends Projectile> T launchProjectile(@NotNull Class<? extends T> projectile, @Nullable Vector velocity, @Nullable org.bukkit.util.Consumer<T> 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 <[email protected]> +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 extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) { ++ // Paper start - launchProjectile consumer ++ return this.launchProjectile(projectile, velocity, null); ++ } ++ ++ @Override ++ @SuppressWarnings("unchecked") ++ public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity, org.bukkit.util.Consumer<T> 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 extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) { ++ // Paper start - launchProjectile consumer ++ return this.launchProjectile(projectile, velocity, null); ++ } ++ ++ @Override ++ public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity, org.bukkit.util.Consumer<T> 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(); |