Posted July 14, 201312 yr 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
July 14, 201312 yr 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.
July 14, 201312 yr Author Sorry but I'm new to moding. What do you mean by doing it with blockActivate() or itemRightClick() ?
July 14, 201312 yr 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?
July 14, 201312 yr Author I want to make the player glow when he has a specific armor (helmet OR chestplate OR leggings OR boots)
July 14, 201312 yr 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.
July 15, 201312 yr 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 ?
July 15, 201312 yr 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.
July 16, 201312 yr 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.