Fix EntityLoadCrossbowEvent Sync Issue (#5739)

This commit is contained in:
LemonCaramel 2021-12-31 15:54:23 +09:00
parent 04087a3e9a
commit 7426c0370e
2 changed files with 4 additions and 5 deletions

View file

@ -89,10 +89,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Set whether or not to cancel the crossbow being loaded. If canceled, the
+ * projectile that would be loaded into the crossbow will not be consumed.
+ *
+ * If set to false, and this event is pertaining to a player entity,
+ * it's recommended that a call to {@link Player#updateInventory()} is made
+ * as the client may think the server still loaded an item into the crossbow.
+ *
+ * @param cancel true if you wish to cancel this event
+ */
+ @Override

View file

@ -16,7 +16,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - EntityLoadCrossbowEvent
+ if (f >= 1.0F && !CrossbowItem.isCharged(stack) /*&& CrossbowItem.tryLoadProjectiles(entityliving, itemstack)*/) {
+ final io.papermc.paper.event.entity.EntityLoadCrossbowEvent event = new io.papermc.paper.event.entity.EntityLoadCrossbowEvent(user.getBukkitLivingEntity(), stack.asBukkitMirror(), user.getUsedItemHand() == InteractionHand.MAIN_HAND ? org.bukkit.inventory.EquipmentSlot.HAND : org.bukkit.inventory.EquipmentSlot.OFF_HAND);
+ if (!event.callEvent() || !tryLoadProjectiles(user, stack, event.shouldConsumeItem())) return;
+ if (!event.callEvent() || !tryLoadProjectiles(user, stack, event.shouldConsumeItem())) {
+ if (user instanceof ServerPlayer player) player.containerMenu.sendAllDataToRemote();
+ return;
+ }
+ // Paper end
CrossbowItem.setCharged(stack, true);
SoundSource soundcategory = user instanceof Player ? SoundSource.PLAYERS : SoundSource.HOSTILE;