diff options
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AbstractContainerMenu.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AbstractContainerMenu.java.patch | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AbstractContainerMenu.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AbstractContainerMenu.java.patch new file mode 100644 index 0000000000..d577eee6c2 --- /dev/null +++ b/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AbstractContainerMenu.java.patch @@ -0,0 +1,304 @@ +--- a/net/minecraft/world/inventory/AbstractContainerMenu.java ++++ b/net/minecraft/world/inventory/AbstractContainerMenu.java +@@ -33,6 +35,18 @@ + import net.minecraft.world.level.block.entity.BlockEntity; + import org.slf4j.Logger; + ++// CraftBukkit start ++import com.google.common.base.Preconditions; ++import java.util.HashMap; ++import java.util.Map; ++import org.bukkit.craftbukkit.inventory.CraftInventory; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.Event.Result; ++import org.bukkit.event.inventory.InventoryDragEvent; ++import org.bukkit.event.inventory.InventoryType; ++import org.bukkit.inventory.InventoryView; ++// CraftBukkit end ++ + public abstract class AbstractContainerMenu { + private static final Logger LOGGER = LogUtils.getLogger(); + public static final int SLOT_CLICKED_OUTSIDE = -999; +@@ -62,6 +77,27 @@ + private ContainerSynchronizer synchronizer; + private boolean suppressRemoteUpdates; + ++ // CraftBukkit start ++ public boolean checkReachable = true; ++ public abstract InventoryView getBukkitView(); ++ public void transferTo(AbstractContainerMenu other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) { ++ InventoryView source = this.getBukkitView(), destination = other.getBukkitView(); ++ ((CraftInventory) source.getTopInventory()).getInventory().onClose(player); ++ ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player); ++ ((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player); ++ ((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player); ++ } ++ private Component title; ++ public final Component getTitle() { ++ Preconditions.checkState(this.title != null, "Title not set"); ++ return this.title; ++ } ++ public final void setTitle(Component title) { ++ Preconditions.checkState(this.title == null, "Title already set"); ++ this.title = title; ++ } ++ // CraftBukkit end ++ + protected AbstractContainerMenu(@Nullable MenuType<?> menuType, int containerId) { + this.menuType = menuType; + this.containerId = containerId; +@@ -153,6 +199,15 @@ + } + } + ++ // CraftBukkit start ++ public void broadcastCarriedItem() { ++ this.remoteCarried = this.getCarried().copy(); ++ if (this.synchronizer != null) { ++ this.synchronizer.sendCarriedChange(this, this.remoteCarried); ++ } ++ } ++ // CraftBukkit end ++ + public void removeSlotListener(ContainerListener listener) { + this.containerListeners.remove(listener); + } +@@ -328,8 +424,8 @@ + } + } else if (this.quickcraftStatus == 2) { + if (!this.quickcraftSlots.isEmpty()) { +- if (this.quickcraftSlots.size() == 1) { +- int i1 = this.quickcraftSlots.iterator().next().index; ++ if (false && this.quickcraftSlots.size() == 1) { // CraftBukkit - treat everything as a drag since we are unable to easily call InventoryClickEvent instead ++ k = ((Slot) this.quickcraftSlots.iterator().next()).index; + this.resetQuickCraft(); + this.doClick(i1, this.quickcraftType, ClickType.PICKUP, player); + return; +@@ -343,23 +440,59 @@ + + int count = this.getCarried().getCount(); + +- for (Slot slot1 : this.quickcraftSlots) { +- ItemStack carried1 = this.getCarried(); +- if (slot1 != null +- && canItemQuickReplace(slot1, carried1, true) +- && slot1.mayPlace(carried1) +- && (this.quickcraftType == 2 || carried1.getCount() >= this.quickcraftSlots.size()) +- && this.canDragTo(slot1)) { +- int i2 = slot1.hasItem() ? slot1.getItem().getCount() : 0; +- int min = Math.min(itemStack.getMaxStackSize(), slot1.getMaxStackSize(itemStack)); +- int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min); +- count -= min1 - i2; +- slot1.setByPlayer(itemStack.copyWithCount(min1)); ++ Map<Integer, ItemStack> draggedSlots = new HashMap<Integer, ItemStack>(); // CraftBukkit - Store slots from drag in map (raw slot id -> new stack) ++ while (iterator.hasNext()) { ++ Slot slot1 = (Slot) iterator.next(); ++ ItemStack itemstack2 = this.getCarried(); ++ ++ if (slot1 != null && canItemQuickReplace(slot1, itemstack2, true) && slot1.mayPlace(itemstack2) && (this.quickcraftType == 2 || itemstack2.getCount() >= this.quickcraftSlots.size()) && this.canDragTo(slot1)) { ++ int j1 = slot1.hasItem() ? slot1.getItem().getCount() : 0; ++ int k1 = Math.min(itemstack1.getMaxStackSize(), slot1.getMaxStackSize(itemstack1)); ++ int l1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemstack1) + j1, k1); ++ ++ l -= l1 - j1; ++ // slot1.setByPlayer(itemstack1.copyWithCount(l1)); ++ draggedSlots.put(slot1.index, itemstack1.copyWithCount(l1)); // CraftBukkit - Put in map instead of setting + } + } + +- itemStack.setCount(count); +- this.setCarried(itemStack); ++ // CraftBukkit start - InventoryDragEvent ++ InventoryView view = getBukkitView(); ++ org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack1); ++ newcursor.setAmount(l); ++ Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<Integer, org.bukkit.inventory.ItemStack>(); ++ for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet()) { ++ eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue())); ++ } ++ ++ // It's essential that we set the cursor to the new value here to prevent item duplication if a plugin closes the inventory. ++ ItemStack oldCursor = this.getCarried(); ++ this.setCarried(CraftItemStack.asNMSCopy(newcursor)); ++ ++ InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != org.bukkit.Material.AIR ? newcursor : null), CraftItemStack.asBukkitCopy(oldCursor), this.quickcraftType == 1, eventmap); ++ player.level().getCraftServer().getPluginManager().callEvent(event); ++ ++ // Whether or not a change was made to the inventory that requires an update. ++ boolean needsUpdate = event.getResult() != Result.DEFAULT; ++ ++ if (event.getResult() != Result.DENY) { ++ for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet()) { ++ view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue())); ++ } ++ // The only time the carried item will be set to null is if the inventory is closed by the server. ++ // If the inventory is closed by the server, then the cursor items are dropped. This is why we change the cursor early. ++ if (this.getCarried() != null) { ++ this.setCarried(CraftItemStack.asNMSCopy(event.getCursor())); ++ needsUpdate = true; ++ } ++ } else { ++ this.setCarried(oldCursor); ++ } ++ ++ if (needsUpdate && player instanceof ServerPlayer) { ++ this.sendAllDataToRemote(); ++ } ++ // CraftBukkit end + } + + this.resetQuickCraft(); +@@ -368,15 +501,23 @@ + } + } else if (this.quickcraftStatus != 0) { + this.resetQuickCraft(); +- } else if ((clickType == ClickType.PICKUP || clickType == ClickType.QUICK_MOVE) && (button == 0 || button == 1)) { +- ClickAction clickAction = button == 0 ? ClickAction.PRIMARY : ClickAction.SECONDARY; +- if (slotId == -999) { +- if (!this.getCarried().isEmpty()) { +- if (clickAction == ClickAction.PRIMARY) { +- player.drop(this.getCarried(), true); +- this.setCarried(ItemStack.EMPTY); +- } else { +- player.drop(this.getCarried().split(1), true); ++ } else { ++ int i2; ++ ++ if ((clickType == InventoryClickType.PICKUP || clickType == InventoryClickType.QUICK_MOVE) && (button == 0 || button == 1)) { ++ ClickAction clickaction = button == 0 ? ClickAction.PRIMARY : ClickAction.SECONDARY; ++ ++ if (slotId == -999) { ++ if (!this.getCarried().isEmpty()) { ++ if (clickaction == ClickAction.PRIMARY) { ++ // CraftBukkit start ++ ItemStack carried = this.getCarried(); ++ this.setCarried(ItemStack.EMPTY); ++ player.drop(carried, true); ++ // CraftBukkit start ++ } else { ++ player.drop(this.getCarried().split(1), true); ++ } + } + } + } else if (clickType == ClickType.QUICK_MOVE) { +@@ -435,37 +576,56 @@ + } + } + +- slot.setChanged(); +- } +- } else if (clickType == ClickType.SWAP && (button >= 0 && button < 9 || button == 40)) { +- ItemStack item = inventory.getItem(button); +- Slot slot = this.slots.get(slotId); +- ItemStack carried = slot.getItem(); +- if (!item.isEmpty() || !carried.isEmpty()) { +- if (item.isEmpty()) { +- if (slot.mayPickup(player)) { +- inventory.setItem(button, carried); +- slot.onSwapCraft(carried.getCount()); +- slot.setByPlayer(ItemStack.EMPTY); +- slot.onTake(player, carried); +- } +- } else if (carried.isEmpty()) { +- if (slot.mayPlace(item)) { +- int maxStackSize = slot.getMaxStackSize(item); +- if (item.getCount() > maxStackSize) { +- slot.setByPlayer(item.split(maxStackSize)); +- } else { +- inventory.setItem(button, ItemStack.EMPTY); +- slot.setByPlayer(item); ++ slot.setChanged(); ++ // CraftBukkit start - Make sure the client has the right slot contents ++ if (player instanceof ServerPlayer && slot.getMaxStackSize() != 64) { ++ ((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), slot.index, slot.getItem())); ++ // Updating a crafting inventory makes the client reset the result slot, have to send it again ++ if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) { ++ ((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 0, this.getSlot(0).getItem())); + } + } +- } else if (slot.mayPickup(player) && slot.mayPlace(item)) { +- int maxStackSize = slot.getMaxStackSize(item); +- if (item.getCount() > maxStackSize) { +- slot.setByPlayer(item.split(maxStackSize)); +- slot.onTake(player, carried); +- if (!inventory.add(carried)) { +- player.drop(carried, true); ++ // CraftBukkit end ++ } ++ } else { ++ int j2; ++ ++ if (clickType == InventoryClickType.SWAP && (button >= 0 && button < 9 || button == 40)) { ++ ItemStack itemstack4 = playerinventory.getItem(button); ++ ++ slot = (Slot) this.slots.get(slotId); ++ itemstack = slot.getItem(); ++ if (!itemstack4.isEmpty() || !itemstack.isEmpty()) { ++ if (itemstack4.isEmpty()) { ++ if (slot.mayPickup(player)) { ++ playerinventory.setItem(button, itemstack); ++ slot.onSwapCraft(itemstack.getCount()); ++ slot.setByPlayer(ItemStack.EMPTY); ++ slot.onTake(player, itemstack); ++ } ++ } else if (itemstack.isEmpty()) { ++ if (slot.mayPlace(itemstack4)) { ++ j2 = slot.getMaxStackSize(itemstack4); ++ if (itemstack4.getCount() > j2) { ++ slot.setByPlayer(itemstack4.split(j2)); ++ } else { ++ playerinventory.setItem(button, ItemStack.EMPTY); ++ slot.setByPlayer(itemstack4); ++ } ++ } ++ } else if (slot.mayPickup(player) && slot.mayPlace(itemstack4)) { ++ j2 = slot.getMaxStackSize(itemstack4); ++ if (itemstack4.getCount() > j2) { ++ slot.setByPlayer(itemstack4.split(j2)); ++ slot.onTake(player, itemstack); ++ if (!playerinventory.add(itemstack)) { ++ player.drop(itemstack, true); ++ } ++ } else { ++ playerinventory.setItem(button, itemstack); ++ slot.setByPlayer(itemstack4); ++ slot.onTake(player, itemstack); ++ } + } + } else { + inventory.setItem(button, carried); +@@ -539,15 +699,17 @@ + + public void removed(Player player) { + if (player instanceof ServerPlayer) { +- ItemStack carried = this.getCarried(); +- if (!carried.isEmpty()) { +- if (player.isAlive() && !((ServerPlayer)player).hasDisconnected()) { +- player.getInventory().placeItemBackInInventory(carried); ++ ItemStack itemstack = this.getCarried(); ++ ++ if (!itemstack.isEmpty()) { ++ this.setCarried(ItemStack.EMPTY); // CraftBukkit - SPIGOT-4556 - from below ++ if (player.isAlive() && !((ServerPlayer) player).hasDisconnected()) { ++ player.getInventory().placeItemBackInInventory(itemstack); + } else { + player.drop(carried, false); + } + +- this.setCarried(ItemStack.EMPTY); ++ // this.setCarried(ItemStack.EMPTY); // CraftBukkit - moved up + } + } + } +@@ -726,6 +926,11 @@ + } + + public ItemStack getCarried() { ++ // CraftBukkit start ++ if (this.carried.isEmpty()) { ++ this.setCarried(ItemStack.EMPTY); ++ } ++ // CraftBukkit end + return this.carried; + } + |