Adds an enchantment with a desired level on the ItemStack.
(Enchantment ench, int level)
| 885 | * Adds an enchantment with a desired level on the ItemStack. |
| 886 | */ |
| 887 | public void addEnchantment(Enchantment ench, int level) |
| 888 | { |
| 889 | if (this.stackTagCompound == null) |
| 890 | { |
| 891 | this.setTagCompound(new NBTTagCompound()); |
| 892 | } |
| 893 | |
| 894 | if (!this.stackTagCompound.hasKey("ench", 9)) |
| 895 | { |
| 896 | this.stackTagCompound.setTag("ench", new NBTTagList()); |
| 897 | } |
| 898 | |
| 899 | NBTTagList nbttaglist = this.stackTagCompound.getTagList("ench", 10); |
| 900 | NBTTagCompound nbttagcompound = new NBTTagCompound(); |
| 901 | nbttagcompound.setShort("id", (short)ench.effectId); |
| 902 | nbttagcompound.setShort("lvl", (byte)level); |
| 903 | nbttaglist.appendTag(nbttagcompound); |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * True if the item has enchantment data |
no test coverage detected