Jump to content

Recommended Posts

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

Posted

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.

Posted

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?

Posted

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.

Posted

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 ?

Posted

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.

Posted

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

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