3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 13:30:05 +01:00
Paper/src/main/java/net/minecraft/server/ShapelessRecipes.java

80 Zeilen
2.3 KiB
Java

package net.minecraft.server;
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 {
2012-02-29 22:31:04 +01:00
private final ItemStack result;
private final List ingredients;
public ShapelessRecipes(ItemStack itemstack, List list) {
2012-02-29 22:31:04 +01:00
this.result = itemstack;
this.ingredients = list;
}
// CraftBukkit start
@SuppressWarnings("unchecked")
public ShapelessRecipe toBukkitRecipe() {
2012-02-29 22:31:04 +01:00
CraftItemStack result = new CraftItemStack(this.result);
CraftShapelessRecipe recipe = new CraftShapelessRecipe(result, this);
2012-02-29 22:31:04 +01:00
for (ItemStack stack : (List<ItemStack>) this.ingredients) {
if (stack != null) {
recipe.addIngredient(org.bukkit.Material.getMaterial(stack.id), stack.getData());
}
}
return recipe;
}
// CraftBukkit end
public ItemStack b() {
2012-02-29 22:31:04 +01:00
return this.result;
}
public boolean a(InventoryCrafting inventorycrafting) {
2012-02-29 22:31:04 +01:00
ArrayList arraylist = new ArrayList(this.ingredients);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
ItemStack itemstack = inventorycrafting.b(j, i);
if (itemstack != null) {
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext()) {
ItemStack itemstack1 = (ItemStack) iterator.next();
if (itemstack.id == itemstack1.id && (itemstack1.getData() == -1 || itemstack.getData() == itemstack1.getData())) {
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag) {
return false;
}
}
}
}
return arraylist.isEmpty();
}
public ItemStack b(InventoryCrafting inventorycrafting) {
2012-02-29 22:31:04 +01:00
return this.result.cloneItemStack();
}
public int a() {
2012-02-29 22:31:04 +01:00
return this.ingredients.size();
}
}