From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ben Kerllenevich <ben@omega24.dev>
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/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java
index 77562d7c7248835532f2d9582cce6ef6725a12a6..264542304babba94e364811da8d7b51b812a2b47 100644
--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java
+++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java
@@ -111,7 +111,7 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
         // Paper end
         int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, projectile);
         int j = i == 0 ? 1 : 3;
-        boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild; // Paper - add consume
+        boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild || (net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, projectile) > 0); // Paper - add consume // Purpur
         ItemStack itemstack1 = shooter.getProjectile(projectile);
         ItemStack itemstack2 = itemstack1.copy();
 
@@ -302,7 +302,7 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
 
         for (int i = 0; i < list.size(); ++i) {
             ItemStack itemstack1 = (ItemStack) list.get(i);
-            boolean flag = entity instanceof Player && ((Player) entity).getAbilities().instabuild;
+            boolean flag = entity instanceof Player && ((Player) entity).getAbilities().instabuild || (net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0); // Purpur
 
             if (!itemstack1.isEmpty()) {
                 if (i == 0) {
diff --git a/src/main/java/net/minecraft/world/item/enchantment/ArrowInfiniteEnchantment.java b/src/main/java/net/minecraft/world/item/enchantment/ArrowInfiniteEnchantment.java
index 6763d0b96c83d1b462999f525bf1f31c30cf705f..bfd7b1d1965cf9da5234c7835affa4e97a6e4bb0 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/ArrowInfiniteEnchantment.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/ArrowInfiniteEnchantment.java
@@ -4,7 +4,7 @@ import net.minecraft.world.entity.EquipmentSlot;
 
 public class ArrowInfiniteEnchantment extends Enchantment {
     public ArrowInfiniteEnchantment(Enchantment.Rarity weight, EquipmentSlot... slotTypes) {
-        super(weight, EnchantmentCategory.BOW, slotTypes);
+        super(weight, net.pl3x.purpur.PurpurConfig.allowCrossbowInfinity ? EnchantmentCategory.BOW_AND_CROSSBOW : EnchantmentCategory.BOW, slotTypes); // Purpur
     }
 
     @Override
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
index 6f6106ca4d74d50a7b74b086adc96c58c7906cb6..d6417c1e77ac8823e18a179dc9f61757a1f339ad 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
@@ -97,6 +97,14 @@ public enum EnchantmentCategory {
         public boolean canEnchant(Item item) {
             return item instanceof Vanishable || Block.byItem(item) instanceof Vanishable || BREAKABLE.canEnchant(item);
         }
+    // Purpur start
+    },
+    BOW_AND_CROSSBOW {
+        @Override
+        public boolean canEnchant(Item item) {
+            return item instanceof BowItem || item instanceof CrossbowItem;
+        }
+    // Purpur end
     };
 
     public abstract boolean canEnchant(Item item);
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index ccd228aa323eef108526640dfe03b07541041236..80fc65c5f3a89241fb7aadaccbf730a5f05dec64 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -378,6 +378,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);
@@ -385,6 +386,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;
