/** * An Item Object consists of data about a particular item stack. Information included is: type, * data, qty, and an array of enchantment objects (labeled enchants): etype (enchantment type) and * elevel (enchantment level). For backwards compatibility, this information is also listed in * numerical slots as well as associative slots. If the MCItemStack is null, or the underlying * item is nonexistant (or air) CNull is returned. * * @param is * @return */ public Construct item(MCItemStack is, Target t) { if (is == null || is.getAmount() == 0) { return new CNull(t); } int type = is.getTypeId(); int data; if (type < 256) { // Use the data data = (is.getData() != null ? is.getData().getData() : 0); } else { // Use the durability data = is.getDurability(); } int qty = is.getAmount(); CArray enchants = new CArray(t); for (Map.Entry<MCEnchantment, Integer> entry : is.getEnchantments().entrySet()) { CArray enchObj = CArray.GetAssociativeArray(t); enchObj.set("etype", new CString(entry.getKey().getName(), t), t); enchObj.set("elevel", new CInt(entry.getValue(), t), t); enchants.push(enchObj); } Construct meta = itemMeta(is, t); CArray ret = CArray.GetAssociativeArray(t); ret.set("type", Integer.toString(type)); ret.set("data", Integer.toString(data)); ret.set("qty", Integer.toString(qty)); ret.set("enchants", enchants, t); ret.set("meta", meta, t); return ret; }