From 968bdeb46f9b30aa9959b9bd9c0e89f9b657a191 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Fri, 19 Jul 2024 19:29:31 +0200 Subject: Make CraftComplexRecipe extend CraftingRecipe (#11114) --- patches/api/0481-Add-CrafterCraftEvent.patch | 97 ---------------------- ...aftComplexRecipe-to-extend-CraftingRecipe.patch | 27 ++++++ patches/api/0482-Add-CrafterCraftEvent.patch | 97 ++++++++++++++++++++++ patches/server/1041-Add-CrafterCraftEvent.patch | 31 ------- ...aftComplexRecipe-to-extend-CraftingRecipe.patch | 50 +++++++++++ patches/server/1042-Add-CrafterCraftEvent.patch | 31 +++++++ 6 files changed, 205 insertions(+), 128 deletions(-) delete mode 100644 patches/api/0481-Add-CrafterCraftEvent.patch create mode 100644 patches/api/0481-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch create mode 100644 patches/api/0482-Add-CrafterCraftEvent.patch delete mode 100644 patches/server/1041-Add-CrafterCraftEvent.patch create mode 100644 patches/server/1041-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch create mode 100644 patches/server/1042-Add-CrafterCraftEvent.patch diff --git a/patches/api/0481-Add-CrafterCraftEvent.patch b/patches/api/0481-Add-CrafterCraftEvent.patch deleted file mode 100644 index c91ab8393d..0000000000 --- a/patches/api/0481-Add-CrafterCraftEvent.patch +++ /dev/null @@ -1,97 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: ploppyperson -Date: Thu, 18 Jul 2024 16:37:58 +0200 -Subject: [PATCH] Add CrafterCraftEvent - -Ports the currently proposed CrafterCraftEvent -from upstream. -The type is experimental to account for spigot -potentially changing some api contracts, however -the event is required for a stable release and -waiting on spigot's PR queue is not an option. - -See: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/1044/overview - -diff --git a/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java -new file mode 100644 -index 0000000000000000000000000000000000000000..8dec6d16aa3c3579eadd77f637c9afa54ee9a90f ---- /dev/null -+++ b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java -@@ -0,0 +1,77 @@ -+package org.bukkit.event.block; -+ -+import org.bukkit.block.Block; -+import org.bukkit.event.Cancellable; -+import org.bukkit.event.HandlerList; -+import org.bukkit.inventory.CraftingRecipe; -+import org.bukkit.inventory.ItemStack; -+import org.jetbrains.annotations.NotNull; -+ -+/** -+ * Event called when a Crafter is about to craft an item -+ * @apiNote Currently still experimental as it is ported from an open, not merged, spigot PR. -+ * The event was pulled to allow protection plugins and the likes to properly manage crafters. -+ * The type remains experimental as upstream *may* change the event before pulling it, resulting in a breaking change. -+ */ -+@org.jetbrains.annotations.ApiStatus.Experimental -+public class CrafterCraftEvent extends BlockEvent implements Cancellable { -+ -+ private static final HandlerList handlers = new HandlerList(); -+ private boolean cancelled; -+ private ItemStack result; -+ private final CraftingRecipe recipe; -+ -+ @org.jetbrains.annotations.ApiStatus.Internal // Paper - internal constructor. -+ public CrafterCraftEvent(@NotNull Block theBlock, @NotNull CraftingRecipe recipe, @NotNull ItemStack result) { -+ super(theBlock); -+ this.result = result; -+ this.recipe = recipe; -+ } -+ -+ /** -+ * Gets the result for the craft -+ * @return the result for the craft -+ */ -+ @NotNull -+ public ItemStack getResult() { -+ return result.clone(); -+ } -+ -+ /** -+ * Sets the result of the craft -+ * @param result the result of the craft -+ */ -+ public void setResult(@NotNull ItemStack result) { -+ this.result = result.clone(); -+ } -+ -+ /** -+ * The recipe that was used to craft this item -+ * @return the recipe that was used to craft this item -+ */ -+ @NotNull -+ public CraftingRecipe getRecipe() { -+ return recipe; -+ } -+ -+ @NotNull -+ @Override -+ public HandlerList getHandlers() { -+ return handlers; -+ } -+ -+ @Override -+ public boolean isCancelled() { -+ return cancelled; -+ } -+ -+ @Override -+ public void setCancelled(boolean cancel) { -+ this.cancelled = cancel; -+ } -+ -+ @NotNull -+ public static HandlerList getHandlerList() { -+ return handlers; -+ } -+} diff --git a/patches/api/0481-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch b/patches/api/0481-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch new file mode 100644 index 0000000000..7bf99722cc --- /dev/null +++ b/patches/api/0481-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Fri, 19 Jul 2024 19:09:21 +0200 +Subject: [PATCH] Move CraftComplexRecipe to extend CraftingRecipe + +A craft complex recipe wraps a CustomRecipe, which itself is a +CraftingRecipe. +As such, this complex recipe should also be a crafting recipe. + +diff --git a/src/main/java/org/bukkit/inventory/CraftingRecipe.java b/src/main/java/org/bukkit/inventory/CraftingRecipe.java +index 37024b4736dd3897490ca51d08cf07901b01d59f..afa3de9ab78d01c448d450d8afbc7b1e7e62754c 100644 +--- a/src/main/java/org/bukkit/inventory/CraftingRecipe.java ++++ b/src/main/java/org/bukkit/inventory/CraftingRecipe.java +@@ -11,8 +11,11 @@ import org.jetbrains.annotations.NotNull; + * Represents a shaped or shapeless crafting recipe. + */ + public abstract class CraftingRecipe implements Recipe, Keyed { +- private final NamespacedKey key; +- private final ItemStack output; ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - start ++ protected NamespacedKey key; ++ protected ItemStack output; ++ protected CraftingRecipe() {} ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - end + private String group = ""; + private CraftingBookCategory category = CraftingBookCategory.MISC; + diff --git a/patches/api/0482-Add-CrafterCraftEvent.patch b/patches/api/0482-Add-CrafterCraftEvent.patch new file mode 100644 index 0000000000..c91ab8393d --- /dev/null +++ b/patches/api/0482-Add-CrafterCraftEvent.patch @@ -0,0 +1,97 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ploppyperson +Date: Thu, 18 Jul 2024 16:37:58 +0200 +Subject: [PATCH] Add CrafterCraftEvent + +Ports the currently proposed CrafterCraftEvent +from upstream. +The type is experimental to account for spigot +potentially changing some api contracts, however +the event is required for a stable release and +waiting on spigot's PR queue is not an option. + +See: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/1044/overview + +diff --git a/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..8dec6d16aa3c3579eadd77f637c9afa54ee9a90f +--- /dev/null ++++ b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java +@@ -0,0 +1,77 @@ ++package org.bukkit.event.block; ++ ++import org.bukkit.block.Block; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.inventory.CraftingRecipe; ++import org.bukkit.inventory.ItemStack; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Event called when a Crafter is about to craft an item ++ * @apiNote Currently still experimental as it is ported from an open, not merged, spigot PR. ++ * The event was pulled to allow protection plugins and the likes to properly manage crafters. ++ * The type remains experimental as upstream *may* change the event before pulling it, resulting in a breaking change. ++ */ ++@org.jetbrains.annotations.ApiStatus.Experimental ++public class CrafterCraftEvent extends BlockEvent implements Cancellable { ++ ++ private static final HandlerList handlers = new HandlerList(); ++ private boolean cancelled; ++ private ItemStack result; ++ private final CraftingRecipe recipe; ++ ++ @org.jetbrains.annotations.ApiStatus.Internal // Paper - internal constructor. ++ public CrafterCraftEvent(@NotNull Block theBlock, @NotNull CraftingRecipe recipe, @NotNull ItemStack result) { ++ super(theBlock); ++ this.result = result; ++ this.recipe = recipe; ++ } ++ ++ /** ++ * Gets the result for the craft ++ * @return the result for the craft ++ */ ++ @NotNull ++ public ItemStack getResult() { ++ return result.clone(); ++ } ++ ++ /** ++ * Sets the result of the craft ++ * @param result the result of the craft ++ */ ++ public void setResult(@NotNull ItemStack result) { ++ this.result = result.clone(); ++ } ++ ++ /** ++ * The recipe that was used to craft this item ++ * @return the recipe that was used to craft this item ++ */ ++ @NotNull ++ public CraftingRecipe getRecipe() { ++ return recipe; ++ } ++ ++ @NotNull ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancelled = cancel; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} diff --git a/patches/server/1041-Add-CrafterCraftEvent.patch b/patches/server/1041-Add-CrafterCraftEvent.patch deleted file mode 100644 index 28eb5f5746..0000000000 --- a/patches/server/1041-Add-CrafterCraftEvent.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: ploppyperson -Date: Thu, 18 Jul 2024 16:38:48 +0200 -Subject: [PATCH] Add CrafterCraftEvent - -While not a one-to-one copy from the proposed commit upstream, -the patch calls the preemtively pulled CrafterCraftEvent. - -See: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/1450/overview - -diff --git a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java -index 6c24b25a7c8ce6e34aceb5702f1a0a6732ebca44..391a6af36d4c27a04000b31583297a25b89125d3 100644 ---- a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java -+++ b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java -@@ -163,6 +163,16 @@ public class CrafterBlock extends BaseEntityBlock { - } else { - RecipeHolder recipeHolder = optional.get(); - ItemStack itemStack = recipeHolder.value().assemble(var11, world.registryAccess()); -+ // Paper start - call CrafterCraftEvent -+ final org.bukkit.event.block.CrafterCraftEvent event = new org.bukkit.event.block.CrafterCraftEvent( -+ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos), -+ (org.bukkit.inventory.CraftingRecipe) recipeHolder.toBukkitRecipe(), -+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack) -+ ); -+ if (!event.callEvent()) return; -+ -+ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); -+ // Paper end - call CrafterCraftEvent - if (itemStack.isEmpty()) { - world.levelEvent(1050, pos, 0); - } else { diff --git a/patches/server/1041-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch b/patches/server/1041-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch new file mode 100644 index 0000000000..3e85c7f987 --- /dev/null +++ b/patches/server/1041-Move-CraftComplexRecipe-to-extend-CraftingRecipe.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Fri, 19 Jul 2024 17:27:38 +0200 +Subject: [PATCH] Move CraftComplexRecipe to extend CraftingRecipe + +A craft complex recipe wraps a CustomRecipe, which itself is a +CraftingRecipe. +As such, this complex recipe should also be a crafting recipe. + +diff --git a/src/main/java/net/minecraft/world/item/crafting/CustomRecipe.java b/src/main/java/net/minecraft/world/item/crafting/CustomRecipe.java +index b57a2ba09f160409b5df9a2ae7ec159af3e4bf93..69a7e500c725e9da950df30f2cc4ff5f72e527d0 100644 +--- a/src/main/java/net/minecraft/world/item/crafting/CustomRecipe.java ++++ b/src/main/java/net/minecraft/world/item/crafting/CustomRecipe.java +@@ -34,7 +34,12 @@ public abstract class CustomRecipe implements CraftingRecipe { + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { +- return new org.bukkit.craftbukkit.inventory.CraftComplexRecipe(id, this); ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - start ++ final org.bukkit.craftbukkit.inventory.CraftComplexRecipe recipe = new org.bukkit.craftbukkit.inventory.CraftComplexRecipe(id, this); ++ recipe.setGroup(this.getGroup()); ++ recipe.setCategory(org.bukkit.craftbukkit.inventory.CraftRecipe.getCategory(this.category())); ++ return recipe; ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - end + } + // CraftBukkit end + } +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java +index dcaeaa3367351eb54e2cf8e62be19ecc125a4bb4..05f42ec6177218960b22dc2c224f63cbf37d696f 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java +@@ -9,12 +9,17 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey; + import org.bukkit.inventory.ComplexRecipe; + import org.bukkit.inventory.ItemStack; + +-public class CraftComplexRecipe implements CraftRecipe, ComplexRecipe { ++public class CraftComplexRecipe extends org.bukkit.inventory.CraftingRecipe implements CraftRecipe, ComplexRecipe { // Paper - make CraftComplexRecipe extend CraftingRecipe + + private final NamespacedKey key; + private final CustomRecipe recipe; + + public CraftComplexRecipe(NamespacedKey key, CustomRecipe recipe) { ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - start ++ super(); ++ super.key = key; ++ super.output = ItemStack.empty(); ++ // Paper - make CraftComplexRecipe extend CraftingRecipe - end + this.key = key; + this.recipe = recipe; + } diff --git a/patches/server/1042-Add-CrafterCraftEvent.patch b/patches/server/1042-Add-CrafterCraftEvent.patch new file mode 100644 index 0000000000..28eb5f5746 --- /dev/null +++ b/patches/server/1042-Add-CrafterCraftEvent.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ploppyperson +Date: Thu, 18 Jul 2024 16:38:48 +0200 +Subject: [PATCH] Add CrafterCraftEvent + +While not a one-to-one copy from the proposed commit upstream, +the patch calls the preemtively pulled CrafterCraftEvent. + +See: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/1450/overview + +diff --git a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java +index 6c24b25a7c8ce6e34aceb5702f1a0a6732ebca44..391a6af36d4c27a04000b31583297a25b89125d3 100644 +--- a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java +@@ -163,6 +163,16 @@ public class CrafterBlock extends BaseEntityBlock { + } else { + RecipeHolder recipeHolder = optional.get(); + ItemStack itemStack = recipeHolder.value().assemble(var11, world.registryAccess()); ++ // Paper start - call CrafterCraftEvent ++ final org.bukkit.event.block.CrafterCraftEvent event = new org.bukkit.event.block.CrafterCraftEvent( ++ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos), ++ (org.bukkit.inventory.CraftingRecipe) recipeHolder.toBukkitRecipe(), ++ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack) ++ ); ++ if (!event.callEvent()) return; ++ ++ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); ++ // Paper end - call CrafterCraftEvent + if (itemStack.isEmpty()) { + world.levelEvent(1050, pos, 0); + } else { -- cgit v1.2.3