--- a/net/minecraft/world/item/component/BundleContents.java
+++ b/net/minecraft/world/item/component/BundleContents.java
@@ -25,6 +_,7 @@
         .flatXmap(BundleContents::checkAndCreate, bundleContents -> DataResult.success(bundleContents.items));
     public static final StreamCodec<RegistryFriendlyByteBuf, BundleContents> STREAM_CODEC = ItemStack.STREAM_CODEC
         .apply(ByteBufCodecs.list())
+        .apply(ByteBufCodecs::increaseDepth) // Paper - Track codec depth
         .map(BundleContents::new, contents -> contents.items);
     private static final Fraction BUNDLE_IN_BUNDLE_WEIGHT = Fraction.getFraction(1, 16);
     private static final int NO_STACK_INDEX = -1;
@@ -76,6 +_,12 @@
         return !stack.isEmpty() && stack.getItem().canFitInsideContainerItems();
     }
 
+    // Paper start - correct bundle inventory action
+    public int getMaxAmountToAdd(final ItemStack stack) {
+        return Mutable.getMaxAmountToAdd(stack, this.weight);
+    }
+    // Paper end - correct bundle inventory action
+
     public int getNumberOfItemsToShow() {
         int size = this.size();
         int i = size > 12 ? 11 : 12;
@@ -170,8 +_,14 @@
             }
         }
 
-        private int getMaxAmountToAdd(ItemStack stack) {
-            Fraction fraction = Fraction.ONE.subtract(this.weight);
+        public int getMaxAmountToAdd(ItemStack stack) {
+        // Paper start - correct bundle inventory action
+        // Static overload to easily compute this value without the need for an instance of mutable.
+            return getMaxAmountToAdd(stack, this.weight);
+        }
+        static int getMaxAmountToAdd(final ItemStack stack, final Fraction weight) {
+            Fraction fraction = Fraction.ONE.subtract(weight);
+        // Paper end - correct bundle inventory action
             return Math.max(fraction.divideBy(BundleContents.getWeight(stack)).intValue(), 0);
         }
 
@@ -206,15 +_,21 @@
         }
 
         public void toggleSelectedItem(int selectedItem) {
-            this.selectedItem = this.selectedItem != selectedItem && selectedItem < this.items.size() ? selectedItem : -1;
-        }
+            this.selectedItem = !indexIsOutsideAllowedBounds(selectedItem) ? selectedItem : -1; // Paper
+        }
+
+        // Paper start
+        private boolean indexIsOutsideAllowedBounds(int param0) {
+            return param0 < 0 || param0 >= this.items.size();
+        }
+        // Paper end
 
         @Nullable
         public ItemStack removeOne() {
             if (this.items.isEmpty()) {
                 return null;
             } else {
-                int i = this.selectedItem != -1 && this.selectedItem < this.items.size() ? this.selectedItem : 0;
+                int i = !indexIsOutsideAllowedBounds(this.selectedItem) ? this.selectedItem : 0; // Paper
                 ItemStack itemStack = this.items.remove(i).copy();
                 this.weight = this.weight.subtract(BundleContents.getWeight(itemStack).multiplyBy(Fraction.getFraction(itemStack.getCount(), 1)));
                 this.toggleSelectedItem(-1);
