How do I get a player's username using Minecraft Forge?
What I want to do is when a player picks up an item I can check the username against mine and if it matches they can keep the item and if it doesn't it gets deleted out of there inventory so only I can use the item.
I'm currently trying to do this onItemUseFist to be honest I have no idea where to start with doing this. I already have the item I want to do this to. I just don't know how to do that. I think xComp does something like this with his glasses in Mystcraft.
Thanks in advance,
Josh
Best Answer
Minecraft.getMinecraft().thePlayer.username.equals("username")
works. You can put that as the arguments of an if. then statement then an else statement to do what you want to happen if it doesn't match your username. You could also invert the if statement with a ! before the first M then have the code run in the then statement.
Pictures about "How do I get a player's username using Minecraft Forge?"



How do you select a forge profile in Minecraft?
Open Minecraft and change the profile to 'forge'. Once the game loads, you'll see a new 'Mods' menu on the start screen. Click this and choose which mods to use.What is the forge profile in Minecraft?
Minecraft Forge is an add-on for Minecraft: Java Edition that lets you install and enable mods. Make sure that you download the version of Minecraft Forge that corresponds with your current Minecraft version. Visit Insider's Tech Reference library for more stories.Do you need a Minecraft account to use Forge?
If you are creating a Forge server, You don't need Minecraft official server software installed. The Forge installer contains all of the server files.How do you link Minecraft to forge?
To install Forge, you must run Minecraft and log in before it can be installed.How to Become a PLAYER ?
More answers regarding how do I get a player's username using Minecraft Forge?
Answer 2
In the code of Forge for 1.12 I found:
Minecraft.getMinecraft().player.getName()
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ketut Subiyanto, Mary Taylor, Ivan Samkov, RF._.studio
