From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Encode42 <me@encode42.dev>
Date: Mon, 28 Jun 2021 15:32:57 -0400
Subject: [PATCH] Armor click equip options


diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index dd5bc68171ce5a67ecf30de65f0c1d280cc88419..38323c95dc36e5ead294670ce120114492de37d5 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -499,7 +499,7 @@ public class ServerPlayerGameMode {
                 return interactionresultwrapper.getResult();
             } else {
                 player.setItemInHand(hand, itemstack1);
-                if (this.isCreative()) {
+                if (this.isCreative() && itemstack1 != ItemStack.EMPTY) { // Purpur
                     itemstack1.setCount(i);
                     if (itemstack1.isDamageableItem() && itemstack1.getDamageValue() != j) {
                         itemstack1.setDamageValue(j);
diff --git a/src/main/java/net/minecraft/world/item/ArmorItem.java b/src/main/java/net/minecraft/world/item/ArmorItem.java
index dba3b8e0671ee63ff077155a8964f3e245740e7e..747bc81aef6e9e8a6d3b4384e30f7e97feefdc6a 100644
--- a/src/main/java/net/minecraft/world/item/ArmorItem.java
+++ b/src/main/java/net/minecraft/world/item/ArmorItem.java
@@ -146,7 +146,14 @@ public class ArmorItem extends Item implements Wearable {
             }
 
             itemstack.setCount(0);
-            return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
+            // Purpur start
+            return InteractionResultHolder.success(world.purpurConfig.playerArmorSwappingCreativeMakesCopy ? itemstack : ItemStack.EMPTY);
+        } else if (world.purpurConfig.playerArmorSwapping && !net.minecraft.world.item.enchantment.EnchantmentHelper.hasBindingCurse(itemstack1)) {
+            user.setItemSlot(enumitemslot, itemstack);
+            user.awardStat(Stats.ITEM_USED.get(this));
+            user.level.playSound(null, user.getX(), user.getY(), user.getZ(), itemstack.getEquipSound(), net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F); // we have to force the sound, for whatever reason
+            return InteractionResultHolder.success(itemstack1);
+            // Purpur end
         } else {
             return InteractionResultHolder.fail(itemstack);
         }
diff --git a/src/main/java/net/minecraft/world/item/ElytraItem.java b/src/main/java/net/minecraft/world/item/ElytraItem.java
index 42f79d418ec4e2dbeac9a217d9dc144cda2ef714..250c0e31825f772d3fee7a523f150cb25e8ae558 100644
--- a/src/main/java/net/minecraft/world/item/ElytraItem.java
+++ b/src/main/java/net/minecraft/world/item/ElytraItem.java
@@ -39,7 +39,14 @@ public class ElytraItem extends Item implements Wearable {
             }
 
             itemStack.setCount(0);
-            return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
+            // Purpur start
+            return InteractionResultHolder.success(world.purpurConfig.playerArmorSwappingCreativeMakesCopy ? itemStack : ItemStack.EMPTY);
+        } else if (world.purpurConfig.playerArmorSwapping) {
+            user.setItemSlot(equipmentSlot, itemStack);
+            user.awardStat(Stats.ITEM_USED.get(this));
+            user.level.playSound(null, user.getX(), user.getY(), user.getZ(), itemStack.getEquipSound(), net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F); // we have to force the sound, for whatever reason
+            return InteractionResultHolder.success(itemStack2);
+            // Purpur end
         } else {
             return InteractionResultHolder.fail(itemStack);
         }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 093340d3871ec3db4271d5c33e53edef04d7ce03..2ba590032d6d7c5278cc2bf5774be2c278e99fc0 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -344,6 +344,8 @@ public class PurpurWorldConfig {
     public boolean playersSkipNight = true;
     public double playerCriticalDamageMultiplier = 1.5D;
     public boolean playerBurpWhenFull = false;
+    public boolean playerArmorSwapping = false;
+    public boolean playerArmorSwappingCreativeMakesCopy = true;
     private void playerSettings() {
         idleTimeoutKick = getBoolean("gameplay-mechanics.player.idle-timeout.kick-if-idle", idleTimeoutKick);
         idleTimeoutTickNearbyEntities = getBoolean("gameplay-mechanics.player.idle-timeout.tick-nearby-entities", idleTimeoutTickNearbyEntities);
@@ -362,6 +364,8 @@ public class PurpurWorldConfig {
         playersSkipNight = getBoolean("gameplay-mechanics.player.can-skip-night", playersSkipNight);
         playerCriticalDamageMultiplier = getDouble("gameplay-mechanics.player.critical-damage-multiplier", playerCriticalDamageMultiplier);
         playerBurpWhenFull = getBoolean("gameplay-mechanics.player.burp-when-full", playerBurpWhenFull);
+        playerArmorSwapping = getBoolean("gameplay-mechanics.player.armor-click-equip.allow-hot-swapping", playerArmorSwapping);
+        playerArmorSwappingCreativeMakesCopy = getBoolean("gameplay-mechanics.player.armor-click-equip.creative-makes-copy", playerArmorSwappingCreativeMakesCopy);
     }
 
     public int snowballDamage = -1;
