13
0
geforkt von Mirrors/Paper

Implemented addRecipe method in CraftServer and associated recipe classes.

By: Celtic Minstrel <celtic.minstrel.ca@>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2011-04-15 22:11:13 -04:00
Ursprung 2980396ae5
Commit c1e9a053fb
5 geänderte Dateien mit 165 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -8,6 +8,10 @@ import net.minecraft.server.IWorldAccess;
import org.bukkit.command.*; import org.bukkit.command.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.world.WorldLoadEvent; 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,6 +41,10 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitScheduler; 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.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
@ -420,4 +428,24 @@ public final class CraftServer implements Server {
return this.prefix; 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;
}
} }

Datei anzeigen

@ -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));
}
}

Datei anzeigen

@ -0,0 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import org.bukkit.inventory.Recipe;
public interface CraftRecipe extends Recipe {
void addToCraftingManager();
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
}