Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

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.

 

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.

  • Author

 

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!

 

10 hours ago, ChaoticSoul said:

 

SOLVED!

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

 

No problem! Like I said, I literally had just coded this exact thing!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.