MCPcopy Create free account
hub / github.com/DGVPSH/SlackOpen / addEnchantment

Method addEnchantment

src/main/java/net/minecraft/item/ItemStack.java:887–904  ·  view source on GitHub ↗

Adds an enchantment with a desired level on the ItemStack.

(Enchantment ench, int level)

Source from the content-addressed store, hash-verified

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

Callers 4

processCommandMethod · 0.95
enchantItemMethod · 0.95
setEnchantmentsMethod · 0.45
addRandomEnchantmentMethod · 0.45

Calls 6

setTagCompoundMethod · 0.95
setShortMethod · 0.95
appendTagMethod · 0.95
hasKeyMethod · 0.80
setTagMethod · 0.80
getTagListMethod · 0.80

Tested by

no test coverage detected