Jump to content

[Solved] [1.7.10] custom enchantment on armor creates four of each


Glistre

Recommended Posts

Why would four pieces of each armor, ie, 4 helmet, 4 chestplates , 4 leggings, and 4 boots be created when overriding getSubItems?

 

 @Override
    public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List list){

    		ItemStack enchant0 = new ItemStack(GlistreMod.MyHelmet_2);
    		ItemStack enchant1 = new ItemStack(GlistreMod.MyChestplate_2);
    		ItemStack enchant2 = new ItemStack(GlistreMod.MyLeggings_2);
    		ItemStack enchant3 = new ItemStack(GlistreMod.MyBoots_2);
    		enchant0.addEnchantment(Enchantment.blastProtection, 9);
   		enchant1.addEnchantment(Enchantment.blastProtection, 9);
   		enchant2.addEnchantment(Enchantment.blastProtection, 9);
    		enchant3.addEnchantment(Enchantment.blastProtection, 9);
    		list.add(enchant0);
   		list.add(enchant1);
   		list.add(enchant2);
   		list.add(enchant3);
    		    		
}

 

I am sure there is a simple explanation and easier way to write this code such as an array

Link to comment
Share on other sites

getSubItems is getting called for each of your armor pieces because all of the armor pieces you have registered are an instance of your class that is adding the subitems. Each armor piece is adding a full set to the game. Try only adding one sub item to the list. So it would be something like this:

 

ItemStack stack = new ItemStack(this);
stack.addEnchantment(enchantmenthere);
list.add(stack);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.