From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul Sauve <paul@technove.co>
Date: Sat, 13 Mar 2021 12:24:41 -0600
Subject: [PATCH] Remove iterators from inventory contains


diff --git a/src/main/java/net/minecraft/world/entity/player/PlayerInventory.java b/src/main/java/net/minecraft/world/entity/player/PlayerInventory.java
index 2df3ae0b72ccb5f816d55fed15396ba5a1affb7f..754a3ea18905b79ae5ae4fc2442c94f0611b6d0e 100644
--- a/src/main/java/net/minecraft/world/entity/player/PlayerInventory.java
+++ b/src/main/java/net/minecraft/world/entity/player/PlayerInventory.java
@@ -630,6 +630,8 @@ public class PlayerInventory implements IInventory, INamableTileEntity {
     }
 
     public boolean h(ItemStack itemstack) {
+        // Airplane start - skip using abstract iterators and stuff, they're generic and slow and allocating them sucks
+        /*
         Iterator iterator = this.f.iterator();
 
         while (iterator.hasNext()) {
@@ -644,6 +646,20 @@ public class PlayerInventory implements IInventory, INamableTileEntity {
                 }
             }
         }
+         */
+        List<NonNullList<ItemStack>> components = this.getComponents();
+        for (int i = 0; i < components.size(); i++) {
+            List<ItemStack> list = components.get(i);
+
+            for (int j = 0; j < list.size(); j++) {
+                ItemStack itemstack1 = list.get(j);
+
+                if (!itemstack1.isEmpty() && itemstack1.doMaterialsMatch(itemstack)) {
+                    return true;
+                }
+            }
+        }
+        // Airplane end
 
         return false;
     }
