From ef9a371e834483b7c376b40a1c7eda35caf67c59 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Mon, 15 Jul 2024 12:28:03 +0200 Subject: [PATCH 1/6] Add CrafterCraftItemEvent Adds an event fired when the crafter crafts an item. The event only exposes the recipe and the potential result for event modifications. --- .../api/0481-Add-CrafterCraftItemEvent.patch | 119 ++++++++++++++++++ .../1041-Add-CrafterCraftItemEvent.patch | 32 +++++ 2 files changed, 151 insertions(+) create mode 100644 patches/api/0481-Add-CrafterCraftItemEvent.patch create mode 100644 patches/server/1041-Add-CrafterCraftItemEvent.patch diff --git a/patches/api/0481-Add-CrafterCraftItemEvent.patch b/patches/api/0481-Add-CrafterCraftItemEvent.patch new file mode 100644 index 000000000000..966fd2accc9b --- /dev/null +++ b/patches/api/0481-Add-CrafterCraftItemEvent.patch @@ -0,0 +1,119 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Mon, 15 Jul 2024 12:27:39 +0200 +Subject: [PATCH] Add CrafterCraftItemEvent + +Adds an event fired when the crafter crafts an item. +The event only exposes the recipe and the potential result +for event modifications. + +The patch may be expanded in the future for more crafter related +event calls. + +diff --git a/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..6aec8f56a55c97b13b4e401968f36e301ee021e5 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java +@@ -0,0 +1,101 @@ ++package io.papermc.paper.event.block; ++ ++import com.google.common.base.Preconditions; ++import org.bukkit.block.Block; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.block.BlockEvent; ++import org.bukkit.inventory.ItemStack; ++import org.bukkit.inventory.Recipe; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * The crafter craft event is called when a crafter is crafting an item. ++ *

