|
16 | 16 | public class ArmorReplacer { |
17 | 17 |
|
18 | 18 | 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); |
23 | 24 |
|
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 | + } |
31 | 32 | } |
32 | | - return TypedActionResult.fail(playerEntity.getStackInHand(hand)); |
| 33 | + return TypedActionResult.pass(newArmor); |
33 | 34 | } |
34 | 35 |
|
35 | 36 | } |
0 commit comments