Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.craftbukkit.inventory;
2
3import net.minecraft.server.CraftingManager;
4import org.bukkit.inventory.ItemStack;
5import org.bukkit.inventory.ShapedRecipe;
6import org.bukkit.material.MaterialData;
7
8import java.util.HashMap;
9
10public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
11 public CraftShapedRecipe(ItemStack result) {
12 super(result);
13 }
14
15 public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) {
16 if (recipe instanceof CraftShapedRecipe) {
17 return (CraftShapedRecipe) recipe;
18 }
19 CraftShapedRecipe ret = new CraftShapedRecipe(recipe.getResult());
20 String[] shape = recipe.getShape();
21 ret.shape(shape);
22 for (char c : recipe.getIngredientMap().keySet()) {
23 ret.setIngredient(c, recipe.getIngredientMap().get(c));
24 }
25 return ret;
26 }
27
28 public void addToCraftingManager() {
29 Object[] data;
30 String[] shape = this.getShape();
31 HashMap<Character, MaterialData> ingred = this.getIngredientMap();
32 int datalen = shape.length;
33 datalen += ingred.size() * 2;
34 int i = 0;
35 data = new Object[datalen];
36 for (; i < shape.length; i++) {
37 data[i] = shape[i];
38 }
39 for (char c : ingred.keySet()) {
40 data[i] = c;
41 i++;
42 MaterialData mdata = ingred.get(c);
43 int id = mdata.getItemTypeId();
44 byte dmg = mdata.getData();
45 data[i] = new net.minecraft.server.ItemStack(id, 1, dmg);
46 i++;
47 }
48 int id = this.getResult().getTypeId();
49 int amount = this.getResult().getAmount();
50 short durability = this.getResult().getDurability();
51 CraftingManager.getInstance().registerShapedRecipe(new net.minecraft.server.ItemStack(id, amount, durability), data);
52 }
53}