9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-04 15:41:40 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0120-Remove-iterators-from-Inventory-contains.patch
Kaan D. 502385840d Bunch of side perf improvements (#217)
* Fix TE Lag

* Sepals Rearrange the attackable conditions

* Cache ItemStack max stack size

* fix build

* extra: Skip dirty stats copy when requesting player stats

* extra: Reset dirty flag when loading maps from the disk

* extra: Supporting block cache

* extra: Avoid useless deque clear on - credit: @MachineBreaker

* experimental/draft: Optimize SortedArraySet

* experimental/draft: Simplify SortedArraySet - sometime complex stuff doesnt mean faster.

* extra: Change maps/sets in brain + remove streams from villagers

* extra: Remove 'copyOf' from Baby Villager Sensor

* experimental: Rewrite trigger in SimpleCriterionTrigger

* [ci/skip] fix comments

* Faster setter for SimpleCriterionTrigger

* extra: Cache and optimize fluidOnEyes

* Sync changes

* [ci/skip] cleanup

* extra: QuadTree implementation for isChunkNearPlayer

* [ci/skip] cleanup

* [ci/skip] cleanup

* [ci/skip] clean up

* [ci/skip] cleanup

* Only player pushable

* Store chunkPos with keys

* [ci/skip] cleanup

* [ci/skip] cleanup

* cleanup

* rebuild patches

* cache some more stuff

* extra: optimize collectTickingChunks

* remove quadTree optimization for now (will open a new PR just for that)

* temp: Lazily optimize isChunkNearPlayer

* Inline filter & merge as a single loop

* [ci/skip] Add diff on change

* extra: optimize everything but the testing itself on getEntities

* [ci/skip] cleanup

* Optimize chunkUnloadQueue

* Remove iterators from inventory

* [ci/skip] Add TODOs

* i hate programming

* remove forEach

* extra: Alternative Brain Behaviour

* remove: opt getEntities + cache fluidOnEyes

* extra: Improve checkDespawn - credits: @kidofcubes

* extra: Improve pushEntity and getEntities

* yeet this

* VERY EXPERIMENTAL: getEntities Optimization

* fix bunch of issues from getEntities patch

* extra: slightly optimize getNearestPlayer - credits: @kidofcubes

* drop a patch for now (will open a new pr)

* move these to a new branch

* fix and optimize checkDespawn patches

* Rebuild Patches

* [ci/skip] Update benchmark

* [ci/skip] cleanup

* Drop

* [ci/skip] Drop

* Rebuild

* [ci/skip]

* Add configurable brain running behavior cache update interval

* Move to new pr

* [ci/skip] Update benchmark

---------

Co-authored-by: MachineBreaker <saltspigotpp@gmail.com>
Co-authored-by: kidofcubes <kidofcubes@gmail.com>
Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
2025-02-22 02:23:53 -05:00

62 lines
2.9 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#contains
diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java
index 839cbb67d3d38960d9114a4db5bab911b66a573c..e2237ffebadc8f010688c6e7336f4278193a1a20 100644
--- a/net/minecraft/world/entity/player/Inventory.java
+++ b/net/minecraft/world/entity/player/Inventory.java
@@ -568,9 +568,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(ItemStack stack) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (!itemStack.isEmpty() && ItemStack.isSameItemSameComponents(itemStack, stack)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack1 = list.get(j);
+ if (!itemstack1.isEmpty() && ItemStack.isSameItemSameComponents(itemstack1, stack)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}
@@ -580,9 +584,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(TagKey<Item> tag) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (!itemStack.isEmpty() && itemStack.is(tag)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack = list.get(j);
+ if (!itemstack.isEmpty() && itemstack.is(tag)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}
@@ -592,9 +600,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(Predicate<ItemStack> predicate) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (predicate.test(itemStack)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack = list.get(j);
+ if (predicate.test(itemstack)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}