2021-08-26 04:16:27 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 11 Mar 2021 03:03:32 -0800
Subject: [PATCH] Do not run close logic for inventories on chunk unload
Still call the event and change the active container though. We
want to avoid close logic because it's possible to load the
chunk through it. This should also be OK from a leak prevention/
state desync POV because the TE is getting unloaded anyways.
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-01-19 12:30:04 +01:00
index 1e67fd45b4449b46992cb0617db22e74ce517b4d..dfbec0bd98f58f7e01d0f45f2ab2c433f9094cc3 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-01-12 21:58:54 +01:00
@@ -1578,9 +1578,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-08-26 04:16:27 +02:00
// Spigot Start
for (net.minecraft.world.level.block.entity.BlockEntity tileentity : chunk.getBlockEntities().values()) {
if (tileentity instanceof net.minecraft.world.Container) {
+ // Paper start - this area looks like it can load chunks, change the behavior
+ // chests for example can apply physics to the world
+ // so instead we just change the active container and call the event
for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((net.minecraft.world.Container) tileentity).getViewers())) {
- h.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
+ ((org.bukkit.craftbukkit.entity.CraftHumanEntity)h).getHandle().closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
}
2024-01-19 12:30:04 +01:00
+ // Paper end - this area looks like it can load chunks, change the behavior
2021-08-26 04:16:27 +02:00
}
}
// Spigot End
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2023-12-31 00:45:24 +01:00
index 9f7c149d3ad1175d55ec02e295ee43bc571c3280..87fdc78409fb16c961c04a5551980a8a231b70d0 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2023-12-29 20:57:32 +01:00
@@ -1630,6 +1630,18 @@ public class ServerPlayer extends Player {
2021-08-26 04:16:27 +02:00
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
+ // Paper start - special close for unloaded inventory
+ @Override
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ // copied from above
+ CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
+ // Paper end
+ // copied from below
+ this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
+ this.containerMenu = this.inventoryMenu;
+ // do not run close logic
+ }
+ // Paper end - special close for unloaded inventory
2022-12-07 21:16:54 +01:00
@Override
2021-08-26 04:16:27 +02:00
public void doCloseContainer() {
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-01-19 12:30:04 +01:00
index 21a02cab65506a3746ddc709d92c6fde244446eb..6018717ea7ff9d3947e48aacd3dbedc075a8376e 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2023-09-22 15:32:32 +02:00
@@ -508,6 +508,11 @@ public abstract class Player extends LivingEntity {
2021-08-26 04:16:27 +02:00
this.containerMenu = this.inventoryMenu;
}
// Paper end
+ // Paper start - special close for unloaded inventory
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ this.containerMenu = this.inventoryMenu;
+ }
+ // Paper end - special close for unloaded inventory
public void closeContainer() {
this.containerMenu = this.inventoryMenu;