Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
69 Zeilen
4.1 KiB
Diff
69 Zeilen
4.1 KiB
Diff
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
|
|
index 3c281cdd24acbc9484c968c07f737d50be2deced..ecb4dc0642685d67621c82bb24fb0e939c805ce4 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1239,9 +1239,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// 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 - Inventory close reason
|
|
+ ((org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper - Inventory close reason
|
|
}
|
|
+ // Paper end - this area looks like it can load chunks, change the behavior
|
|
}
|
|
}
|
|
// Spigot End
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index c680b311760601bb539d685bceddba6712d141d4..d2fbbdbb451d6c54d847b4ba125397ad41c4f7b4 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1983,6 +1983,18 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
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
|
|
|
|
@Override
|
|
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
|
|
index 68a6b1508ce4544fe8b18746d440944d41a2fe5b..b8edbd23d547d7189ec64c5d3a8cd1d51859ce23 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -544,6 +544,11 @@ public abstract class Player extends LivingEntity {
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
// Paper end - Inventory close reason
|
|
+ // 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;
|