From 95a758264f2d19242fe3beb9a8e17ebb4a82a91b Mon Sep 17 00:00:00 2001 From: DungeonDev Date: Tue, 11 Apr 2023 15:35:54 +0200 Subject: [PATCH] Optimize hoppers by not trying to merge full items. (#9110) This can skip many very expensive call to ItemStack.tagMatches. Makes canMergeItems return false for merging into ItemStacks that are already full. --- patches/server/Optimize-Hoppers.patch | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/patches/server/Optimize-Hoppers.patch b/patches/server/Optimize-Hoppers.patch index 091074c67f..c2515c95cc 100644 --- a/patches/server/Optimize-Hoppers.patch +++ b/patches/server/Optimize-Hoppers.patch @@ -551,6 +551,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 List list = world.getEntities((Entity) null, new AABB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), EntitySelector.CONTAINER_ENTITY_SELECTOR); if (!list.isEmpty()) { +@@ -0,0 +0,0 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen + } + + private static boolean canMergeItems(ItemStack first, ItemStack second) { +- return !first.is(second.getItem()) ? false : (first.getDamageValue() != second.getDamageValue() ? false : (first.getCount() > first.getMaxStackSize() ? false : ItemStack.tagMatches(first, second))); ++ return first.is(second.getItem()) && first.getDamageValue() == second.getDamageValue() && first.getCount() < first.getMaxStackSize() && ItemStack.tagMatches(first, second); // Paper - used to return true for full itemstacks?! + } + + @Override diff --git a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java