--- a/net/minecraft/world/level/entity/EntitySection.java
+++ b/net/minecraft/world/level/entity/EntitySection.java
@@ -13,6 +13,10 @@
     private static final Logger LOGGER = LogUtils.getLogger();
     private final ClassInstanceMultiMap<T> storage;
     private Visibility chunkStatus;
+    // Paper start - track number of items and minecarts
+    public int itemCount;
+    public int inventoryEntityCount;
+    // Paper end
 
     public EntitySection(Class<T> entityClass, Visibility status) {
         this.chunkStatus = status;
@@ -20,10 +24,24 @@
     }
 
     public void add(T entity) {
+        // Paper start
+        if (entity instanceof net.minecraft.world.entity.item.ItemEntity) {
+            this.itemCount++;
+        } else if (entity instanceof net.minecraft.world.Container) {
+            this.inventoryEntityCount++;
+        }
+        // Paper end
         this.storage.add(entity);
     }
 
     public boolean remove(T entity) {
+        // Paper start
+        if (entity instanceof net.minecraft.world.entity.item.ItemEntity) {
+            this.itemCount--;
+        } else if (entity instanceof net.minecraft.world.Container) {
+            this.inventoryEntityCount--;
+        }
+        // Paper end
         return this.storage.remove(entity);
     }
 
@@ -42,7 +60,7 @@
             for(T entityAccess : collection) {
                 U entityAccess2 = (U)((EntityAccess)type.tryCast(entityAccess));
                 if (entityAccess2 != null && entityAccess.getBoundingBox().intersects(box)) {
-                    action.accept((T)entityAccess2);
+                    action.accept(entityAccess2); // Paper - decompile fix
                 }
             }
 
