2011-07-15 02:54:07 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-07-24 05:16:14 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
|
|
import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public class ShapedRecipes implements IRecipe {
|
2011-07-15 02:54:07 +02:00
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
private int width;
|
|
|
|
private int height;
|
|
|
|
private ItemStack[] items;
|
|
|
|
private ItemStack result;
|
2011-07-15 02:54:07 +02:00
|
|
|
public final int a;
|
2013-07-01 13:03:00 +02:00
|
|
|
private boolean f;
|
2011-07-15 02:54:07 +02:00
|
|
|
|
|
|
|
public ShapedRecipes(int i, int j, ItemStack[] aitemstack, ItemStack itemstack) {
|
|
|
|
this.a = itemstack.id;
|
2012-02-29 22:31:04 +01:00
|
|
|
this.width = i;
|
|
|
|
this.height = j;
|
|
|
|
this.items = aitemstack;
|
|
|
|
this.result = itemstack;
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|
|
|
|
|
2011-07-24 05:16:14 +02:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
public org.bukkit.inventory.ShapedRecipe toBukkitRecipe() {
|
2012-12-17 08:31:41 +01:00
|
|
|
CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
2011-07-24 05:16:14 +02:00
|
|
|
CraftShapedRecipe recipe = new CraftShapedRecipe(result, this);
|
2012-08-05 16:32:35 +02:00
|
|
|
switch (this.height) {
|
2011-07-24 05:16:14 +02:00
|
|
|
case 1:
|
2012-08-05 16:32:35 +02:00
|
|
|
switch (this.width) {
|
2011-07-24 05:16:14 +02:00
|
|
|
case 1:
|
|
|
|
recipe.shape("a");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
recipe.shape("ab");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
recipe.shape("abc");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-08-05 16:32:35 +02:00
|
|
|
switch (this.width) {
|
2011-07-24 05:16:14 +02:00
|
|
|
case 1:
|
|
|
|
recipe.shape("a","b");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
recipe.shape("ab","cd");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
recipe.shape("abc","def");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2012-08-05 16:32:35 +02:00
|
|
|
switch (this.width) {
|
2011-07-24 05:16:14 +02:00
|
|
|
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';
|
2012-02-29 22:31:04 +01:00
|
|
|
for (ItemStack stack : this.items) {
|
2011-07-24 05:16:14 +02:00
|
|
|
if (stack != null) {
|
|
|
|
recipe.setIngredient(c, org.bukkit.Material.getMaterial(stack.id), stack.getData());
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-07-15 02:54:07 +02:00
|
|
|
public ItemStack b() {
|
2012-02-29 22:31:04 +01:00
|
|
|
return this.result;
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean a(InventoryCrafting inventorycrafting, World world) {
|
2012-02-29 22:31:04 +01:00
|
|
|
for (int i = 0; i <= 3 - this.width; ++i) {
|
|
|
|
for (int j = 0; j <= 3 - this.height; ++j) {
|
2011-07-15 02:54:07 +02:00
|
|
|
if (this.a(inventorycrafting, i, j, true)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.a(inventorycrafting, i, j, false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(InventoryCrafting inventorycrafting, int i, int j, boolean flag) {
|
|
|
|
for (int k = 0; k < 3; ++k) {
|
|
|
|
for (int l = 0; l < 3; ++l) {
|
|
|
|
int i1 = k - i;
|
|
|
|
int j1 = l - j;
|
|
|
|
ItemStack itemstack = null;
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
if (i1 >= 0 && j1 >= 0 && i1 < this.width && j1 < this.height) {
|
2011-07-15 02:54:07 +02:00
|
|
|
if (flag) {
|
2012-02-29 22:31:04 +01:00
|
|
|
itemstack = this.items[this.width - i1 - 1 + j1 * this.width];
|
2011-07-15 02:54:07 +02:00
|
|
|
} else {
|
2012-02-29 22:31:04 +01:00
|
|
|
itemstack = this.items[i1 + j1 * this.width];
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack itemstack1 = inventorycrafting.b(k, l);
|
|
|
|
|
|
|
|
if (itemstack1 != null || itemstack != null) {
|
|
|
|
if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack.id != itemstack1.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack.getData() != 32767 && itemstack.getData() != itemstack1.getData()) {
|
2011-07-15 02:54:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public ItemStack a(InventoryCrafting inventorycrafting) {
|
2012-12-20 05:03:52 +01:00
|
|
|
ItemStack itemstack = this.b().cloneItemStack();
|
|
|
|
|
|
|
|
if (this.f) {
|
|
|
|
for (int i = 0; i < inventorycrafting.getSize(); ++i) {
|
|
|
|
ItemStack itemstack1 = inventorycrafting.getItem(i);
|
|
|
|
|
|
|
|
if (itemstack1 != null && itemstack1.hasTag()) {
|
|
|
|
itemstack.setTag((NBTTagCompound) itemstack1.tag.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int a() {
|
2012-02-29 22:31:04 +01:00
|
|
|
return this.width * this.height;
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|
2012-12-20 05:03:52 +01:00
|
|
|
|
|
|
|
public ShapedRecipes c() {
|
|
|
|
this.f = true;
|
|
|
|
return this;
|
|
|
|
}
|
2011-07-15 02:54:07 +02:00
|
|
|
}
|