@@ -17,20 +17,22 @@ public class ArmorReplacer {
1717
1818 public static TypedActionResult <ItemStack > tryChangeArmor (PlayerEntity playerEntity , Hand hand ){
1919 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 );
20+ ClientPlayerInteractionManager interactionManager = MinecraftClient . getInstance (). interactionManager ;
21+ if ( interactionManager != null && MinecraftClient .getInstance ().mouse . wasRightButtonClicked ()){
22+ if (!( newArmor . getItem () == Items . ELYTRA || newArmor . getItem () instanceof ArmorItem ))
23+ return TypedActionResult . pass (newArmor );
2424
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- }
25+ EquipmentSlot equipmentSlot = MobEntity .getPreferredEquipmentSlot (newArmor );
26+
27+ if (playerEntity .getEquippedStack (equipmentSlot ).getItem ().equals (Items .AIR ))
28+ return TypedActionResult .pass (newArmor );
29+
30+ int slotIndex = 8 -equipmentSlot .getEntitySlotId ();
31+ interactionManager .clickSlot (playerEntity .playerScreenHandler .syncId ,slotIndex ,playerEntity .inventory .main .indexOf (newArmor ), SlotActionType .SWAP ,playerEntity );
32+ playerEntity .playSound (newArmor .getItem () == Items .ELYTRA ? SoundEvents .ITEM_ARMOR_EQUIP_ELYTRA : ((ArmorItem )newArmor .getItem ()).getMaterial ().getEquipSound (), 1.0F ,1.0F );
33+ return TypedActionResult .success (playerEntity .getStackInHand (hand ));
3234 }
33- return TypedActionResult .pass (newArmor );
35+ return TypedActionResult .fail (newArmor );
3436 }
3537
3638}
0 commit comments