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
|
2023-08-17 22:51:34 +02:00
|
|
|
index ba570f1c9654e1004e068a1efe2118f36c954505..eede02c3f125d230af537bb67bebed9b88f7d1b4 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
|
2023-03-14 21:25:13 +01:00
|
|
|
@@ -89,7 +89,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);
|
2021-12-31 07:54:23 +01:00
|
|
|
+ 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;
|
|
|
|
|
2023-06-08 01:56:33 +02:00
|
|
|
@@ -98,10 +105,16 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
|
|
|
|
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
2023-06-08 01:56:33 +02:00
|
|
|
+ @io.papermc.paper.annotation.DoNotUse // Paper
|
|
|
|
private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbow) {
|
2021-06-14 20:50:22 +02:00
|
|
|
+ // Paper start
|
2023-06-08 01:56:33 +02:00
|
|
|
+ return CrossbowItem.tryLoadProjectiles(shooter, crossbow, true);
|
2021-06-14 20:50:22 +02:00
|
|
|
+ }
|
2023-06-08 01:56:33 +02:00
|
|
|
+ private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbow, boolean consume) {
|
2021-06-14 20:50:22 +02:00
|
|
|
+ // Paper end
|
2023-06-08 01:56:33 +02:00
|
|
|
int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, crossbow);
|
2021-06-14 20:50:22 +02:00
|
|
|
int j = i == 0 ? 1 : 3;
|
|
|
|
- boolean flag = shooter instanceof Player && ((Player) shooter).getAbilities().instabuild;
|
2021-06-21 16:36:53 +02:00
|
|
|
+ boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild; // Paper - add consume
|
2023-06-08 01:56:33 +02:00
|
|
|
ItemStack itemstack1 = shooter.getProjectile(crossbow);
|
2021-06-14 20:50:22 +02:00
|
|
|
ItemStack itemstack2 = itemstack1.copy();
|
|
|
|
|