[Bleeding] Recipe API improvements and fixes. Addresses BUKKIT-738 and BUKKIT-624
Add a recipe iterator to make it possible to retrieve and remove recipes (BUKKIT-738), and updated the recipe classes to not clip the data to 127 (BUKKIT-624)
This commit is contained in:
committed by
EvilSeph
parent
84ecdb5439
commit
326091c130
@@ -8,13 +8,13 @@ import java.util.List;
|
||||
public class CraftingManager {
|
||||
|
||||
private static final CraftingManager a = new CraftingManager();
|
||||
private List b = new ArrayList();
|
||||
public List b = new ArrayList(); // CraftBukkit - private -> public
|
||||
|
||||
public static final CraftingManager getInstance() {
|
||||
return a;
|
||||
}
|
||||
|
||||
private CraftingManager() {
|
||||
public CraftingManager() { // CraftBukkit - private -> public
|
||||
(new RecipesTools()).a(this);
|
||||
(new RecipesWeapons()).a(this);
|
||||
(new RecipeIngots()).a(this);
|
||||
@@ -91,10 +91,17 @@ public class CraftingManager {
|
||||
this.registerShapedRecipe(new ItemStack(Item.BED, 1), new Object[] { "###", "XXX", Character.valueOf('#'), Block.WOOL, Character.valueOf('X'), Block.WOOD});
|
||||
this.registerShapedRecipe(new ItemStack(Block.ENCHANTMENT_TABLE, 1), new Object[] { " B ", "D#D", "###", Character.valueOf('#'), Block.OBSIDIAN, Character.valueOf('B'), Item.BOOK, Character.valueOf('D'), Item.DIAMOND});
|
||||
this.registerShapelessRecipe(new ItemStack(Item.EYE_OF_ENDER, 1), new Object[] { Item.ENDER_PEARL, Item.BLAZE_POWDER});
|
||||
Collections.sort(this.b, new RecipeSorter(this));
|
||||
//Collections.sort(this.b, new RecipeSorter(this)); // CraftBukkit - removed; see below
|
||||
this.sort(); // CraftBukkit - moved sort to a separate method
|
||||
System.out.println(this.b.size() + " recipes");
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
public void sort() {
|
||||
Collections.sort(this.b, new RecipeSorter(this));
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public void registerShapedRecipe(ItemStack itemstack, Object... aobject) { // CraftBukkit - default -> public
|
||||
String s = "";
|
||||
int i = 0;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import org.bukkit.inventory.Recipe; // CraftBukkit
|
||||
|
||||
public interface CraftingRecipe {
|
||||
|
||||
boolean a(InventoryCrafting inventorycrafting);
|
||||
@@ -9,4 +11,6 @@ public interface CraftingRecipe {
|
||||
int a();
|
||||
|
||||
ItemStack b();
|
||||
|
||||
Recipe toBukkitRecipe(); // CraftBukkit
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import java.util.Map;
|
||||
public class FurnaceRecipes {
|
||||
|
||||
private static final FurnaceRecipes a = new FurnaceRecipes();
|
||||
private Map b = new HashMap();
|
||||
public Map b = new HashMap(); // CraftBukkit - private -> public
|
||||
|
||||
public static final FurnaceRecipes getInstance() {
|
||||
return a;
|
||||
}
|
||||
|
||||
private FurnaceRecipes() {
|
||||
public FurnaceRecipes() { // CraftBukkit - private -> public
|
||||
this.registerRecipe(Block.IRON_ORE.id, new ItemStack(Item.IRON_INGOT));
|
||||
this.registerRecipe(Block.GOLD_ORE.id, new ItemStack(Item.GOLD_INGOT));
|
||||
this.registerRecipe(Block.DIAMOND_ORE.id, new ItemStack(Item.DIAMOND));
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
// CraftBukkit end
|
||||
|
||||
public class ShapedRecipes implements CraftingRecipe {
|
||||
|
||||
private int b;
|
||||
@@ -16,6 +22,62 @@ public class ShapedRecipes implements CraftingRecipe {
|
||||
this.e = itemstack;
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
public ShapedRecipe toBukkitRecipe() {
|
||||
CraftItemStack result = new CraftItemStack(this.e);
|
||||
CraftShapedRecipe recipe = new CraftShapedRecipe(result, this);
|
||||
switch (this.b) {
|
||||
case 1:
|
||||
switch (this.c) {
|
||||
case 1:
|
||||
recipe.shape("a");
|
||||
break;
|
||||
case 2:
|
||||
recipe.shape("ab");
|
||||
break;
|
||||
case 3:
|
||||
recipe.shape("abc");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (this.c) {
|
||||
case 1:
|
||||
recipe.shape("a","b");
|
||||
break;
|
||||
case 2:
|
||||
recipe.shape("ab","cd");
|
||||
break;
|
||||
case 3:
|
||||
recipe.shape("abc","def");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
switch (this.c) {
|
||||
case 1:
|
||||
recipe.shape("a","b","c");
|
||||
break;
|
||||
case 2:
|
||||
recipe.shape("ab","cd","ef");
|
||||
break;
|
||||
case 3:
|
||||
recipe.shape("abc","def","ghi");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
char c = 'a';
|
||||
for (ItemStack stack : this.d) {
|
||||
if (stack != null) {
|
||||
recipe.setIngredient(c, org.bukkit.Material.getMaterial(stack.id), stack.getData());
|
||||
}
|
||||
c++;
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public ItemStack b() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
// CraftBukkit end
|
||||
|
||||
public class ShapelessRecipes implements CraftingRecipe {
|
||||
|
||||
private final ItemStack a;
|
||||
@@ -14,6 +20,20 @@ public class ShapelessRecipes implements CraftingRecipe {
|
||||
this.b = list;
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
@SuppressWarnings("unchecked")
|
||||
public ShapelessRecipe toBukkitRecipe() {
|
||||
CraftItemStack result = new CraftItemStack(this.a);
|
||||
CraftShapelessRecipe recipe = new CraftShapelessRecipe(result, this);
|
||||
for (ItemStack stack : (List<ItemStack>) this.b) {
|
||||
if (stack != null) {
|
||||
recipe.addIngredient(org.bukkit.Material.getMaterial(stack.id), stack.getData());
|
||||
}
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public ItemStack b() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user