Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
69 Zeilen
3.9 KiB
Diff
69 Zeilen
3.9 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 e809a959d69197ecdec768a2d4f348c73c0d5b9a..0f6d4f80677c54a94a1bbfb861a3bcce17b83489 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1553,9 +1553,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
// 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
|
|
}
|
|
+ // Paper end
|
|
}
|
|
}
|
|
// 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 59e02bd5b49e0c900d049a1f1927316d45910768..ce2972c62f91724f6a9e56c8103fba219f7a60bb 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1615,6 +1615,18 @@ public class ServerPlayer extends 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 fd39c81ab54e07630fa12e9e451dcd9b529db446..b69e0cd17467752707a33540cd6113dc21554ca1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -503,6 +503,11 @@ public abstract class Player extends LivingEntity {
|
|
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;
|