summaryrefslogtreecommitdiffstats
path: root/nms-patches/CraftingManager.patch
blob: 7435b9f8e3f3319fe9582fca4e8465d7cd3c1956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--- a/net/minecraft/server/CraftingManager.java
+++ b/net/minecraft/server/CraftingManager.java
@@ -9,10 +9,16 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
 public class CraftingManager {
 
     private static final CraftingManager a = new CraftingManager();
     public List<IRecipe> recipes = Lists.newArrayList();
+    // CraftBukkit start
+    public IRecipe lastRecipe;
+    public org.bukkit.inventory.InventoryView lastCraftView;
+    // CraftBukkit end
 
     public static CraftingManager getInstance() {
         return CraftingManager.a;
@@ -32,7 +38,7 @@
         this.recipes.add(new RecipeMapExtend());
         this.recipes.add(new RecipeFireworks());
         this.recipes.add(new RecipeRepair());
-        this.recipes.add(new RecipeTippedArrow());
+        // this.recipes.add(new RecipeTippedArrow());
         (new RecipesBanner()).a(this);
         (new RecipiesShield()).a(this);
         this.registerShapedRecipe(new ItemStack(Items.PAPER, 3), new Object[] { "###", Character.valueOf('#'), Items.REEDS});
@@ -176,7 +182,12 @@
         this.registerShapedRecipe(new ItemStack(Blocks.HOPPER), new Object[] { "I I", "ICI", " I ", Character.valueOf('I'), Items.IRON_INGOT, Character.valueOf('C'), Blocks.CHEST});
         this.registerShapedRecipe(new ItemStack(Items.ARMOR_STAND, 1), new Object[] { "///", " / ", "/_/", Character.valueOf('/'), Items.STICK, Character.valueOf('_'), new ItemStack(Blocks.STONE_SLAB, 1, BlockDoubleStepAbstract.EnumStoneSlabVariant.STONE.a())});
         this.registerShapedRecipe(new ItemStack(Blocks.END_ROD, 4), new Object[] { "/", "#", Character.valueOf('/'), Items.BLAZE_ROD, Character.valueOf('#'), Items.CHORUS_FRUIT_POPPED});
-        Collections.sort(this.recipes, new Comparator() {
+        sort();
+    }
+
+    // CraftBukkit start
+    public void sort() {
+       Collections.sort(this.recipes, new Comparator() {
             public int a(IRecipe irecipe, IRecipe irecipe1) {
                 return irecipe instanceof ShapelessRecipes && irecipe1 instanceof ShapedRecipes ? 1 : (irecipe1 instanceof ShapelessRecipes && irecipe instanceof ShapedRecipes ? -1 : (irecipe1.a() < irecipe.a() ? -1 : (irecipe1.a() > irecipe.a() ? 1 : 0)));
             }
@@ -283,13 +294,18 @@
 
         do {
             if (!iterator.hasNext()) {
+                inventorycrafting.currentRecipe = null; // CraftBukkit - Clear recipe when no recipe is found
                 return null;
             }
 
             irecipe = (IRecipe) iterator.next();
         } while (!irecipe.a(inventorycrafting, world));
 
-        return irecipe.craftItem(inventorycrafting);
+        // CraftBukkit start - INVENTORY_PRE_CRAFT event
+        inventorycrafting.currentRecipe = irecipe;
+        ItemStack result = irecipe.craftItem(inventorycrafting);
+        return CraftEventFactory.callPreCraftEvent(inventorycrafting, result, lastCraftView, false);
+        // CraftBukkit end
     }
 
     public ItemStack[] b(InventoryCrafting inventorycrafting, World world) {