Skip to content

Commit 18fa8a3

Browse files
Merge pull request #48 from Leo40Git/fix-armor-swap
Fix "Quick Armor Swap" crash with non-armor items
2 parents f4deda6 + 9df4dd0 commit 18fa8a3

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

  • src/main/java/me/juancarloscp52/bedrockify/client/features/quickArmorSwap

src/main/java/me/juancarloscp52/bedrockify/client/features/quickArmorSwap/ArmorReplacer.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616
public class ArmorReplacer {
1717

1818
public static TypedActionResult<ItemStack> tryChangeArmor(PlayerEntity playerEntity, Hand hand){
19-
ClientPlayerInteractionManager interactionManager = MinecraftClient.getInstance().interactionManager;
20-
if(MinecraftClient.getInstance().mouse.wasRightButtonClicked()){
21-
ItemStack newArmor = playerEntity.getStackInHand(hand);
22-
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(newArmor);
19+
ItemStack newArmor = playerEntity.getStackInHand(hand);
20+
if (newArmor.getItem() == Items.ELYTRA || newArmor.getItem() instanceof ArmorItem){
21+
ClientPlayerInteractionManager interactionManager = MinecraftClient.getInstance().interactionManager;
22+
if(interactionManager != null && MinecraftClient.getInstance().mouse.wasRightButtonClicked()){
23+
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(newArmor);
2324

24-
if(playerEntity.getEquippedStack(equipmentSlot).getItem().equals(Items.AIR))
25-
return TypedActionResult.pass(playerEntity.getStackInHand(hand));
26-
27-
int slotIndex = 8-equipmentSlot.getEntitySlotId();
28-
interactionManager.clickSlot(playerEntity.playerScreenHandler.syncId,slotIndex,playerEntity.inventory.main.indexOf(newArmor), SlotActionType.SWAP,playerEntity);
29-
playerEntity.playSound(newArmor.getItem() == Items.ELYTRA ? SoundEvents.ITEM_ARMOR_EQUIP_ELYTRA : ((ArmorItem)newArmor.getItem()).getMaterial().getEquipSound(), 1.0F,1.0F);
30-
return TypedActionResult.success(playerEntity.getStackInHand(hand));
25+
if(!playerEntity.getEquippedStack(equipmentSlot).getItem().equals(Items.AIR)){
26+
int slotIndex = 8-equipmentSlot.getEntitySlotId();
27+
interactionManager.clickSlot(playerEntity.playerScreenHandler.syncId,slotIndex,playerEntity.inventory.main.indexOf(newArmor), SlotActionType.SWAP,playerEntity);
28+
playerEntity.playSound(newArmor.getItem() == Items.ELYTRA ? SoundEvents.ITEM_ARMOR_EQUIP_ELYTRA : ((ArmorItem)newArmor.getItem()).getMaterial().getEquipSound(), 1.0F,1.0F);
29+
return TypedActionResult.success(playerEntity.getStackInHand(hand));
30+
}
31+
}
3132
}
32-
return TypedActionResult.fail(playerEntity.getStackInHand(hand));
33+
return TypedActionResult.pass(newArmor);
3334
}
3435

3536
}

0 commit comments

Comments
 (0)