2022-09-20 02:03:59 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: MelnCat <melncatuwu@gmail.com>
|
|
|
|
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
|
2023-11-26 00:03:02 +01:00
|
|
|
index 0faed04c7794dd4fd758a151d15ad5956e4f4907..c9396a55fddba47124ad5aebe7f816d99a03659c 100644
|
2022-09-20 02:03:59 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2023-07-04 10:22:56 +02:00
|
|
|
@@ -509,8 +509,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2022-09-20 02:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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")
|
2023-11-26 00:03:02 +01:00
|
|
|
+ public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity, java.util.function.Consumer<? super T> function) {
|
2022-09-20 02:03:59 +02:00
|
|
|
+ // Paper end - launchProjectile consumer
|
|
|
|
Preconditions.checkState(!this.getHandle().generation, "Cannot launch projectile during world generation");
|
|
|
|
|
2023-10-27 01:34:58 +02:00
|
|
|
net.minecraft.world.level.Level world = ((CraftWorld) this.getWorld()).getHandle();
|
2023-07-04 10:22:56 +02:00
|
|
|
@@ -593,6 +600,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2022-09-20 02:03:59 +02:00
|
|
|
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
|
2023-11-26 00:03:02 +01:00
|
|
|
index 7f9a716ea65f98d1c8487438949f1d5bc8becc4a..ab684fc1b09d4eade7dd11a95065e72b842a3667 100644
|
2022-09-20 02:03:59 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java
|
2023-09-22 17:35:51 +02:00
|
|
|
@@ -56,6 +56,13 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
|
2022-09-20 02:03:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
|
|
|
|
+ // Paper start - launchProjectile consumer
|
|
|
|
+ return this.launchProjectile(projectile, velocity, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2023-11-26 00:03:02 +01:00
|
|
|
+ public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity, java.util.function.Consumer<? super T> function) {
|
2022-09-20 02:03:59 +02:00
|
|
|
+ // Paper end - launchProjectile consumer
|
2023-06-13 01:51:45 +02:00
|
|
|
Preconditions.checkArgument(this.getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
|
2022-09-20 02:03:59 +02:00
|
|
|
// Copied from BlockDispenser.dispense()
|
2023-09-22 17:35:51 +02:00
|
|
|
BlockSource sourceblock = new BlockSource((ServerLevel) this.dispenserBlock.getLevel(), this.dispenserBlock.getBlockPos(), this.dispenserBlock.getBlockState(), this.dispenserBlock);
|
|
|
|
@@ -146,6 +153,11 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
|
2022-09-20 02:03:59 +02:00
|
|
|
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();
|