9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-22 00:19:20 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0194-Remove-iterators-from-Inventory.patch
hayanesuru 23b7b02eee optimize chunk map (#438)
* rebase

* optimize LivingEntity#travel

* cleanup

* Replace fluid height map

* reuse array list in Entity#collide

* cleanup

* fix fire and liquid collision shape

* fix checkInside

* inline betweenClosed

* cleanup

* optimize getOnPos

* optimize equals in getOnPos

* update mainSupportingBlockPos on dirty

* cleanup

* rename

* merge same patch

* rebase and remove properly

* [ci skip] cleanup

* rebase and rebuild

* fix async locator

* remove async locator

* cleanup

* rebase

---------

Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
2025-08-19 20:48:26 +02:00

127 lines
4.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 13 Feb 2025 01:25:40 +0100
Subject: [PATCH] Remove iterators from Inventory
diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java
index a6bb436dc80daf6901dc027a6011ead4b3ed27e2..b835f8e8caf44e6782b22a76910b26e6f29cb985 100644
--- a/net/minecraft/world/entity/player/Inventory.java
+++ b/net/minecraft/world/entity/player/Inventory.java
@@ -456,13 +456,15 @@ public class Inventory implements Container, Nameable {
}
}
- for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOT_MAPPING.values()) {
+ // Leaf start - Remove iterators from Inventory
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
ItemStack itemStack = this.equipment.get(equipmentSlot);
if (itemStack == stack) {
this.equipment.set(equipmentSlot, ItemStack.EMPTY);
return;
}
}
+ // Leaf end - Remove iterators from Inventory
}
@Override
@@ -515,17 +517,20 @@ public class Inventory implements Container, Nameable {
@Override
public boolean isEmpty() {
- for (ItemStack itemStack : this.items) {
+ // Leaf start - Remove iterators from Inventory
+ for (int i = 0; i < this.items.size(); i++) {
+ ItemStack itemStack = this.items.get(i);
if (!itemStack.isEmpty()) {
return false;
}
}
- for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOT_MAPPING.values()) {
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
if (!this.equipment.get(equipmentSlot).isEmpty()) {
return false;
}
}
+ // Leaf end - Remove iterators from Inventory
return true;
}
@@ -572,31 +577,58 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(ItemStack stack) {
- for (ItemStack itemStack : this) {
+ // Leaf start - Remove iterators from Inventory
+ for (int i = 0; i < this.items.size(); i++) {
+ ItemStack itemStack = this.items.get(i);
if (!itemStack.isEmpty() && ItemStack.isSameItemSameComponents(itemStack, stack)) {
return true;
}
}
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
+ ItemStack itemStack = this.equipment.get(equipmentSlot);
+ if (!itemStack.isEmpty() && ItemStack.isSameItemSameComponents(itemStack, stack)) {
+ return true;
+ }
+ }
+ // Leaf end - Remove iterators from Inventory
return false;
}
public boolean contains(TagKey<Item> tag) {
- for (ItemStack itemStack : this) {
+ // Leaf start - Remove iterators from Inventory
+ for (int i = 0; i < this.items.size(); i++) {
+ ItemStack itemStack = this.items.get(i);
+ if (!itemStack.isEmpty() && itemStack.is(tag)) {
+ return true;
+ }
+ }
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
+ ItemStack itemStack = this.equipment.get(equipmentSlot);
if (!itemStack.isEmpty() && itemStack.is(tag)) {
return true;
}
}
+ // Leaf end - Remove iterators from Inventory
return false;
}
public boolean contains(Predicate<ItemStack> predicate) {
- for (ItemStack itemStack : this) {
+ // Leaf start - Remove iterators from Inventory
+ for (int i = 0; i < this.items.size(); i++) {
+ ItemStack itemStack = this.items.get(i);
if (predicate.test(itemStack)) {
return true;
}
}
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
+ ItemStack itemStack = this.equipment.get(equipmentSlot);
+ if (predicate.test(itemStack)) {
+ return true;
+ }
+ }
+ // Leaf end - Remove iterators from Inventory
return false;
}
@@ -616,9 +648,12 @@ public class Inventory implements Container, Nameable {
}
public void fillStackedContents(StackedItemContents contents) {
- for (ItemStack itemStack : this.items) {
+ // Leaf start - Remove iterators from Inventory
+ for (int i = 0; i < this.items.size(); i++) {
+ ItemStack itemStack = this.items.get(i);
contents.accountSimpleStack(itemStack);
}
+ // Leaf end - Remove iterators from Inventory
}
public ItemStack removeFromSelected(boolean removeStack) {