mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
115 lines
5.2 KiB
Diff
115 lines
5.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Wed, 23 Nov 2022 20:18:05 +0100
|
|
Subject: [PATCH] Remove iterators from Inventory#contains
|
|
|
|
Removed since 1.21.4
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
This patch is based on the following patch:
|
|
"Remove iterators from inventory contains"
|
|
By: Paul Sauve <paul@technove.co>
|
|
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
* Airplane copyright *
|
|
|
|
Airplane
|
|
Copyright (C) 2020 Technove LLC
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
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 ad82e5aeb565b23c3ec565fa60e1f31d1710bd4e..5bf4164f0b9a3d4e6b8e9de87d80683c98a21298 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
@@ -649,6 +649,8 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
public boolean contains(ItemStack stack) {
|
|
+ // Gale start - Airplane - remove iterators from Inventory#contains
|
|
+ /*
|
|
Iterator iterator = this.compartments.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -685,25 +687,34 @@ public class Inventory implements Container, Nameable {
|
|
|
|
return false;
|
|
}
|
|
+ */
|
|
+ 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);
|
|
|
|
- public boolean contains(Predicate<ItemStack> predicate) {
|
|
- Iterator iterator = this.compartments.iterator();
|
|
-
|
|
- while (iterator.hasNext()) {
|
|
- List<ItemStack> list = (List) iterator.next();
|
|
- Iterator iterator1 = list.iterator();
|
|
+ if (!itemstack1.isEmpty() && ItemStack.isSameItem(itemstack1, stack)) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
|
|
- while (iterator1.hasNext()) {
|
|
- ItemStack itemstack = (ItemStack) iterator1.next();
|
|
+ public boolean containsMatchedMap(Predicate<ItemStack> predicate) {
|
|
+ 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 (predicate.test(itemstack)) {
|
|
+ if (!itemstack1.isEmpty() && predicate.test(itemstack1)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
-
|
|
return false;
|
|
}
|
|
+ // Gale end - Airplane - remove iterators from Inventory#contains
|
|
|
|
public void replaceWith(Inventory other) {
|
|
for (int i = 0; i < this.getContainerSize(); ++i) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
index ae321b3b8d98e42ef07fd1f0f738c1a2b428f6db..b15b0c8057e61c6aef05c0865e2c3e06adcf938b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
@@ -294,7 +294,7 @@ public class MapItemSavedData extends SavedData {
|
|
|
|
Predicate<ItemStack> predicate = MapItemSavedData.mapMatcher(stack);
|
|
|
|
- if (!player.getInventory().contains(predicate)) {
|
|
+ if (!player.getInventory().containsMatchedMap(predicate)) { // Gale - Airplane - remove iterators from Inventory#contains
|
|
this.removeDecoration(player.getName().getString());
|
|
}
|
|
|
|
@@ -303,7 +303,7 @@ public class MapItemSavedData extends SavedData {
|
|
Player entityhuman1 = worldmap_worldmaphumantracker1.player;
|
|
String s = entityhuman1.getName().getString();
|
|
|
|
- if (!entityhuman1.isRemoved() && (entityhuman1.getInventory().contains(predicate) || stack.isFramed())) {
|
|
+ if (!entityhuman1.isRemoved() && (entityhuman1.getInventory().containsMatchedMap(predicate) || stack.isFramed())) { // Gale - Airplane - remove iterators from Inventory#contains
|
|
if (!stack.isFramed() && entityhuman1.level().dimension() == this.dimension && this.trackingPosition) {
|
|
this.addDecoration(MapDecorationTypes.PLAYER, entityhuman1.level(), s, entityhuman1.getX(), entityhuman1.getZ(), (double) entityhuman1.getYRot(), (Component) null);
|
|
}
|