Fix InventoryOpenEvent cancellation

This commit is contained in:
Tamion
2024-08-19 18:05:26 +02:00
parent be5187c2da
commit 2742ad6a9a
23 changed files with 325 additions and 64 deletions

View File

@@ -37,6 +37,19 @@
}
@Override
@@ -109,10 +125,10 @@
@Override
public void openCustomInventoryScreen(Player player) {
- player.openMenu(this);
+ // Paper - fix inventory open cancel - moved into below if
Level world = player.level();
- if (world instanceof ServerLevel worldserver) {
+ if (world instanceof ServerLevel worldserver && player.openMenu(this).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
this.gameEvent(GameEvent.CONTAINER_OPEN, player);
PiglinAi.angerNearbyPiglins(worldserver, player, true);
}
@@ -165,7 +181,7 @@
@Nullable
@Override

View File

@@ -32,7 +32,18 @@
}
default void chestVehicleDestroyed(DamageSource source, ServerLevel world, Entity vehicle) {
@@ -97,13 +101,18 @@
@@ -91,19 +95,28 @@
}
default InteractionResult interactWithContainerVehicle(Player player) {
- player.openMenu(this);
+ // Paper start - Fix InventoryOpenEvent cancellation
+ if (player.openMenu(this).isEmpty()) {
+ return InteractionResult.PASS;
+ }
+ // Paper end - Fix InventoryOpenEvent cancellation
return InteractionResult.SUCCESS;
}
default void unpackChestVehicleLootTable(@Nullable Player player) {
MinecraftServer minecraftServer = this.level().getServer();
@@ -53,7 +64,7 @@
LootParams.Builder builder = new LootParams.Builder((ServerLevel)this.level()).withParameter(LootContextParams.ORIGIN, this.position());
if (player != null) {
builder.withLuck(player.getLuck()).withParameter(LootContextParams.THIS_ENTITY, player);
@@ -173,4 +182,14 @@
@@ -173,4 +186,14 @@
default boolean isChestVehicleStillValid(Player player) {
return !this.isRemoved() && player.canInteractWithEntity(this.getBoundingBox(), 4.0);
}