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-04-24 23:23:56 +02:00
|
|
|
index 6344ab27c113dd42c729e0b05b957670c4930722..bf58fb8acd09723cbc55f6ac41c24cccda97bac8 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-04-24 23:23:56 +02:00
|
|
|
@@ -561,8 +561,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-04-24 23:23:56 +02:00
|
|
|
@@ -649,6 +656,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-12-25 23:51:56 +01:00
|
|
|
index faab60e735aca230cb4c0b7db21e6a9a237daf6e..89401fc942c151941790b1152a35357aa51fcdba 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-12-25 23:51:56 +01:00
|
|
|
@@ -55,6 +55,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);
|
2023-12-25 23:51:56 +01:00
|
|
|
@@ -145,6 +152,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();
|