++ * The crafter instance may be accessed via {@link #getBlock()}'s {@link Block#getState(boolean)}. ++ */ ++public class CrafterCraftEvent extends BlockEvent implements Cancellable { ++ ++ private final Recipe recipe; ++ private ItemStack result; ++ private boolean isCancelled; ++ ++ @ApiStatus.Internal ++ public CrafterCraftEvent( ++ final @NotNull Block theBlock, ++ final @NotNull Recipe recipe, ++ final @NotNull ItemStack result ++ ) { ++ super(theBlock); ++ this.recipe = recipe; ++ this.result = result; ++ } ++ ++ /** ++ * Yields the recipe crafted by the crafted. ++ * ++ * @return the recipe. ++ */ ++ @NotNull ++ public Recipe getRecipe() { ++ return this.recipe; ++ } ++ ++ /** ++ * Returns the resulting item the crafter is about to craft. ++ *

++ * This method may yield a mutated itemstack if other event handlers called {@link #setResult(ItemStack)}. ++ * To retrieve the original result, see {@link #getRecipe()}'s {@link Recipe#getResult()}. ++ * ++ * @return a copy of the result. Modifying said item will not mutate this event or item the crafter crafts. ++ */ ++ @NotNull ++ public ItemStack getResult() { ++ return this.result.clone(); ++ } ++ ++ /** ++ * Sets the itemstack the crafter crafted. ++ * ++ * @param itemStack the itemstack the crafter is crafting. ++ */ ++ public void setResult(final @NotNull ItemStack itemStack) { ++ Preconditions.checkArgument(itemStack != null, "Cannot set crafter craft result to null"); ++ this.result = itemStack.clone(); ++ } ++ ++ /** ++ * Sets if this event is cancelled. ++ *

++ * Cancelling this event prevents the crafter from crafting, leaving its inventory untouched. ++ * ++ * @param cancel true if you wish to cancel this event ++ */ ++ @Override ++ public void setCancelled(final boolean cancel) { ++ this.isCancelled = cancel; ++ } ++ ++ /** ++ * Returns if the event is cancelled. ++ * ++ * @return {@code true} if the event is cancelled, {@code false} otherwise. ++ */ ++ @Override ++ public boolean isCancelled() { ++ return this.isCancelled; ++ } ++ ++ private static final HandlerList HANDLER_LIST = new HandlerList(); ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return HANDLER_LIST; ++ } ++ ++ @Override ++ public @NotNull HandlerList getHandlers() { ++ return HANDLER_LIST; ++ } ++} diff --git a/patches/server/1041-Add-CrafterCraftItemEvent.patch b/patches/server/1041-Add-CrafterCraftItemEvent.patch new file mode 100644 index 000000000000..a066c0463e17 --- /dev/null +++ b/patches/server/1041-Add-CrafterCraftItemEvent.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Mon, 15 Jul 2024 15:25:15 +0200 +Subject: [PATCH] Add CrafterCraftItemEvent + +Adds an event fired when the crafter crafts an item. +The event only exposes the recipe and the potential result +for event modifications. + +The patch may be expanded in the future for more crafter related +event calls. + +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..e05f69884ace9150a39e9347903e4985435c2203 100644 +--- a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java +@@ -166,6 +166,15 @@ public class CrafterBlock extends BaseEntityBlock { + if (itemStack.isEmpty()) { + world.levelEvent(1050, pos, 0); + } else { ++ // Paper start - add CrafterCraftEvent - fire event ++ final io.papermc.paper.event.block.CrafterCraftEvent event = new io.papermc.paper.event.block.CrafterCraftEvent( ++ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos), recipeHolder.toBukkitRecipe(), org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemStack) ++ ); ++ if (!event.callEvent()) return; ++ ++ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); ++ // Paper end - add CrafterCraftEvent - fire event ++ + crafterBlockEntity.setCraftingTicksRemaining(6); + world.setBlock(pos, state.setValue(CRAFTING, Boolean.valueOf(true)), 2); + itemStack.onCraftedBySystem(world); From 90da990bd6b7f2925cd6f5711003dca34f7492ff Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Mon, 15 Jul 2024 16:29:21 +0200 Subject: [PATCH 2/6] Javadocs improvement as per review --- patches/api/0481-Add-CrafterCraftItemEvent.patch | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/patches/api/0481-Add-CrafterCraftItemEvent.patch b/patches/api/0481-Add-CrafterCraftItemEvent.patch index 966fd2accc9b..b2195552db16 100644 --- a/patches/api/0481-Add-CrafterCraftItemEvent.patch +++ b/patches/api/0481-Add-CrafterCraftItemEvent.patch @@ -12,10 +12,10 @@ event calls. diff --git a/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java new file mode 100644 -index 0000000000000000000000000000000000000000..6aec8f56a55c97b13b4e401968f36e301ee021e5 +index 0000000000000000000000000000000000000000..40a67f1c9de3fb213dbffd6c7c777b696694f294 --- /dev/null +++ b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java -@@ -0,0 +1,101 @@ +@@ -0,0 +1,105 @@ +package io.papermc.paper.event.block; + +import com.google.common.base.Preconditions; @@ -51,7 +51,7 @@ index 0000000000000000000000000000000000000000..6aec8f56a55c97b13b4e401968f36e30 + } + + /** -+ * Yields the recipe crafted by the crafted. ++ * Yields the recipe crafted by the crafter. + * + * @return the recipe. + */ @@ -66,7 +66,8 @@ index 0000000000000000000000000000000000000000..6aec8f56a55c97b13b4e401968f36e30 + * This method may yield a mutated itemstack if other event handlers called {@link #setResult(ItemStack)}. + * To retrieve the original result, see {@link #getRecipe()}'s {@link Recipe#getResult()}. + * -+ * @return a copy of the result. Modifying said item will not mutate this event or item the crafter crafts. ++ * @return a copy of the result. Modifying said itemstack will not mutate this event or itemstack the ++ * crafter crafts. + */ + @NotNull + public ItemStack getResult() { @@ -76,6 +77,9 @@ index 0000000000000000000000000000000000000000..6aec8f56a55c97b13b4e401968f36e30 + /** + * Sets the itemstack the crafter crafted. + * ++ * The crafter will still consume the itemstacks found inside of it according to the original {@link #getRecipe()} ++ * however, it will dispense the passed itemstack instead of the usual recipes result. ++ * + * @param itemStack the itemstack the crafter is crafting. + */ + public void setResult(final @NotNull ItemStack itemStack) { From 944dbbdae54815e363b155f6d02ce1aef1dfb9e2 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Mon, 15 Jul 2024 16:54:17 +0200 Subject: [PATCH 3/6] Important formatting changes --- patches/api/0481-Add-CrafterCraftItemEvent.patch | 6 +++--- ...ItemEvent.patch => 1042-Add-CrafterCraftItemEvent.patch} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename patches/server/{1041-Add-CrafterCraftItemEvent.patch => 1042-Add-CrafterCraftItemEvent.patch} (88%) diff --git a/patches/api/0481-Add-CrafterCraftItemEvent.patch b/patches/api/0481-Add-CrafterCraftItemEvent.patch index b2195552db16..2a1c75d7e5e0 100644 --- a/patches/api/0481-Add-CrafterCraftItemEvent.patch +++ b/patches/api/0481-Add-CrafterCraftItemEvent.patch @@ -12,7 +12,7 @@ event calls. diff --git a/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java new file mode 100644 -index 0000000000000000000000000000000000000000..40a67f1c9de3fb213dbffd6c7c777b696694f294 +index 0000000000000000000000000000000000000000..5a7611f0b70012ae2aeac7a6e81e91a9caa40bb2 --- /dev/null +++ b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java @@ -0,0 +1,105 @@ @@ -76,7 +76,7 @@ index 0000000000000000000000000000000000000000..40a67f1c9de3fb213dbffd6c7c777b69 + + /** + * Sets the itemstack the crafter crafted. -+ * ++ *

+ * The crafter will still consume the itemstacks found inside of it according to the original {@link #getRecipe()} + * however, it will dispense the passed itemstack instead of the usual recipes result. + * @@ -92,7 +92,7 @@ index 0000000000000000000000000000000000000000..40a67f1c9de3fb213dbffd6c7c777b69 + *

+ * Cancelling this event prevents the crafter from crafting, leaving its inventory untouched. + * -+ * @param cancel true if you wish to cancel this event ++ * @param cancel {@code true} if you wish to cancel this event + */ + @Override + public void setCancelled(final boolean cancel) { diff --git a/patches/server/1041-Add-CrafterCraftItemEvent.patch b/patches/server/1042-Add-CrafterCraftItemEvent.patch similarity index 88% rename from patches/server/1041-Add-CrafterCraftItemEvent.patch rename to patches/server/1042-Add-CrafterCraftItemEvent.patch index a066c0463e17..2bf7730003cb 100644 --- a/patches/server/1041-Add-CrafterCraftItemEvent.patch +++ b/patches/server/1042-Add-CrafterCraftItemEvent.patch @@ -11,7 +11,7 @@ The patch may be expanded in the future for more crafter related event calls. 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..e05f69884ace9150a39e9347903e4985435c2203 100644 +index 6c24b25a7c8ce6e34aceb5702f1a0a6732ebca44..1f5621d7f256c225bc410c1cdaecbcea0c5cd9a1 100644 --- a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java +++ b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java @@ -166,6 +166,15 @@ public class CrafterBlock extends BaseEntityBlock { @@ -24,7 +24,7 @@ index 6c24b25a7c8ce6e34aceb5702f1a0a6732ebca44..e05f69884ace9150a39e9347903e4985 + ); + if (!event.callEvent()) return; + -+ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); ++ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); + // Paper end - add CrafterCraftEvent - fire event + crafterBlockEntity.setCraftingTicksRemaining(6); From 306318db500327f8765f207dc514c34458875814 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Thu, 18 Jul 2024 16:21:56 +0200 Subject: [PATCH 4/6] Replace with upstream event --- patches/api/0481-Add-CrafterCraftEvent.patch | 93 +++++++++++++ .../api/0481-Add-CrafterCraftItemEvent.patch | 123 ------------------ .../server/1041-Add-CrafterCraftEvent.patch | 27 ++++ .../1042-Add-CrafterCraftItemEvent.patch | 32 ----- 4 files changed, 120 insertions(+), 155 deletions(-) create mode 100644 patches/api/0481-Add-CrafterCraftEvent.patch delete mode 100644 patches/api/0481-Add-CrafterCraftItemEvent.patch create mode 100644 patches/server/1041-Add-CrafterCraftEvent.patch delete mode 100644 patches/server/1042-Add-CrafterCraftItemEvent.patch diff --git a/patches/api/0481-Add-CrafterCraftEvent.patch b/patches/api/0481-Add-CrafterCraftEvent.patch new file mode 100644 index 000000000000..a7f32111e238 --- /dev/null +++ b/patches/api/0481-Add-CrafterCraftEvent.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ploppyperson +Date: Thu, 18 Jul 2024 16:37:58 +0200 +Subject: [PATCH] Add CrafterCraftEvent + +This patch is ported from an existing spigot PR as +paper requires this event for a stable 1.21 release. +Instead of introducing a paper-namespaced event in the +io.papermc.event package, this option was chosen to have +as minimal conflict as possible when upstream merges the +PR this patch is taken from. + +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..250dc5f7f5ffd2a53f140602d87908804994518f +--- /dev/null ++++ b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java +@@ -0,0 +1,73 @@ ++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 ++ */ ++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-Add-CrafterCraftItemEvent.patch b/patches/api/0481-Add-CrafterCraftItemEvent.patch deleted file mode 100644 index 2a1c75d7e5e0..000000000000 --- a/patches/api/0481-Add-CrafterCraftItemEvent.patch +++ /dev/null @@ -1,123 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll -Date: Mon, 15 Jul 2024 12:27:39 +0200 -Subject: [PATCH] Add CrafterCraftItemEvent - -Adds an event fired when the crafter crafts an item. -The event only exposes the recipe and the potential result -for event modifications. - -The patch may be expanded in the future for more crafter related -event calls. - -diff --git a/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java -new file mode 100644 -index 0000000000000000000000000000000000000000..5a7611f0b70012ae2aeac7a6e81e91a9caa40bb2 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/event/block/CrafterCraftEvent.java -@@ -0,0 +1,105 @@ -+package io.papermc.paper.event.block; -+ -+import com.google.common.base.Preconditions; -+import org.bukkit.block.Block; -+import org.bukkit.event.Cancellable; -+import org.bukkit.event.HandlerList; -+import org.bukkit.event.block.BlockEvent; -+import org.bukkit.inventory.ItemStack; -+import org.bukkit.inventory.Recipe; -+import org.jetbrains.annotations.ApiStatus; -+import org.jetbrains.annotations.NotNull; -+ -+/** -+ * The crafter craft event is called when a crafter is crafting an item. -+ *

-+ * The crafter instance may be accessed via {@link #getBlock()}'s {@link Block#getState(boolean)}. -+ */ -+public class CrafterCraftEvent extends BlockEvent implements Cancellable { -+ -+ private final Recipe recipe; -+ private ItemStack result; -+ private boolean isCancelled; -+ -+ @ApiStatus.Internal -+ public CrafterCraftEvent( -+ final @NotNull Block theBlock, -+ final @NotNull Recipe recipe, -+ final @NotNull ItemStack result -+ ) { -+ super(theBlock); -+ this.recipe = recipe; -+ this.result = result; -+ } -+ -+ /** -+ * Yields the recipe crafted by the crafter. -+ * -+ * @return the recipe. -+ */ -+ @NotNull -+ public Recipe getRecipe() { -+ return this.recipe; -+ } -+ -+ /** -+ * Returns the resulting item the crafter is about to craft. -+ *

-+ * This method may yield a mutated itemstack if other event handlers called {@link #setResult(ItemStack)}. -+ * To retrieve the original result, see {@link #getRecipe()}'s {@link Recipe#getResult()}. -+ * -+ * @return a copy of the result. Modifying said itemstack will not mutate this event or itemstack the -+ * crafter crafts. -+ */ -+ @NotNull -+ public ItemStack getResult() { -+ return this.result.clone(); -+ } -+ -+ /** -+ * Sets the itemstack the crafter crafted. -+ *

-+ * The crafter will still consume the itemstacks found inside of it according to the original {@link #getRecipe()} -+ * however, it will dispense the passed itemstack instead of the usual recipes result. -+ * -+ * @param itemStack the itemstack the crafter is crafting. -+ */ -+ public void setResult(final @NotNull ItemStack itemStack) { -+ Preconditions.checkArgument(itemStack != null, "Cannot set crafter craft result to null"); -+ this.result = itemStack.clone(); -+ } -+ -+ /** -+ * Sets if this event is cancelled. -+ *

-+ * Cancelling this event prevents the crafter from crafting, leaving its inventory untouched. -+ * -+ * @param cancel {@code true} if you wish to cancel this event -+ */ -+ @Override -+ public void setCancelled(final boolean cancel) { -+ this.isCancelled = cancel; -+ } -+ -+ /** -+ * Returns if the event is cancelled. -+ * -+ * @return {@code true} if the event is cancelled, {@code false} otherwise. -+ */ -+ @Override -+ public boolean isCancelled() { -+ return this.isCancelled; -+ } -+ -+ private static final HandlerList HANDLER_LIST = new HandlerList(); -+ -+ @NotNull -+ public static HandlerList getHandlerList() { -+ return HANDLER_LIST; -+ } -+ -+ @Override -+ public @NotNull HandlerList getHandlers() { -+ return HANDLER_LIST; -+ } -+} diff --git a/patches/server/1041-Add-CrafterCraftEvent.patch b/patches/server/1041-Add-CrafterCraftEvent.patch new file mode 100644 index 000000000000..79201df6dcd0 --- /dev/null +++ b/patches/server/1041-Add-CrafterCraftEvent.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Thu, 18 Jul 2024 16:38:48 +0200 +Subject: [PATCH] Add CrafterCraftEvent + + +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/1042-Add-CrafterCraftItemEvent.patch b/patches/server/1042-Add-CrafterCraftItemEvent.patch deleted file mode 100644 index 2bf7730003cb..000000000000 --- a/patches/server/1042-Add-CrafterCraftItemEvent.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll -Date: Mon, 15 Jul 2024 15:25:15 +0200 -Subject: [PATCH] Add CrafterCraftItemEvent - -Adds an event fired when the crafter crafts an item. -The event only exposes the recipe and the potential result -for event modifications. - -The patch may be expanded in the future for more crafter related -event calls. - -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..1f5621d7f256c225bc410c1cdaecbcea0c5cd9a1 100644 ---- a/src/main/java/net/minecraft/world/level/block/CrafterBlock.java -+++ b/src/main/java/net/minecraft/world/level/block/CrafterBlock.java -@@ -166,6 +166,15 @@ public class CrafterBlock extends BaseEntityBlock { - if (itemStack.isEmpty()) { - world.levelEvent(1050, pos, 0); - } else { -+ // Paper start - add CrafterCraftEvent - fire event -+ final io.papermc.paper.event.block.CrafterCraftEvent event = new io.papermc.paper.event.block.CrafterCraftEvent( -+ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos), recipeHolder.toBukkitRecipe(), org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemStack) -+ ); -+ if (!event.callEvent()) return; -+ -+ itemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getResult()); -+ // Paper end - add CrafterCraftEvent - fire event -+ - crafterBlockEntity.setCraftingTicksRemaining(6); - world.setBlock(pos, state.setValue(CRAFTING, Boolean.valueOf(true)), 2); - itemStack.onCraftedBySystem(world); From f7851eb50dd1acab1cfdb721fde2f8502e534413 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Thu, 18 Jul 2024 16:54:55 +0200 Subject: [PATCH 5/6] Mark as experimental --- patches/api/0481-Add-CrafterCraftEvent.patch | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/patches/api/0481-Add-CrafterCraftEvent.patch b/patches/api/0481-Add-CrafterCraftEvent.patch index a7f32111e238..5ef230294f9f 100644 --- a/patches/api/0481-Add-CrafterCraftEvent.patch +++ b/patches/api/0481-Add-CrafterCraftEvent.patch @@ -1,23 +1,15 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: ploppyperson +From: Bjarne Koll Date: Thu, 18 Jul 2024 16:37:58 +0200 Subject: [PATCH] Add CrafterCraftEvent -This patch is ported from an existing spigot PR as -paper requires this event for a stable 1.21 release. -Instead of introducing a paper-namespaced event in the -io.papermc.event package, this option was chosen to have -as minimal conflict as possible when upstream merges the -PR this patch is taken from. - -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..250dc5f7f5ffd2a53f140602d87908804994518f +index 0000000000000000000000000000000000000000..8dec6d16aa3c3579eadd77f637c9afa54ee9a90f --- /dev/null +++ b/src/main/java/org/bukkit/event/block/CrafterCraftEvent.java -@@ -0,0 +1,73 @@ +@@ -0,0 +1,77 @@ +package org.bukkit.event.block; + +import org.bukkit.block.Block; @@ -29,7 +21,11 @@ index 0000000000000000000000000000000000000000..250dc5f7f5ffd2a53f140602d8790880 + +/** + * 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(); From 3161d1d938b2b86f57a6497bffdb57c8b9afb207 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Fri, 19 Jul 2024 10:00:25 +0200 Subject: [PATCH 6/6] Fix author --- patches/api/0481-Add-CrafterCraftEvent.patch | 10 +++++++++- patches/server/1041-Add-CrafterCraftEvent.patch | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/patches/api/0481-Add-CrafterCraftEvent.patch b/patches/api/0481-Add-CrafterCraftEvent.patch index 5ef230294f9f..c91ab8393dff 100644 --- a/patches/api/0481-Add-CrafterCraftEvent.patch +++ b/patches/api/0481-Add-CrafterCraftEvent.patch @@ -1,8 +1,16 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll +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 diff --git a/patches/server/1041-Add-CrafterCraftEvent.patch b/patches/server/1041-Add-CrafterCraftEvent.patch index 79201df6dcd0..28eb5f574673 100644 --- a/patches/server/1041-Add-CrafterCraftEvent.patch +++ b/patches/server/1041-Add-CrafterCraftEvent.patch @@ -1,8 +1,12 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll +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