[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
@@ -2,18 +2,12 @@ package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import net.minecraft.server.FurnaceRecipes;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||
public CraftFurnaceRecipe(ItemStack result, Material source) {
|
||||
super(result, source);
|
||||
}
|
||||
|
||||
public CraftFurnaceRecipe(ItemStack result, MaterialData source) {
|
||||
super(result, source);
|
||||
public CraftFurnaceRecipe(ItemStack result, ItemStack source) {
|
||||
super(result, source.getType(), source.getDurability());
|
||||
}
|
||||
|
||||
public static CraftFurnaceRecipe fromBukkitRecipe(FurnaceRecipe recipe) {
|
||||
@@ -24,7 +18,8 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||
}
|
||||
|
||||
public void addToCraftingManager() {
|
||||
MaterialData input = this.getInput();
|
||||
FurnaceRecipes.getInstance().registerRecipe(input.getItemTypeId(), CraftItemStack.createNMSItemStack(this.getResult()));
|
||||
ItemStack result = this.getResult();
|
||||
ItemStack input = this.getInput();
|
||||
FurnaceRecipes.getInstance().registerRecipe(input.getTypeId(), CraftItemStack.createNMSItemStack(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.CraftingManager;
|
||||
import net.minecraft.server.ShapedRecipes;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
// TODO: Could eventually use this to add a matches() method or some such
|
||||
private ShapedRecipes recipe;
|
||||
|
||||
public CraftShapedRecipe(ItemStack result) {
|
||||
super(result);
|
||||
}
|
||||
|
||||
public CraftShapedRecipe(ItemStack result, ShapedRecipes recipe) {
|
||||
this(result);
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) {
|
||||
if (recipe instanceof CraftShapedRecipe) {
|
||||
@@ -20,8 +28,12 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
CraftShapedRecipe ret = new CraftShapedRecipe(recipe.getResult());
|
||||
String[] shape = recipe.getShape();
|
||||
ret.shape(shape);
|
||||
for (char c : recipe.getIngredientMap().keySet()) {
|
||||
ret.setIngredient(c, recipe.getIngredientMap().get(c));
|
||||
Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap();
|
||||
for (char c : ingredientMap.keySet()) {
|
||||
ItemStack stack = ingredientMap.get(c);
|
||||
if (stack != null) {
|
||||
ret.setIngredient(c, stack.getType(), stack.getDurability());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -29,7 +41,7 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
Object[] data;
|
||||
String[] shape = this.getShape();
|
||||
HashMap<Character, MaterialData> ingred = this.getIngredientMap();
|
||||
Map<Character, ItemStack> ingred = this.getIngredientMap();
|
||||
int datalen = shape.length;
|
||||
datalen += ingred.size() * 2;
|
||||
int i = 0;
|
||||
@@ -38,11 +50,12 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
data[i] = shape[i];
|
||||
}
|
||||
for (char c : ingred.keySet()) {
|
||||
ItemStack mdata = ingred.get(c);
|
||||
if (mdata == null) continue;
|
||||
data[i] = c;
|
||||
i++;
|
||||
MaterialData mdata = ingred.get(c);
|
||||
int id = mdata.getItemTypeId();
|
||||
byte dmg = mdata.getData();
|
||||
int id = mdata.getTypeId();
|
||||
short dmg = mdata.getDurability();
|
||||
data[i] = new net.minecraft.server.ItemStack(id, 1, dmg);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -1,36 +1,44 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.CraftingManager;
|
||||
import net.minecraft.server.ShapelessRecipes;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe {
|
||||
// TODO: Could eventually use this to add a matches() method or some such
|
||||
private ShapelessRecipes recipe;
|
||||
|
||||
public CraftShapelessRecipe(ItemStack result) {
|
||||
super(result);
|
||||
}
|
||||
|
||||
public CraftShapelessRecipe(ItemStack result, ShapelessRecipes recipe) {
|
||||
this(result);
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
public static CraftShapelessRecipe fromBukkitRecipe(ShapelessRecipe recipe) {
|
||||
if (recipe instanceof CraftShapelessRecipe) {
|
||||
return (CraftShapelessRecipe) recipe;
|
||||
}
|
||||
CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getResult());
|
||||
for (MaterialData ingred : recipe.getIngredientList()) {
|
||||
ret.addIngredient(ingred);
|
||||
for (ItemStack ingred : recipe.getIngredientList()) {
|
||||
ret.addIngredient(ingred.getType(), ingred.getDurability());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addToCraftingManager() {
|
||||
ArrayList<MaterialData> ingred = this.getIngredientList();
|
||||
List<ItemStack> ingred = this.getIngredientList();
|
||||
Object[] data = new Object[ingred.size()];
|
||||
int i = 0;
|
||||
for (MaterialData mdata : ingred) {
|
||||
int id = mdata.getItemTypeId();
|
||||
byte dmg = mdata.getData();
|
||||
for (ItemStack mdata : ingred) {
|
||||
int id = mdata.getTypeId();
|
||||
short dmg = mdata.getDurability();
|
||||
data[i] = new net.minecraft.server.ItemStack(id, 1, dmg);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import net.minecraft.server.CraftingManager;
|
||||
import net.minecraft.server.CraftingRecipe;
|
||||
import net.minecraft.server.FurnaceRecipes;
|
||||
|
||||
public class RecipeIterator implements Iterator<Recipe> {
|
||||
private Iterator<CraftingRecipe> recipes;
|
||||
private Iterator<Integer> smelting;
|
||||
private Iterator<?> removeFrom = null;
|
||||
|
||||
public RecipeIterator() {
|
||||
this.recipes = CraftingManager.getInstance().b().iterator();
|
||||
this.smelting = FurnaceRecipes.getInstance().b().keySet().iterator();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
if (recipes.hasNext()) {
|
||||
return true;
|
||||
} else {
|
||||
return smelting.hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe next() {
|
||||
if (recipes.hasNext()) {
|
||||
removeFrom = recipes;
|
||||
return recipes.next().toBukkitRecipe();
|
||||
} else {
|
||||
removeFrom = smelting;
|
||||
int id = smelting.next();
|
||||
CraftItemStack stack = new CraftItemStack(FurnaceRecipes.getInstance().a(id));
|
||||
CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(stack, new ItemStack(id, 1, (short) -1));
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (removeFrom == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
removeFrom.remove();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user