Skip to content

Commit 44b70a8

Browse files
committed
fix #90
1 parent 98ee84a commit 44b70a8

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/main/java/lol/hyper/toolstats/events/ShootBow.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ public void onShoot(EntityShootBowEvent event) {
5656
return;
5757
}
5858

59-
PlayerInventory inventory = player.getInventory();
60-
ItemStack heldBow = getBow(inventory);
61-
62-
// player swapped
59+
ItemStack heldBow = getBow(player.getInventory());
60+
// player swapped or we can't get the bow
6361
if (heldBow == null) {
6462
return;
6563
}
@@ -68,22 +66,23 @@ public void onShoot(EntityShootBowEvent event) {
6866
}
6967

7068
private static @Nullable ItemStack getBow(PlayerInventory inventory) {
71-
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
72-
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
73-
ItemStack heldBow = null;
74-
if (isMainHand) {
75-
heldBow = inventory.getItemInMainHand();
69+
ItemStack main = inventory.getItemInMainHand();
70+
ItemStack offHand = inventory.getItemInOffHand();
71+
72+
boolean isMain = main.getType() == Material.BOW || main.getType() == Material.CROSSBOW;
73+
boolean isOffHand = offHand.getType() == Material.BOW || offHand.getType() == Material.CROSSBOW;
74+
75+
// if the player is holding a bow in their main hand, use that one
76+
// if the bow is in their offhand instead, use that one after checking main hand
77+
// Minecraft prioritizes main hand if the player holds in both hands
78+
if (isMain) {
79+
return main;
7680
}
7781
if (isOffHand) {
78-
heldBow = inventory.getItemInOffHand();
82+
return offHand;
7983
}
8084

81-
// if the player is holding a bow in both hands
82-
// default to main hand since that takes priority
83-
if (isMainHand && isOffHand) {
84-
heldBow = inventory.getItemInMainHand();
85-
}
86-
return heldBow;
85+
return null;
8786
}
8887

8988
private void updateArrowsShot(ItemStack bow) {

0 commit comments

Comments
 (0)