Skip to content

Commit 79cf135

Browse files
authored
Ignore HopperInventorySearchEvent when it has no listeners (#13009)
1 parent 1922be9 commit 79cf135

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

paper-server/patches/features/0028-Optimize-Hoppers.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ index 0000000000000000000000000000000000000000..24a2090e068ad3c0d08705050944abdf
4848
+ }
4949
+}
5050
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
51-
index 34b10db71d22cb7211dcfc5565e6833c8d4d2413..382d2b6b53bd144f4d56dccdc603ed0da8fe07a7 100644
51+
index 6c8f06bc55cc6bffe6879433c5eda74eb5a13cb0..914ab3ad3e9b5735fcc179e17aaad82ab1b63b18 100644
5252
--- a/net/minecraft/server/MinecraftServer.java
5353
+++ b/net/minecraft/server/MinecraftServer.java
5454
@@ -1719,6 +1719,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -103,7 +103,7 @@ index 275646a9f99f3c46bc81a23143c1960f2a6300b1..5986825d6a381eeb445dd424dd127864
103103
}
104104
}
105105
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
106-
index 94d68fbb3d152b2fd43f989b728c5efabbf3c22c..800b7e78ae989868ed0b9e060c80dcd002759412 100644
106+
index 0af3eef04782b7d54c5bb0b0cfe2c2b5e052661e..01ed25d1f895d94485b5fecd98476534cbb26930 100644
107107
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
108108
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
109109
@@ -143,18 +143,56 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -628,7 +628,7 @@ index 94d68fbb3d152b2fd43f989b728c5efabbf3c22c..800b7e78ae989868ed0b9e060c80dcd0
628628
stack = leftover; // Paper - Make hoppers respect inventory max stack size
629629
flag = true;
630630
} else if (canMergeItems(item, stack)) {
631-
@@ -523,13 +772,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
631+
@@ -525,13 +774,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
632632

633633
@Nullable
634634
public static Container getContainerAt(Level level, BlockPos pos) {
@@ -650,7 +650,7 @@ index 94d68fbb3d152b2fd43f989b728c5efabbf3c22c..800b7e78ae989868ed0b9e060c80dcd0
650650
blockContainer = getEntityContainer(level, x, y, z);
651651
}
652652

653-
@@ -555,14 +810,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
653+
@@ -557,14 +812,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
654654

655655
@Nullable
656656
private static Container getEntityContainer(Level level, double x, double y, double z) {

paper-server/patches/sources/net/minecraft/world/level/block/entity/HopperBlockEntity.java.patch

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
}
238238

239239
destination.setChanged();
240-
@@ -336,14 +_,57 @@
240+
@@ -336,14 +_,59 @@
241241
return stack;
242242
}
243243

@@ -263,9 +263,10 @@
263263
@Nullable
264264
private static Container getAttachedContainer(Level level, BlockPos pos, HopperBlockEntity blockEntity) {
265265
- return getContainerAt(level, pos.relative(blockEntity.facing));
266-
+ // CraftBukkit start
266+
+ // Paper start
267267
+ BlockPos searchPosition = pos.relative(blockEntity.facing);
268268
+ Container inventory = getContainerAt(level, searchPosition);
269+
+ if (org.bukkit.event.inventory.HopperInventorySearchEvent.getHandlerList().getRegisteredListeners().length == 0) return inventory;
269270
+
270271
+ org.bukkit.craftbukkit.block.CraftBlock hopper = org.bukkit.craftbukkit.block.CraftBlock.at(level, pos);
271272
+ org.bukkit.craftbukkit.block.CraftBlock searchBlock = org.bukkit.craftbukkit.block.CraftBlock.at(level, searchPosition);
@@ -275,14 +276,15 @@
275276
+ searchBlock,
276277
+ org.bukkit.event.inventory.HopperInventorySearchEvent.ContainerType.DESTINATION
277278
+ );
278-
+ // CraftBukkit end
279+
+ // Paper end
279280
}
280281

281282
@Nullable
282283
private static Container getSourceContainer(Level level, Hopper hopper, BlockPos pos, BlockState state) {
283284
- return getContainerAt(level, pos, state, hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ());
284-
+ // CraftBukkit start
285+
+ // Paper start
285286
+ final Container inventory = HopperBlockEntity.getContainerAt(level, pos, state, hopper.getLevelX(), hopper.getLevelY() + 1.0D, hopper.getLevelZ());
287+
+ if (org.bukkit.event.inventory.HopperInventorySearchEvent.getHandlerList().getRegisteredListeners().length == 0) return inventory;
286288
+
287289
+ final BlockPos hopperPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY(), hopper.getLevelZ());
288290
+ org.bukkit.craftbukkit.block.CraftBlock hopperBlock = org.bukkit.craftbukkit.block.CraftBlock.at(level, hopperPos);
@@ -293,7 +295,7 @@
293295
+ containerBlock,
294296
+ org.bukkit.event.inventory.HopperInventorySearchEvent.ContainerType.SOURCE
295297
+ );
296-
+ // CraftBukkit end
298+
+ // Paper end
297299
}
298300

299301
public static List<ItemEntity> getItemsAtAndAbove(Level level, Hopper hopper) {

0 commit comments

Comments
 (0)