diff --git a/paper-server/patches/sources/net/minecraft/world/entity/projectile/Projectile.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/projectile/Projectile.java.patch index fa08deb05c..23f65236b8 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/projectile/Projectile.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/projectile/Projectile.java.patch @@ -29,21 +29,48 @@ } -@@ -213,7 +221,7 @@ +@@ -211,11 +219,34 @@ + }); + } ++ // Paper start - delayed projectile spawning ++ public record Delayed( ++ T projectile, ++ ServerLevel world, ++ ItemStack projectileStack ++ ) { ++ // Taken from net.minecraft.world.entity.projectile.Projectile.spawnProjectile(T, net.minecraft.server.level.ServerLevel, net.minecraft.world.item.ItemStack, java.util.function.Consumer) ++ public boolean attemptSpawn() { ++ if (!world.addFreshEntity(projectile)) return false; ++ projectile.applyOnProjectileSpawned(this.world, this.projectileStack); ++ return true; ++ } ++ ++ public T spawn() { ++ this.attemptSpawn(); ++ return projectile(); ++ } ++ } ++ // Paper end - delayed projectile spawning ++ public static T spawnProjectile(T projectile, ServerLevel world, ItemStack projectileStack, Consumer beforeSpawn) { ++ // Paper start - delayed projectile spawning ++ return spawnProjectileDelayed(projectile, world, projectileStack, beforeSpawn).spawn(); ++ } ++ public static Delayed spawnProjectileDelayed(T projectile, ServerLevel world, ItemStack projectileStack, Consumer beforeSpawn) { ++ // Paper end - delayed projectile spawning beforeSpawn.accept(projectile); - world.addFreshEntity(projectile); -+ if (world.addFreshEntity(projectile)) // CraftBukkit - projectile.applyOnProjectileSpawned(world, projectileStack); - return projectile; +- projectile.applyOnProjectileSpawned(world, projectileStack); +- return projectile; ++ return new Delayed<>(projectile, world, projectileStack); // Paper - delayed projectile spawning + } + + public void applyOnProjectileSpawned(ServerLevel world, ItemStack projectileStack) { +@@ -232,6 +263,17 @@ + } -@@ -230,7 +238,18 @@ - } - } -+ } -+ + // CraftBukkit start - call projectile hit event + protected ProjectileDeflection preHitTargetOrDeflectSelf(HitResult movingobjectposition) { + org.bukkit.event.entity.ProjectileHitEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); @@ -52,12 +79,13 @@ + return this.hitTargetOrDeflectSelf(movingobjectposition); + } + return ProjectileDeflection.NONE; - } ++ } + // CraftBukkit end - ++ protected ProjectileDeflection hitTargetOrDeflectSelf(HitResult hitResult) { if (hitResult.getType() == HitResult.Type.ENTITY) { -@@ -309,6 +328,11 @@ + EntityHitResult movingobjectpositionentity = (EntityHitResult) hitResult; +@@ -309,6 +351,11 @@ protected void onHitEntity(EntityHitResult entityHitResult) {} protected void onHitBlock(BlockHitResult blockHitResult) { diff --git a/paper-server/patches/sources/net/minecraft/world/item/FireworkRocketItem.java.patch b/paper-server/patches/sources/net/minecraft/world/item/FireworkRocketItem.java.patch index d36c81e68f..09b7c81a1a 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/FireworkRocketItem.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/FireworkRocketItem.java.patch @@ -9,12 +9,26 @@ ); itemStack.shrink(1); } -@@ -56,7 +56,7 @@ +@@ -56,9 +56,19 @@ if (user.isFallFlying()) { ItemStack itemStack = user.getItemInHand(hand); if (world instanceof ServerLevel serverLevel) { - Projectile.spawnProjectile(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack); -+ Projectile.spawnProjectile(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack, f -> f.spawningEntity = user.getUUID()); // Paper - firework api - assign spawning entity uuid - itemStack.consume(1, user); - user.awardStat(Stats.ITEM_USED.get(this)); +- itemStack.consume(1, user); +- user.awardStat(Stats.ITEM_USED.get(this)); ++ // Paper start - PlayerElytraBoostEvent ++ final Projectile.Delayed delayed = Projectile.spawnProjectileDelayed(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack, f -> f.spawningEntity = user.getUUID()); // Paper - firework api - assign spawning entity uuid ++ com.destroystokyo.paper.event.player.PlayerElytraBoostEvent event = new com.destroystokyo.paper.event.player.PlayerElytraBoostEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) delayed.projectile().getBukkitEntity(), org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand)); ++ if (event.callEvent() && delayed.attemptSpawn()) { ++ user.awardStat(Stats.ITEM_USED.get(this)); // Moved up from below ++ if (event.shouldConsume() && !user.hasInfiniteMaterials()) { ++ itemStack.shrink(1); // Moved up from below ++ } else ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); ++ } else { ++ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); ++ } ++ // Moved up consume/stat ++ // Paper end - PlayerElytraBoostEvent } + + return InteractionResult.SUCCESS;