Jump to content

[1.7.10] How to getItemEnchantability() from ItemStack's NBTTags


SackCastellon

Recommended Posts

I'm adding some different "attributes" to some of my tools:

 

	nbt.setInteger("HarvestLevel", 2);
	nbt.setInteger("MaxDamage", 500);
	nbt.setFloat("EfficiencyOnProperMaterial", 3.0F);
	nbt.setFloat("DamageVsEntity", 5.0F);
	nbt.setInteger("Enchantability", 40);

* Those values are examples, there are about 400 total combinations

 

The rest of attributes are easily get, because the methods have an ItemStack parameter.

 

For example, the maxDamage:

@Override
public int getMaxDamage(ItemStack stack)
{
	NBTTagCompound nbt = stack.getTagCompound();

	return nbt.getInteger("MaxDamage");
}

 

But unfortunately, the getItemEnchantability() method is the only one without an ItemStack parameter:

 

	@Override
public int getItemEnchantability() {
	// TODO Auto-generated method stub
	return super.getItemEnchantability();
}

 

So, I'm wondering if there is any way to get the NBT Tag, without an ItemStack parameter.

 

Thanks for helping.

 

SackCastellon.

Link to comment
Share on other sites

The problem is there's no hook for it currently.

You can always make a PR on the forge github for this.

 

What needs to be done is following:

Add a new method like getItemEnchantability with an ItemStack parameter inside the Item class which calls the vanilla one by default.

In the EnchantmentHelper class, within the buildEnchantmentList method, you then need to change the line with getItemEnchantability and add the itemstack as parameter.

If that's done, you need to override the getItemEnchantability method in your item with the ItemStack parameter.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Enchantability is expected to be a fixed characteristic of an item class and its material. Are you sure that it needs to become a dynamic (changeable) property of each individual stack of an item?

 

If you aren't planning very many distinct enchantability levels, then the painful work-around might be to create multiple instances of the item's class, one for each possible level. When an item stack's enchantability changes, it would be replaced by a stack of a different subclass of the item. The call to getEnchantability could then return a function of both material and the subclass's enchantability modifier.

 

If you're doing something like having tools magically transmute material, then subclassing by material could change several properties based on the one parameter.

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

The problem is there's no hook for it currently.

You can always make a PR on the forge github for this.

 

What needs to be done is following:

Add a new method like getItemEnchantability with an ItemStack parameter inside the Item class which calls the vanilla one by default.

In the EnchantmentHelper class, within the buildEnchantmentList method, you then need to change the line with getItemEnchantability and add the itemstack as parameter.

If that's done, you need to override the getItemEnchantability method in your item with the ItemStack parameter.

Done, and waiting: https://github.com/MinecraftForge/MinecraftForge/pull/1314

 

Thanks  :)

Link to comment
Share on other sites

Enchantability is expected to be a fixed characteristic of an item class and its material. Are you sure that it needs to become a dynamic (changeable) property of each individual stack of an item?

 

If you aren't planning very many distinct enchantability levels, then the painful work-around might be to create multiple instances of the item's class, one for each possible level. When an item stack's enchantability changes, it would be replaced by a stack of a different subclass of the item. The call to getEnchantability could then return a function of both material and the subclass's enchantability modifier.

 

If you're doing something like having tools magically transmute material, then subclassing by material could change several properties based on the one parameter.

 

What I'm trying to do is create about 400 different tools, with 5 different enchantability levels, depending on the materials made of (information stored on the NBT Tags).

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.



×
×
  • Create New...

Important Information

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