Fix cancelled Projectile Events still consuming arrows#12124
Conversation
55cf4ae to
cf243d4
Compare
|
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 |
c0fc596 to
f1c6435
Compare
|
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)); |
There was a problem hiding this comment.
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.
fixes #12123
pr hardfork #9949
draft pr for now. need to come back to this