3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/patches/server/0536-Add-EntityLoadCrossbowEvent.patch

43 Zeilen
2.7 KiB
Diff

2021-06-14 20:50:22 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Wed, 7 Oct 2020 12:04:01 -0400
Subject: [PATCH] Add EntityLoadCrossbowEvent
diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java
2022-12-07 21:16:54 +01:00
index 48626d564c9fb4630b51858edd124b56af2d7ca0..caa5f5f5d58b8ddbca0910412b695cb810570623 100644
2021-06-14 20:50:22 +02:00
--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java
+++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java
2022-06-08 09:30:41 +02:00
@@ -88,7 +88,14 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
2021-06-14 20:50:22 +02:00
int j = this.getUseDuration(stack) - remainingUseTicks;
float f = CrossbowItem.getPowerForTime(j, stack);
- if (f >= 1.0F && !CrossbowItem.isCharged(stack) && CrossbowItem.tryLoadProjectiles(user, stack)) {
+ // 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())) {
+ if (user instanceof ServerPlayer player) player.containerMenu.sendAllDataToRemote();
+ return;
+ }
2021-06-14 20:50:22 +02:00
+ // Paper end
CrossbowItem.setCharged(stack, true);
SoundSource soundcategory = user instanceof Player ? SoundSource.PLAYERS : SoundSource.HOSTILE;
2022-06-08 09:30:41 +02:00
@@ -98,9 +105,14 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
2021-06-14 20:50:22 +02:00
}
private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack projectile) {
+ // Paper start
+ return CrossbowItem.tryLoadProjectiles(shooter, projectile, true);
+ }
+ private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack projectile, boolean consume) {
+ // Paper end
int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, projectile);
int j = i == 0 ? 1 : 3;
- boolean flag = shooter instanceof Player && ((Player) shooter).getAbilities().instabuild;
+ boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild; // Paper - add consume
2021-06-14 20:50:22 +02:00
ItemStack itemstack1 = shooter.getProjectile(projectile);
ItemStack itemstack2 = itemstack1.copy();