Jump to content

Potion Effects on Armor


ChaoticSoul

Recommended Posts

As the title says, I am trying to give potion effects to each armour set when the player is wearing the full set,

If anyone can help me, just tell me what parts of the code I need to send.

 

I know it is inconvenient but I do not have a lot of experience with java so I may not be able to follow if you start using terms I do not understand.

Edited by ChaoticSoul
Link to comment
Share on other sites

Get the player's equipped items

Check them against your armor types

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Conveniently, I literally just coded this into my mod.

You're going to want to have a class which is an @EventBusSubscriber, with a method annotated @SubscribeEvent which takes the parameter (TickEvent.PlayerTickEvent event).
 

Then you want to make a variable
 

NonNullList<ItemStack> armor = event.player.inventory.armorInventory;

 

then check
 

if(armor.get(0).getItem()=={the boots they should be wearing, as an Item object} && armor.get(1).getItem()=={the leggings they should be wearing, as an Item object} && armor.get(2).getItem()=={the chestplate they should be wearing, as an Item object} && armor.get(3).getItem()=={the helmet they should be wearing, as an Item object}){
	event.player.addPotionEffect(new PotionEffect(MobEffects.{The effect you want},{how many ticks the effect should last},{the level of the effect, -1},false,{false if you want it not to have particles, true if you do});
}


Keep in mind that the effect will be re-added every tick, so you only really need to put the duration at about 5, unless you are doing Night Vision. Night Vision will flicker if it has 10 seconds or less left, so you should put a duration of 220 for that. This also won't really work for Regen or Absorption, but those are a bit complicated to do. It should work for most passive potion effects (Strength, speed, jump boost, resistance, fire resistance, etc)

If you don't understand anything here, you should probably read up on some modding tutorials; they can be very helpful in grasping some of the basics here. Going through some basic online lessons on java (say Code.org) can be helpful for beginners as well.

 

Link to comment
Share on other sites

Rather than get(0), there is a method that will get an item stack based on its equipment type. Use that. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

 

On ‎6‎/‎27‎/‎2018 at 10:46 PM, Venrob said:

Conveniently, I literally just coded this into my mod.

You're going to want to have a class which is an @EventBusSubscriber, with a method annotated @SubscribeEvent which takes the parameter (TickEvent.PlayerTickEvent event).
 

Then you want to make a variable
 


NonNullList<ItemStack> armor = event.player.inventory.armorInventory;

 

then check
 


if(armor.get(0).getItem()=={the boots they should be wearing, as an Item object} && armor.get(1).getItem()=={the leggings they should be wearing, as an Item object} && armor.get(2).getItem()=={the chestplate they should be wearing, as an Item object} && armor.get(3).getItem()=={the helmet they should be wearing, as an Item object}){
	event.player.addPotionEffect(new PotionEffect(MobEffects.{The effect you want},{how many ticks the effect should last},{the level of the effect, -1},false,{false if you want it not to have particles, true if you do});
}


Keep in mind that the effect will be re-added every tick, so you only really need to put the duration at about 5, unless you are doing Night Vision. Night Vision will flicker if it has 10 seconds or less left, so you should put a duration of 220 for that. This also won't really work for Regen or Absorption, but those are a bit complicated to do. It should work for most passive potion effects (Strength, speed, jump boost, resistance, fire resistance, etc)

If you don't understand anything here, you should probably read up on some modding tutorials; they can be very helpful in grasping some of the basics here. Going through some basic online lessons on java (say Code.org) can be helpful for beginners as well.

 

SOLVED!

Thank you so much, I have struggling with this for a week and it is finally working!

 

  • Like 1
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.