From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sun, 25 Aug 2019 00:09:52 -0500
Subject: [PATCH] Dispenser curse of binding protection


diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index b0ac198041a319d33fa65398c1564dfa57aaf8e1..8e5c1ee1023a76f7619ffc0cdc3940582da81509 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -62,6 +62,7 @@ import net.minecraft.world.item.ProjectileWeaponItem;
 import net.minecraft.world.item.SpawnEggItem;
 import net.minecraft.world.item.SwordItem;
 import net.minecraft.world.item.enchantment.EnchantmentHelper;
+import net.minecraft.world.item.enchantment.Enchantments;
 import net.minecraft.world.level.BlockGetter;
 import net.minecraft.world.level.GameRules;
 import net.minecraft.world.level.ItemLike;
@@ -1077,6 +1078,12 @@ public abstract class Mob extends LivingEntity {
 
     }
 
+    // Purpur start
+    public static @Nullable EquipmentSlot getSlotForDispenser(ItemStack itemstack) {
+        return EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BINDING_CURSE, itemstack) > 0 ? null : getEquipmentSlotForItem(itemstack);
+    }
+    // Purpur end
+
     @Nullable
     public static Item getEquipmentForSlot(EquipmentSlot equipmentSlot, int equipmentLevel) {
         switch (equipmentSlot) {
diff --git a/src/main/java/net/minecraft/world/item/ArmorItem.java b/src/main/java/net/minecraft/world/item/ArmorItem.java
index aab4a63e61aced51b1b6c885fd8b8426a4f14408..dba3b8e0671ee63ff077155a8964f3e245740e7e 100644
--- a/src/main/java/net/minecraft/world/item/ArmorItem.java
+++ b/src/main/java/net/minecraft/world/item/ArmorItem.java
@@ -56,7 +56,7 @@ public class ArmorItem extends Item implements Wearable {
             return false;
         } else {
             LivingEntity entityliving = (LivingEntity) list.get(0);
-            EquipmentSlot enumitemslot = Mob.getEquipmentSlotForItem(armor);
+            EquipmentSlot enumitemslot = pointer.getLevel().purpurConfig.dispenserApplyCursedArmor ? Mob.getEquipmentSlotForItem(armor) : Mob.getSlotForDispenser(armor); if (enumitemslot == null) return false; // Purpur
             ItemStack itemstack1 = armor.split(1);
             // CraftBukkit start
             Level world = pointer.getLevel();
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 313d977209b9cb972207cf2d4f63b5d4aadc7227..ee53de5106cc9f3caef95e13d85d4cbd89982012 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -224,6 +224,11 @@ public class PurpurWorldConfig {
         voidDamageDealt = getDouble("gameplay-mechanics.void-damage-dealt", voidDamageDealt);
     }
 
+    public boolean dispenserApplyCursedArmor = true;
+    private void dispenserSettings() {
+        dispenserApplyCursedArmor = getBoolean("blocks.dispenser.apply-cursed-to-armor-slots", dispenserApplyCursedArmor);
+    }
+
     public boolean farmlandGetsMoistFromBelow = false;
     private void farmlandSettings() {
         farmlandGetsMoistFromBelow = getBoolean("blocks.farmland.gets-moist-from-below", farmlandGetsMoistFromBelow);
