mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-20 07:19:35 +00:00
--------- Co-authored-by: MC_XiaoHei <xiaohei.xor7studio@foxmail.com> Co-authored-by: Bluemangoo <chenfy2006@qq.com>
81 lines
3.2 KiB
Diff
81 lines
3.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Wed, 17 Aug 2022 11:04:12 +0800
|
|
Subject: [PATCH] Remove iterators from inventory contains
|
|
|
|
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
index ca7fbe4f8c1e1d2fb90095aa35be4dda3029c23e..3c8f35f92ed7e9518d676087f82d1e4da963b779 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
@@ -1,9 +1,11 @@
|
|
package net.minecraft.world.entity.player;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
+
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.function.Predicate;
|
|
+
|
|
import net.minecraft.CrashReport;
|
|
import net.minecraft.CrashReportCategory;
|
|
import net.minecraft.ReportedException;
|
|
@@ -24,6 +26,7 @@ import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
// CraftBukkit start
|
|
import java.util.ArrayList;
|
|
+
|
|
import org.bukkit.Location;
|
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
import org.bukkit.entity.HumanEntity;
|
|
@@ -643,17 +646,31 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
public boolean contains(ItemStack stack) {
|
|
- Iterator iterator = this.compartments.iterator();
|
|
+ // Leaves start - don't allocate iterators
|
|
+ if (org.leavesmc.leaves.LeavesConfig.removeInventoryContainsIterators) {
|
|
+ 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)) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ Iterator iterator = this.compartments.iterator();
|
|
|
|
- while (iterator.hasNext()) {
|
|
- List<ItemStack> list = (List) iterator.next();
|
|
- Iterator iterator1 = list.iterator();
|
|
+ while (iterator.hasNext()) {
|
|
+ List<ItemStack> list = (List) iterator.next();
|
|
+ Iterator iterator1 = list.iterator();
|
|
|
|
- while (iterator1.hasNext()) {
|
|
- ItemStack itemstack1 = (ItemStack) iterator1.next();
|
|
+ while (iterator1.hasNext()) {
|
|
+ ItemStack itemstack1 = (ItemStack) iterator1.next();
|
|
|
|
- if (!itemstack1.isEmpty() && ItemStack.isSameItemSameComponents(itemstack1, stack)) {
|
|
- return true;
|
|
+ if (!itemstack1.isEmpty() && ItemStack.isSameItemSameComponents(itemstack1, stack)) {
|
|
+ return true;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
@@ -695,7 +712,7 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
}
|
|
}
|
|
-
|
|
+ // Leaves end - don't allocate iterators
|
|
return false;
|
|
}
|
|
|