From a02758acdb5eaa3cc45954eefb5a9862836da93b Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 5 Feb 2025 22:54:42 +1100 Subject: [PATCH] SPIGOT-8005: Can't open Crafter block --- .../minecraft/world/inventory/Container.patch | 23 +++++++++++-------- .../world/inventory/ContainerChest.patch | 7 +++--- .../world/inventory/ContainerShulkerBox.patch | 7 +++--- .../world/inventory/CrafterMenu.patch | 15 +++++++++--- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/nms-patches/net/minecraft/world/inventory/Container.patch b/nms-patches/net/minecraft/world/inventory/Container.patch index 27fb20dd3..142068fdc 100644 --- a/nms-patches/net/minecraft/world/inventory/Container.patch +++ b/nms-patches/net/minecraft/world/inventory/Container.patch @@ -21,7 +21,7 @@ public abstract class Container { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -67,6 +81,28 @@ +@@ -67,6 +81,31 @@ private ContainerSynchronizer synchronizer; private boolean suppressRemoteUpdates; @@ -44,13 +44,16 @@ + Preconditions.checkState(this.title == null, "Title already set"); + this.title = title; + } -+ public void startOpen() {} ++ protected boolean opened; ++ public void startOpen() { ++ this.opened = true; ++ } + // CraftBukkit end + protected Container(@Nullable Containers containers, int i) { this.carried = ItemStack.EMPTY; this.remoteSlots = NonNullList.create(); -@@ -192,6 +228,15 @@ +@@ -192,6 +231,15 @@ } @@ -66,7 +69,7 @@ public void removeSlotListener(ICrafting icrafting) { this.containerListeners.remove(icrafting); } -@@ -417,7 +462,7 @@ +@@ -417,7 +465,7 @@ } } else if (this.quickcraftStatus == 2) { if (!this.quickcraftSlots.isEmpty()) { @@ -75,7 +78,7 @@ k = ((Slot) this.quickcraftSlots.iterator().next()).index; this.resetQuickCraft(); this.doClick(k, this.quickcraftType, InventoryClickType.PICKUP, entityhuman); -@@ -433,6 +478,7 @@ +@@ -433,6 +481,7 @@ l = this.getCarried().getCount(); Iterator iterator = this.quickcraftSlots.iterator(); @@ -83,7 +86,7 @@ while (iterator.hasNext()) { Slot slot1 = (Slot) iterator.next(); ItemStack itemstack2 = this.getCarried(); -@@ -443,12 +489,48 @@ +@@ -443,12 +492,48 @@ int l1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemstack1) + j1, k1); l -= l1 - j1; @@ -135,7 +138,7 @@ } this.resetQuickCraft(); -@@ -466,8 +548,11 @@ +@@ -466,8 +551,11 @@ if (i == -999) { if (!this.getCarried().isEmpty()) { if (clickaction == ClickAction.PRIMARY) { @@ -148,7 +151,7 @@ } else { entityhuman.drop(this.getCarried().split(1), true); } -@@ -530,6 +615,15 @@ +@@ -530,6 +618,15 @@ } slot.setChanged(); @@ -164,7 +167,7 @@ } } else { int j2; -@@ -662,8 +756,9 @@ +@@ -662,8 +759,9 @@ ItemStack itemstack = this.getCarried(); if (!itemstack.isEmpty()) { @@ -175,7 +178,7 @@ } } -@@ -893,6 +988,11 @@ +@@ -893,6 +991,11 @@ } public ItemStack getCarried() { diff --git a/nms-patches/net/minecraft/world/inventory/ContainerChest.patch b/nms-patches/net/minecraft/world/inventory/ContainerChest.patch index 50356f611..71d40414a 100644 --- a/nms-patches/net/minecraft/world/inventory/ContainerChest.patch +++ b/nms-patches/net/minecraft/world/inventory/ContainerChest.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerChest.java +++ b/net/minecraft/world/inventory/ContainerChest.java -@@ -6,10 +6,44 @@ +@@ -6,10 +6,45 @@ import net.minecraft.world.entity.player.PlayerInventory; import net.minecraft.world.item.ItemStack; @@ -39,13 +39,14 @@ + + @Override + public void startOpen() { ++ super.startOpen(); + this.container.startOpen(this.player.player); + } + // CraftBukkit end private ContainerChest(Containers containers, int i, PlayerInventory playerinventory, int j) { this(containers, i, playerinventory, new InventorySubcontainer(9 * j), j); -@@ -52,7 +86,10 @@ +@@ -52,7 +87,10 @@ checkContainerSize(iinventory, j * 9); this.container = iinventory; this.containerRows = j; @@ -57,7 +58,7 @@ boolean flag = true; this.addChestGrid(iinventory, 8, 18); -@@ -72,6 +109,7 @@ +@@ -72,6 +110,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch b/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch index ab52bd196..ca5c50ae9 100644 --- a/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch +++ b/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerShulkerBox.java +++ b/net/minecraft/world/inventory/ContainerShulkerBox.java -@@ -6,10 +6,34 @@ +@@ -6,10 +6,35 @@ import net.minecraft.world.entity.player.PlayerInventory; import net.minecraft.world.item.ItemStack; @@ -29,13 +29,14 @@ + + @Override + public void startOpen() { ++ super.startOpen(); + container.startOpen(player.player); + } + // CraftBukkit end public ContainerShulkerBox(int i, PlayerInventory playerinventory) { this(i, playerinventory, new InventorySubcontainer(27)); -@@ -19,7 +43,8 @@ +@@ -19,7 +44,8 @@ super(Containers.SHULKER_BOX, i); checkContainerSize(iinventory, 27); this.container = iinventory; @@ -45,7 +46,7 @@ boolean flag = true; boolean flag1 = true; -@@ -34,6 +59,7 @@ +@@ -34,6 +60,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch b/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch index b72a478f7..7c2b08266 100644 --- a/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch +++ b/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/CrafterMenu.java +++ b/net/minecraft/world/inventory/CrafterMenu.java -@@ -10,8 +10,29 @@ +@@ -10,8 +10,35 @@ import net.minecraft.world.item.crafting.RecipeCrafting; import net.minecraft.world.level.block.CrafterBlock; @@ -26,11 +26,17 @@ + bukkitEntity = new CraftCrafterView(this.player.getBukkitEntity(), inventory, this); + return bukkitEntity; + } ++ ++ @Override ++ public void startOpen() { ++ super.startOpen(); ++ this.refreshRecipeResult(); ++ } + // CraftBukkit end protected static final int SLOT_COUNT = 9; private static final int INV_SLOT_START = 9; private static final int INV_SLOT_END = 36; -@@ -106,6 +127,7 @@ +@@ -106,18 +133,24 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -38,7 +44,10 @@ return this.container.stillValid(entityhuman); } -@@ -115,9 +137,13 @@ + private void refreshRecipeResult() { ++ if (!this.opened) return; // CraftBukkit - SPIGOT-8005: don't refresh until opened + EntityHuman entityhuman = this.player; + if (entityhuman instanceof EntityPlayer entityplayer) { WorldServer worldserver = entityplayer.serverLevel(); CraftingInput craftinginput = this.container.asCraftInput();