From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ben Kerllenevich <me@notom3ga.me>
Date: Thu, 18 Mar 2021 12:25:29 -0400
Subject: [PATCH] Allow infinity on crossbows


diff --git a/src/main/java/net/minecraft/world/item/ItemCrossbow.java b/src/main/java/net/minecraft/world/item/ItemCrossbow.java
index 4e1e819c8535e8a6b9aa5f76afe568ea171b939f..9cf76f8297c2a44c1df8ce2c4f0813802883a18b 100644
--- a/src/main/java/net/minecraft/world/item/ItemCrossbow.java
+++ b/src/main/java/net/minecraft/world/item/ItemCrossbow.java
@@ -94,7 +94,7 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable
     private static boolean a(EntityLiving entityliving, ItemStack itemstack, boolean consume) { // Paper - add consume
         int i = EnchantmentManager.getEnchantmentLevel(Enchantments.MULTISHOT, itemstack);
         int j = i == 0 ? 1 : 3;
-        boolean flag = !consume || entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild; // Paper - add consme
+        boolean flag = !consume || entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild || (net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentManager.getEnchantmentLevel(Enchantments.ARROW_INFINITE, itemstack) > 0); // Paper - add consme // Purpur
         ItemStack itemstack1 = entityliving.f(itemstack);
         ItemStack itemstack2 = itemstack1.cloneItemStack();
 
@@ -285,7 +285,7 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable
 
         for (int i = 0; i < list.size(); ++i) {
             ItemStack itemstack1 = (ItemStack) list.get(i);
-            boolean flag = entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild;
+            boolean flag = entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild || (net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentManager.getEnchantmentLevel(Enchantments.ARROW_INFINITE, itemstack) > 0); // Purpur
 
             if (!itemstack1.isEmpty()) {
                 if (i == 0) {
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentInfiniteArrows.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentInfiniteArrows.java
index 29bebbccf8dd6ff8976d1bfdb4c2ddcfc9de57dc..07980bf0735aab4aaa379b68d6d9b1dc494a0bab 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentInfiniteArrows.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentInfiniteArrows.java
@@ -5,7 +5,7 @@ import net.minecraft.world.entity.EnumItemSlot;
 public class EnchantmentInfiniteArrows extends Enchantment {
 
     public EnchantmentInfiniteArrows(Enchantment.Rarity enchantment_rarity, EnumItemSlot... aenumitemslot) {
-        super(enchantment_rarity, EnchantmentSlotType.BOW, aenumitemslot);
+        super(enchantment_rarity, net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity ? EnchantmentSlotType.BOW_AND_CROSSBOW : EnchantmentSlotType.BOW, aenumitemslot); // Purpur
     }
 
     @Override
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentSlotType.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentSlotType.java
index cf41863bc8b0be9f2a73ca2dd02a4d414d4f230e..2b75432d74df4f627d08d32c6553bd1a4ecd4a3d 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentSlotType.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentSlotType.java
@@ -96,9 +96,17 @@ public enum EnchantmentSlotType {
     VANISHABLE {
         @Override
         public boolean canEnchant(Item item) {
-            return item instanceof ItemVanishable || Block.asBlock(item) instanceof ItemVanishable || null.BREAKABLE.canEnchant(item);
+            return item instanceof ItemVanishable || Block.asBlock(item) instanceof ItemVanishable || BREAKABLE.canEnchant(item); // Purpur - decompile fix
+        }
+    // Purpur start
+    },
+    BOW_AND_CROSSBOW {
+        @Override
+        public boolean canEnchant(Item item) {
+            return item instanceof ItemBow || item instanceof ItemCrossbow;
         }
     };
+    // Purpur end
 
     private EnchantmentSlotType() {}
 
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 70ac948a91c1d4f9cffeac982c505cd1c3908cd3..844f5d7fee4ea06a5761e8fb6d54357d58bff8f5 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -231,6 +231,7 @@ public class PurpurConfig {
     }
 
     public static boolean allowInfinityMending = false;
+    public static boolean allowCrossbowInfinity = false;
     private static void enchantmentSettings() {
         if (version < 5) {
             boolean oldValue = getBoolean("settings.enchantment.allow-infinite-and-mending-together", false);
@@ -238,6 +239,7 @@ public class PurpurConfig {
             set("settings.enchantment.allow-infinite-and-mending-together", null);
         }
         allowInfinityMending = getBoolean("settings.enchantment.allow-infinity-and-mending-together", allowInfinityMending);
+        allowCrossbowInfinity = getBoolean("settings.enchantment.allow-infinity-on-crossbow", allowCrossbowInfinity);
     }
 
     public static boolean endermanShortHeight = false;
