diff --git a/patches/api/Add-CartographyItemEvent.patch b/patches/api/Add-CartographyItemEvent.patch new file mode 100644 index 0000000000..45015d3af7 --- /dev/null +++ b/patches/api/Add-CartographyItemEvent.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Janet Blackquill +Date: Sun, 7 Apr 2024 16:51:04 -0400 +Subject: [PATCH] Add CartographyItemEvent + +Similar to SmithItemEvent, but for cartography tables. + +diff --git a/src/main/java/io/papermc/paper/event/player/CartographyItemEvent.java b/src/main/java/io/papermc/paper/event/player/CartographyItemEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/player/CartographyItemEvent.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.event.player; ++ ++import org.bukkit.inventory.InventoryView; ++import org.bukkit.inventory.CartographyInventory; ++import org.bukkit.event.inventory.ClickType; ++import org.bukkit.event.inventory.InventoryType; ++import org.bukkit.event.inventory.InventoryAction; ++import org.bukkit.event.inventory.InventoryClickEvent; ++import org.jetbrains.annotations.NotNull; ++import org.jetbrains.annotations.ApiStatus; ++ ++/** ++ * Called when the recipe of an Item is completed inside a cartography table. ++ */ ++public class CartographyItemEvent extends InventoryClickEvent { ++ @ApiStatus.Internal ++ public CartographyItemEvent(@NotNull InventoryView view, @NotNull InventoryType.SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action) { ++ super(view, type, slot, click, action); ++ } ++ ++ @ApiStatus.Internal ++ public CartographyItemEvent(@NotNull InventoryView view, @NotNull InventoryType.SlotType type, int slot, @NotNull ClickType click, @NotNull InventoryAction action, int key) { ++ super(view, type, slot, click, action, key); ++ } ++ ++ @NotNull ++ @Override ++ public CartographyInventory getInventory() { ++ return (CartographyInventory) super.getInventory(); ++ } ++} diff --git a/patches/api/Add-item-slot-convenience-methods.patch b/patches/api/Add-item-slot-convenience-methods.patch index 059aab58f7..078493675c 100644 --- a/patches/api/Add-item-slot-convenience-methods.patch +++ b/patches/api/Add-item-slot-convenience-methods.patch @@ -3,6 +3,7 @@ From: Nassim Jahnke Date: Sat, 25 Apr 2020 23:31:28 +0200 Subject: [PATCH] Add item slot convenience methods +Co-authored-by: Janet Blackquill diff --git a/src/main/java/org/bukkit/inventory/AnvilInventory.java b/src/main/java/org/bukkit/inventory/AnvilInventory.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -73,6 +74,37 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end } +diff --git a/src/main/java/org/bukkit/inventory/CartographyInventory.java b/src/main/java/org/bukkit/inventory/CartographyInventory.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/inventory/CartographyInventory.java ++++ b/src/main/java/org/bukkit/inventory/CartographyInventory.java +@@ -0,0 +0,0 @@ package org.bukkit.inventory; + /** + * Interface to the inventory of a Cartography table. + */ +-public interface CartographyInventory extends Inventory { } ++public interface CartographyInventory extends Inventory { ++ // Paper begin - add getResult/setResult to CartographyInventory ++ /** ++ * Check what item is in the result slot of this smithing table. ++ * ++ * @return the result item ++ */ ++ @org.jetbrains.annotations.Nullable ++ default ItemStack getResult() { ++ return this.getItem(2); // net.minecraft.world.inventory.CartographyTableMenu.RESULT_SLOT ++ } ++ ++ /** ++ * Set the item in the result slot of the smithing table ++ * ++ * @param newResult the new result item ++ */ ++ default void setResult(final @org.jetbrains.annotations.Nullable ItemStack newResult) { ++ this.setItem(2, newResult); // net.minecraft.world.inventory.CartographyTableMenu.RESULT_SLOT ++ } ++ // Paper end - add getResult/setResult to CartographyInventory ++} diff --git a/src/main/java/org/bukkit/inventory/GrindstoneInventory.java b/src/main/java/org/bukkit/inventory/GrindstoneInventory.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/inventory/GrindstoneInventory.java diff --git a/patches/server/Add-CartographyItemEvent.patch b/patches/server/Add-CartographyItemEvent.patch new file mode 100644 index 0000000000..69163ccd51 --- /dev/null +++ b/patches/server/Add-CartographyItemEvent.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Janet Blackquill +Date: Sun, 7 Apr 2024 16:52:42 -0400 +Subject: [PATCH] Add CartographyItemEvent + + +diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + } + } + ++ // Paper start - cartography item event ++ if (packet.getSlotNum() == net.minecraft.world.inventory.CartographyTableMenu.RESULT_SLOT && top instanceof org.bukkit.inventory.CartographyInventory cartographyInventory) { ++ org.bukkit.inventory.ItemStack result = cartographyInventory.getResult(); ++ if (result != null && !result.isEmpty()) { ++ if (click == ClickType.NUMBER_KEY) { ++ event = new io.papermc.paper.event.player.CartographyItemEvent(inventory, type, packet.getSlotNum(), click, action, packet.getButtonNum()); ++ } else { ++ event = new io.papermc.paper.event.player.CartographyItemEvent(inventory, type, packet.getSlotNum(), click, action); ++ } ++ } ++ } ++ // Paper end - cartography item event ++ + event.setCancelled(cancelled); + AbstractContainerMenu oldContainer = this.player.containerMenu; // SPIGOT-1224 + this.cserver.getPluginManager().callEvent(event); +diff --git a/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java b/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java ++++ b/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java +@@ -0,0 +0,0 @@ public class CartographyTableMenu extends AbstractContainerMenu { + this.resultContainer = new ResultContainer(this.createBlockHolder(context)) { // Paper - Add missing InventoryHolders + @Override + public void setChanged() { +- CartographyTableMenu.this.slotsChanged(this); ++ // CartographyTableMenu.this.slotsChanged(this); // Paper - Add CatographyItemEvent - do not recompute results if the result slot changes - allows to set the result slot via api + super.setChanged(); + } +