This commit is contained in:
hyperdefined
2025-01-22 17:02:05 -05:00
parent 98ee84ad13
commit 44b70a8394

View File

@@ -56,10 +56,8 @@ public class ShootBow implements Listener {
return; return;
} }
PlayerInventory inventory = player.getInventory(); ItemStack heldBow = getBow(player.getInventory());
ItemStack heldBow = getBow(inventory); // player swapped or we can't get the bow
// player swapped
if (heldBow == null) { if (heldBow == null) {
return; return;
} }
@@ -68,22 +66,23 @@ public class ShootBow implements Listener {
} }
private static @Nullable ItemStack getBow(PlayerInventory inventory) { private static @Nullable ItemStack getBow(PlayerInventory inventory) {
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW; ItemStack main = inventory.getItemInMainHand();
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW; ItemStack offHand = inventory.getItemInOffHand();
ItemStack heldBow = null;
if (isMainHand) { boolean isMain = main.getType() == Material.BOW || main.getType() == Material.CROSSBOW;
heldBow = inventory.getItemInMainHand(); boolean isOffHand = offHand.getType() == Material.BOW || offHand.getType() == Material.CROSSBOW;
// if the player is holding a bow in their main hand, use that one
// if the bow is in their offhand instead, use that one after checking main hand
// Minecraft prioritizes main hand if the player holds in both hands
if (isMain) {
return main;
} }
if (isOffHand) { if (isOffHand) {
heldBow = inventory.getItemInOffHand(); return offHand;
} }
// if the player is holding a bow in both hands return null;
// default to main hand since that takes priority
if (isMainHand && isOffHand) {
heldBow = inventory.getItemInMainHand();
}
return heldBow;
} }
private void updateArrowsShot(ItemStack bow) { private void updateArrowsShot(ItemStack bow) {