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-06-13 01:51:45 +02:00
|
|
|
index 4590764ec62938e2b601f9f8339d5c4ea183e5e2..4cf07ff38df050defceb69335e402ca52972a05f 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-06-13 01:51:45 +02:00
|
|
|
@@ -496,8 +496,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")
|
|
|
|
+ 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();
|
2023-06-13 01:51:45 +02:00
|
|
|
@@ -580,6 +587,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-06-13 01:51:45 +02:00
|
|
|
index 18d6846d04268f0099a84b01a3a2790d7742d85e..40a1f138b610e336eb11f2ace4a0da5703295c6b 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
|
|
|
|
@@ -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
|
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()
|
|
|
|
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();
|