Jump to content

Adding an effect to an entity based on an enchantment


yanksrock1019

Recommended Posts

If you can't figure out how to override a class method (e.g. onArmorTick), then I suggest you first learn Java. Once you've got that down and understand how to override class methods, then the following may interest you:

 

In the latest version of Forge (10.12.1.1060), there is a new ItemStack sensitive version of getAttributeModifiers, so you can check for enchantments from there and have it return a multimap with a speed attribute modifier, though if you do it this way the player would also get the speed boost when just holding the boots. If that doesn't fit your idea of what the boots should do, then you should use the onArmorTick method as mentioned above.

Link to comment
Share on other sites

If you can't figure out how to override a class method (e.g. onArmorTick), then I suggest you first learn Java. Once you've got that down and understand how to override class methods, then the following may interest you:

 

In the latest version of Forge (10.12.1.1060), there is a new ItemStack sensitive version of getAttributeModifiers, so you can check for enchantments from there and have it return a multimap with a speed attribute modifier, though if you do it this way the player would also get the speed boost when just holding the boots. If that doesn't fit your idea of what the boots should do, then you should use the onArmorTick method as mentioned above.

 

I know how to override stuff I just dont know where to put the onArmorTick and what to put inside it.

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

I have this so far

 @Override
 public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {
	 if(armor.getItem() == PupletItems.bootsPuplet){
		 player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 500, 4));

	 }
	  
 }

 

Now how do I make it dependent on my custom enchantment, and base the speed level on the level of enchantment?

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

Dude, please learn basic java.

Dude, just because I don't know where this is supposed to go doesn't mean I don't know simple java. This has nothing to do with basic java. I deals with minecraft which is why I'm here.

However, having a good grasp of fundamental Java would allow you to quickly solve this Minecraft-related problem, because all you need is the enchantment level (an integer), which you now know how to retrieve thanks to diesieben07, and basic Java to relate that level to the potion duration or amplifier (both also integers).

 

I think most people on these forums are more than happy to give advice about Minecraft-related questions, such as "how do I get the level of an enchantment?", but how you use that level is entirely up to you and your skills with Java.

Link to comment
Share on other sites

Dude, please learn basic java.

Dude, just because I don't know where this is supposed to go doesn't mean I don't know simple java. This has nothing to do with basic java. I deals with minecraft which is why I'm here.

However, having a good grasp of fundamental Java would allow you to quickly solve this Minecraft-related problem, because all you need is the enchantment level (an integer), which you now know how to retrieve thanks to diesieben07, and basic Java to relate that level to the potion duration or amplifier (both also integers).

 

I think most people on these forums are more than happy to give advice about Minecraft-related questions, such as "how do I get the level of an enchantment?", but how you use that level is entirely up to you and your skills with Java.

True, I mean I know what integers are and stuff but for the enchantment id, if it's my custom enchantment, would typing the id that I set work or would I have to use .getId()

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

Again: this is basic programming knowledge. Don't use magic numbers, at least use constants, so that you only have to change the number in one place.

getId

would be the easiest solution here, though.

Just realized it's actually effect id.

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

I think I'm going about this wrong.

@Override
 public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {
	 if(armor.getItem() == PupletItems.bootsPuplet){
		int j = EnchantmentHelper.getEnchantmentLevel(MainClass.speedBoost.effectId, new ItemStack(PupletItems.bootsPuplet));
		if(j > 0){
		 player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 500, 4));
		}

	 }
	  
 }

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

I think I'm going about this wrong.

(code)

if(armor.getItem() == PupletItems.bootsPuplet){

int j = EnchantmentHelper.getEnchantmentLevel(MainClass.speedBoost.effectId, new ItemStack(PupletItems.bootsPuplet));

(/code)

Highlighted the wrong for you.

Link to comment
Share on other sites

I think I'm going about this wrong.

(code)

if(armor.getItem() == PupletItems.bootsPuplet){

int j = EnchantmentHelper.getEnchantmentLevel(MainClass.speedBoost.effectId, new ItemStack(PupletItems.bootsPuplet));

(/code)

Highlighted the wrong for you.

 

Thanks, but I can't see why that would be wrong, don't I have to declare what piece of armor it is, and also create a new ItemStack since getEnchantmentLevel takes ItemStacks not Items

Don't tell me to learn the basics of java, I already know.

Link to comment
Share on other sites

Your "armor" variable is not an Item.

Not sure what you meant by that, but he had "armor.getItem()" in the condition, which was correct...

 

@OP The problem is you are checking for the enchantment level on the wrong ItemStack - you want to check the level on the ItemStack that is actually worn, not on a new ItemStack.

 

// this will always return zero, because a new ItemStack will not have any enchantments!
// not to mention the new stack has absolutely nothing to do with the stack you want to check...
int j = EnchantmentHelper.getEnchantmentLevel(MainClass.speedBoost.effectId, new ItemStack(PupletItems.bootsPuplet));

// this will get the enchantment level of the armor (boots) worn:
int j = EnchantmentHelper.getEnchantmentLevel(MainClass.speedBoost.effectId, armor);

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.