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

Hello everybody !

I'd like to know if it is possible with Minecraft Forge to detect if the player has a specific armor eauiped (an armor thst I have created), and then to do something if he does.

 

- Thib92

Assuming you are doing this with a blockActivated() or itemRightClick(), you can use the player parameter to do this:

 

int id = player.inventory.armorInSlot(slot).itemID;
if(id == myItem.itemID)
{
//do stuff
}

 

Vanilla code.

  • Author

Sorry but I'm new to moding.  :-\

What do you mean by doing it with blockActivate() or itemRightClick() ?

Specifically, what sequence of events do you want to happen that will lead to the point of having to see if the player has armor equipped?

  • Author

I want to make the player glow when he has a specific armor (helmet OR chestplate OR leggings OR boots)

Well, I suppose you could override onArmorTickUpdate() in your item class, and then put the code in there, and it will work for all of the armor pieces as long as one of them is equipped.

  • Author

okay, so I put the onArmorTickUpdate() in my armor class, and then inside it, put the code to toggle the light right ?

And what are the parameters I need ?

If you are using eclipse, right click in the file, go to source, select Override/Implement methods, go to the Item head, and select onArmorTickUpdate() and it will override it for you in your file. Then you add your code there.

You just need to subscribe to the Event "RenderPlayerEvent.Specials.Post". This will secure that your glow will be rendered AFTER (use .Pre if you want it before) everything else. You can do this like this:

import cpw.mods.fml.common.Mod.EventHandler;
import net.minecraftforge.client.event.RenderPlayerEvent.Post;

class YourRenderer {
@EventHandler
public void renderGlow(Post renderEvent)
{
Player p = renderEvent.entityPlayer;
boolean isHelmet = (p.getCurrentArmor(0).getItem() instanceof YourArmorClass);
//etc...
}
}

Put the method whereever you want, preferably in a new class that will handle all your rendering stuff or something. All you have to do is creating a new Instance of this class in your @Mod-class I guess (at least that's how I understood the @EventHandler thingy). This means in your @Mod file there is a variable declared:

@Mod
class bla {
private YourRenderer myRenderer = new YourRenderer(); //Instance

}

That done myRenderer is now ready to receive events of type RenderPlayerEvent.Specials.Post.

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.