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
|
2024-06-23 23:37:20 +02:00
|
|
|
index 34276233751a41b41ee6af99afa97ef7d4bca836..f278346bb5fe816f3c559a02692b125dde0446f4 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
|
2024-06-14 03:30:23 +02:00
|
|
|
@@ -569,8 +569,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();
|
2024-06-21 20:06:31 +02:00
|
|
|
@@ -659,6 +666,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
|
2024-06-14 03:30:23 +02:00
|
|
|
index 8b57044518fbb0fd507da6ae3ff12b99eff70b37..2a6c4a74ff065110bb09b528f2d5f80b560a587a 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
|
2024-06-14 03:30:23 +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);
|
2024-06-14 03:30:23 +02:00
|
|
|
@@ -140,6 +147,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();
|