Add CartographyItemEvent and get/setResult for CartographyInventory (#10396)

This commit is contained in:
Janet Blackquill 2024-04-20 14:10:35 -04:00 committed by GitHub
parent a033033b7a
commit c5f68ff9be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 121 additions and 2 deletions

View file

@ -3,6 +3,7 @@ From: Nassim Jahnke <nassim@njahnke.dev>
Date: Sat, 25 Apr 2020 23:31:28 +0200
Subject: [PATCH] Add item slot convenience methods
Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
diff --git a/src/main/java/org/bukkit/inventory/AnvilInventory.java b/src/main/java/org/bukkit/inventory/AnvilInventory.java
index 52519cd877017704b53d36088d4d4c28f8f27397..c60be4fd24c7fdf65251dd6169e5e1ac3b588d95 100644
@ -73,6 +74,37 @@ index 52519cd877017704b53d36088d4d4c28f8f27397..c60be4fd24c7fdf65251dd6169e5e1ac
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/inventory/CartographyInventory.java b/src/main/java/org/bukkit/inventory/CartographyInventory.java
index 29c9b2682b92433f468d434d25d3c2495b5ac91b..d040ecea3a086711acbf5a852def090ba6c51fae 100644
--- a/src/main/java/org/bukkit/inventory/CartographyInventory.java
+++ b/src/main/java/org/bukkit/inventory/CartographyInventory.java
@@ -3,4 +3,25 @@ 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 9048892c8768c6b4d6cea03da73339f13bfbe82e..1c750108f55a0a31ad23433b333e0ea486a63ff2 100644
--- a/src/main/java/org/bukkit/inventory/GrindstoneInventory.java

View file

@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Janet Blackquill <uhhadd@gmail.com>
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..659b620696e5cc0784ed707c70876e4348897c7f
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/CartographyItemEvent.java
@@ -0,0 +1,31 @@
+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();
+ }
+}