Commits

md_5 authored 4f3946f7ac2
SPIGOT-8003: Fire PrepareItemCraftEvent for Crafter preview
No tags

nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch

Modified
1 1 --- a/net/minecraft/world/inventory/ContainerWorkbench.java
2 2 +++ b/net/minecraft/world/inventory/ContainerWorkbench.java
3 -@@ -16,6 +16,12 @@
3 +@@ -16,6 +16,11 @@
4 4 import net.minecraft.world.item.crafting.Recipes;
5 5 import net.minecraft.world.level.block.Blocks;
6 6
7 7 +// CraftBukkit start
8 -+import net.minecraft.world.item.crafting.RecipeRepair;
9 8 +import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
10 9 +import org.bukkit.craftbukkit.inventory.CraftInventoryView;
11 10 +// CraftBukkit end
12 11 +
13 12 public class ContainerWorkbench extends AbstractCraftingMenu {
14 13
15 14 private static final int CRAFTING_GRID_WIDTH = 3;
16 -@@ -31,13 +37,16 @@
15 +@@ -31,13 +36,16 @@
17 16 public final ContainerAccess access;
18 17 private final EntityHuman player;
19 18 private boolean placingRecipe;
20 19 + // CraftBukkit start
21 20 + private CraftInventoryView bukkitEntity = null;
22 21 + // CraftBukkit end
23 22
24 23 public ContainerWorkbench(int i, PlayerInventory playerinventory) {
25 24 this(i, playerinventory, ContainerAccess.NULL);
26 25 }
27 26
28 27 public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) {
29 28 - super(Containers.CRAFTING, i, 3, 3);
30 29 + super(Containers.CRAFTING, i, 3, 3, playerinventory); // CraftBukkit - pass player
31 30 this.access = containeraccess;
32 31 this.player = playerinventory.player;
33 32 this.addResultSlot(this.player, 124, 35);
34 -@@ -50,6 +59,7 @@
33 +@@ -50,6 +58,7 @@
35 34 EntityPlayer entityplayer = (EntityPlayer) entityhuman;
36 35 ItemStack itemstack = ItemStack.EMPTY;
37 36 Optional<RecipeHolder<RecipeCrafting>> optional = worldserver.getServer().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver, recipeholder);
38 37 + inventorycrafting.setCurrentRecipe(optional.orElse(null)); // CraftBukkit
39 38
40 39 if (optional.isPresent()) {
41 40 RecipeHolder<RecipeCrafting> recipeholder1 = (RecipeHolder) optional.get();
42 -@@ -63,6 +73,7 @@
41 +@@ -63,6 +72,7 @@
43 42 }
44 43 }
45 44 }
46 -+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); // CraftBukkit
45 ++ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional); // CraftBukkit
47 46
48 47 inventorycraftresult.setItem(0, itemstack);
49 48 container.setRemoteSlot(0, itemstack);
50 -@@ -103,6 +114,7 @@
49 +@@ -103,6 +113,7 @@
51 50
52 51 @Override
53 52 public boolean stillValid(EntityHuman entityhuman) {
54 53 + if (!this.checkReachable) return true; // CraftBukkit
55 54 return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE);
56 55 }
57 56
58 -@@ -181,4 +193,17 @@
57 +@@ -181,4 +192,17 @@
59 58 protected EntityHuman owner() {
60 59 return this.player;
61 60 }
62 61 +
63 62 + // CraftBukkit start
64 63 + @Override
65 64 + public CraftInventoryView getBukkitView() {
66 65 + if (bukkitEntity != null) {
67 66 + return bukkitEntity;
68 67 + }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut