From b0576f313f6e9d6167a7d2d062d87d542feb547e Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 17 Jun 2023 06:44:22 +1000 Subject: [PATCH] SPIGOT-7389: Handle setting null items in ChiseledBookshelf Inventory By: Doc --- .../block/entity/ChiseledBookShelfBlockEntity.patch | 9 +++++++++ .../inventory/CraftInventoryChiseledBookshelf.java | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch index b8eda8ce9d..0b2f7a74e3 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch @@ -63,6 +63,15 @@ this.items.clear(); ContainerUtil.loadAllItems(nbttagcompound, this.items); this.lastInteractedSlot = nbttagcompound.getInt("last_interacted_slot"); +@@ -91,7 +134,7 @@ + + this.items.set(i, ItemStack.EMPTY); + if (!itemstack.isEmpty()) { +- this.updateState(i); ++ if (level != null) this.updateState(i); // CraftBukkit - SPIGOT-7381: check for null world + } + + return itemstack; @@ -106,7 +149,7 @@ public void setItem(int i, ItemStack itemstack) { if (itemstack.is(TagsItem.BOOKSHELF_BOOKS)) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryChiseledBookshelf.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryChiseledBookshelf.java index e2082746ff..f775a4d60d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryChiseledBookshelf.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryChiseledBookshelf.java @@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; import org.bukkit.block.ChiseledBookshelf; import org.bukkit.inventory.ChiseledBookshelfInventory; +import org.bukkit.inventory.ItemStack; public class CraftInventoryChiseledBookshelf extends CraftInventory implements ChiseledBookshelfInventory { @@ -11,6 +12,17 @@ public class CraftInventoryChiseledBookshelf extends CraftInventory implements C } + @Override + public void setItem(int index, ItemStack item) { + net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item); + + if (nms.isEmpty()) { + this.getInventory().removeItemNoUpdate(index); + } else { + this.getInventory().setItem(index, nms); + } + } + @Override public ChiseledBookshelf getHolder() { return (ChiseledBookshelf) inventory.getOwner();