cn.nukkit.inventory.Recipe Maven / Gradle / Ivy
package cn.nukkit.inventory;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.item.Item;
import java.util.ArrayList;
import java.util.List;
/**
* @author MagicDroidX (Nukkit Project)
*/
public interface Recipe {
Item getResult();
void registerToCraftingManager(CraftingManager manager);
RecipeType getType();
@PowerNukkitOnly
@Since("1.4.0.0-PN")
static boolean matchItemList(List- haveItems, List
- needItems) {
for (Item needItem : new ArrayList<>(needItems)) {
for (Item haveItem : new ArrayList<>(haveItems)) {
if (needItem.equals(haveItem, needItem.hasMeta(), needItem.hasCompoundTag())) {
int amount = Math.min(haveItem.getCount(), needItem.getCount());
needItem.setCount(needItem.getCount() - amount);
haveItem.setCount(haveItem.getCount() - amount);
if (haveItem.getCount() == 0) {
haveItems.remove(haveItem);
}
if (needItem.getCount() == 0) {
needItems.remove(needItem);
break;
}
}
}
}
return haveItems.isEmpty() && needItems.isEmpty();
}
}