Skip to content

Fix cancelled Projectile Events still consuming arrows#12124

Open
notTamion wants to merge 1 commit into
PaperMC:mainfrom
notTamion:fix-projectile-cancel
Open

Fix cancelled Projectile Events still consuming arrows#12124
notTamion wants to merge 1 commit into
PaperMC:mainfrom
notTamion:fix-projectile-cancel

Conversation

@notTamion
Copy link
Copy Markdown
Contributor

@notTamion notTamion commented Feb 16, 2025

fixes #12123
pr hardfork #9949

draft pr for now. need to come back to this

@notTamion notTamion force-pushed the fix-projectile-cancel branch 2 times, most recently from 55cf4ae to cf243d4 Compare February 22, 2025 09:02
@notTamion
Copy link
Copy Markdown
Contributor Author

should generally be ready for review now. one thing to note is that crossbows now remove items one by one from their charged projectiles, that way plugins can choose to fire only certain projectiles and have the other ones remain charged

@notTamion notTamion marked this pull request as ready for review February 22, 2025 09:03
@notTamion notTamion requested a review from a team as a code owner February 22, 2025 09:03
@notTamion notTamion force-pushed the fix-projectile-cancel branch from c0fc596 to f1c6435 Compare April 13, 2025 08:03
@davidmayr
Copy link
Copy Markdown
Contributor

Shouldn't setConsumeItem be updated in the API? It's currently deprecated and marked as "not currently functional"

Also, is the state of this PR stable enough to apply these patches to a server for production use? Or does this still require more work? Thanks

+ if (weapon.is(net.minecraft.world.item.Items.CROSSBOW)) {
+ List<ItemStack> newProjectiles = new java.util.ArrayList<>(weapon.get(DataComponents.CHARGED_PROJECTILES).getItems());
+ newProjectiles.remove(i - (projectileItems.size() - newProjectiles.size()));
+ weapon.set(DataComponents.CHARGED_PROJECTILES, net.minecraft.world.item.component.ChargedProjectiles.of(newProjectiles));
Copy link
Copy Markdown
Contributor

@Dreeam-qwq Dreeam-qwq Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set call of crossbow should change like this

weapon = shooter.getItemInHand(hand);
if (weapon.is(Items.CROSSBOW)) {
    ...
    weapon.set(DataComponents.CHARGED_PROJECTILES, net.minecraft.world.item.component.ChargedProjectiles.of(newProjectiles));

Since plugin can change player inventory's item during this stage, and set data to weapon can not update actual item data properly. So it needs to update item reference to the actual crossbow on hand.

See Winds-Studio/Leaf@fe444c4...802fed0 for reference.

@github-project-automation github-project-automation Bot moved this from Awaiting review to Changes required in Paper PR Queue Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Changes required

Development

Successfully merging this pull request may close these issues.

Cancelled EntityShootBowEvents/ProjectileLaunchEvents still consume arrows

3 participants