diff options
author | Celtic Minstrel <celtic.minstrel.ca@> | 2011-04-15 22:11:13 -0400 |
---|---|---|
committer | EvilSeph <evilseph@unaligned.org> | 2011-05-01 23:40:48 -0400 |
commit | 5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7 (patch) | |
tree | 5c01022ac2f21947669a4ef02e3213f491ce2963 /src/main/java/org/bukkit | |
parent | 017b15c3a62a2cf066f2ec061da0de582bc5c596 (diff) | |
download | craftbukkit-5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7.tar craftbukkit-5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7.tar.gz craftbukkit-5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7.tar.lz craftbukkit-5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7.tar.xz craftbukkit-5a5ce79035f7ed3d77974c4eb8bc94b2ffae54e7.zip |
Implemented addRecipe method in CraftServer and associated recipe classes.
Diffstat (limited to 'src/main/java/org/bukkit')
5 files changed, 165 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index b699258d..fbf48c60 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -8,6 +8,10 @@ import net.minecraft.server.IWorldAccess; import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.inventory.FurnaceRecipe; +import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; import java.io.File; import java.util.ArrayList; @@ -37,6 +41,10 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe; +import org.bukkit.craftbukkit.inventory.CraftRecipe; +import org.bukkit.craftbukkit.inventory.CraftShapedRecipe; +import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.util.config.Configuration; @@ -420,4 +428,24 @@ public final class CraftServer implements Server { return this.prefix; } } + + @Override + public boolean addRecipe(Recipe recipe) { + CraftRecipe toAdd; + if(recipe instanceof CraftRecipe) { + toAdd = (CraftRecipe) recipe; + } else { + if (recipe instanceof ShapedRecipe) { + toAdd = CraftShapedRecipe.fromBukkitRecipe((ShapedRecipe) recipe); + } else if (recipe instanceof ShapelessRecipe) { + toAdd = CraftShapelessRecipe.fromBukkitRecipe((ShapelessRecipe) recipe); + } else if (recipe instanceof FurnaceRecipe) { + toAdd = CraftFurnaceRecipe.fromBukkitRecipe((FurnaceRecipe) recipe); + } else { + return false; + } + } + toAdd.addToCraftingManager(); + return true; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java new file mode 100644 index 00000000..0c28fd2f --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java @@ -0,0 +1,34 @@ +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 static CraftFurnaceRecipe fromBukkitRecipe(FurnaceRecipe recipe) { + if (recipe instanceof CraftFurnaceRecipe) { + return (CraftFurnaceRecipe) recipe; + } + return new CraftFurnaceRecipe(recipe.getResult(), recipe.getInput()); + } + + public void addToCraftingManager() { + ItemStack result = this.getResult(); + MaterialData input = this.getInput(); + int id = result.getTypeId(); + int amount = result.getAmount(); + int dmg = result.getDurability(); + FurnaceRecipes.a().a(input.getItemTypeId(), new net.minecraft.server.ItemStack(id, amount, dmg)); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java new file mode 100644 index 00000000..d3e03e24 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java @@ -0,0 +1,7 @@ +package org.bukkit.craftbukkit.inventory; + +import org.bukkit.inventory.Recipe; + +public interface CraftRecipe extends Recipe { + void addToCraftingManager(); +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java new file mode 100644 index 00000000..f54cff78 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java @@ -0,0 +1,54 @@ +package org.bukkit.craftbukkit.inventory; + +import java.util.HashMap; + +import net.minecraft.server.CraftingManager; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.material.MaterialData; + +public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { + public CraftShapedRecipe(ItemStack result) { + super(result); + } + + public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) { + if (recipe instanceof CraftShapedRecipe) { + return (CraftShapedRecipe) recipe; + } + 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)); + } + return ret; + } + + public void addToCraftingManager() { + Object[] data; + String[] shape = this.getShape(); + HashMap<Character, MaterialData> ingred = this.getIngredientMap(); + int datalen = shape.length; + datalen += ingred.size() * 2; + int i = 0; + data = new Object[datalen]; + for (; i < shape.length; i++) { + data[i] = shape[i]; + } + for (char c : ingred.keySet()) { + data[i] = c; + i++; + MaterialData mdata = ingred.get(c); + int id = mdata.getItemTypeId(); + byte dmg = mdata.getData(); + data[i] = new net.minecraft.server.ItemStack(id, 1, dmg); + i++; + } + int id = this.getResult().getTypeId(); + int amount = this.getResult().getAmount(); + short durability = this.getResult().getDurability(); + CraftingManager.a().a(new net.minecraft.server.ItemStack(id, amount, durability), data); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java new file mode 100644 index 00000000..53f2a165 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java @@ -0,0 +1,42 @@ +package org.bukkit.craftbukkit.inventory; + +import java.util.ArrayList; + +import net.minecraft.server.CraftingManager; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.material.MaterialData; + +public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe { + public CraftShapelessRecipe(ItemStack result) { + super(result); + } + + 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); + } + return ret; + } + + public void addToCraftingManager() { + ArrayList<MaterialData> ingred = this.getIngredientList(); + Object[] data = new Object[ingred.size()]; + int i = 0; + for (MaterialData mdata : ingred) { + int id = mdata.getItemTypeId(); + byte dmg = mdata.getData(); + data[i] = new net.minecraft.server.ItemStack(id, 1, dmg); + i++; + } + int id = this.getResult().getTypeId(); + int amount = this.getResult().getAmount(); + short durability = this.getResult().getDurability(); + CraftingManager.a().b(new net.minecraft.server.ItemStack(id, amount, durability), data); + } +} |