#get player username
77 messages · Page 1 of 1 (latest)
you're probably accessing player too early
and you shouldn't really store references to MinecraftClient like that
null checks aren't going to solve everything
debug your code
and debug your code. you only showed a small section of your code. i mean if this gets executed at the title screen, ofc the player will be null. a game hasn't even started yet
still you seem to be in a context where the player isn't available?
debug
Well if the Global class is loaded at any point before a player is available then this won't work
Because the player field will reference null
And it won't change when MinecraftClient.player is changed - the field references the object at the time of assignment, not the MinecraftClient field
getDisplayName() has never worked for me in regards to players (not sure if that's a skill issue or just how that method works), does getProfile().getName() work?
try client.getSession().getUserName()
Minecraft.getInstance().player.getName().getString()
or
Minecraft.getInstance().player.getGameProfile().getName()
Stupid reccomendations 2, try to just read the topic and messages above, there was said:"code works earlier than player enters the world" you can't use mc.player, when mc.player is null, only you can use is -> mc.GetSession().GetUserName()
GetSession() is not defined
-_- it is default method of minecraft
Try to write mods
maybe use it on the correct event then
For what? He just need name
READ TOPIC
which will get u the name
Red topic before offtop
i did
It will works only when play enters the world
anything else?
He needs name EARLIER than player enters the world
works when mc is loaded
MinecraftClient.getInstance().getSession().getUserName()
R u kidding?
Mc.player becomes not null ONLY when the world is loaded
nope
Ok, than check it :/
It will give you null error in main menu or in every time when U R not in world
when mc is loaded
so yea, theres no reason to be mad over this
just saying that mc.player also works
*when world is loaded, LOOK AT COORDINATES IDIOT
No, its not, you entered the world
those are the default coordinates
He need a way that will work in main menu
anything else u got?
Yeah it means that you are in world, but we still need a method that will work in main menu
nope
I got that you cant read
those are the default coordinates when a new instance is created
Ok, than what is magic coordinates showed if you r not in world???
INSTANCE BECOMES CREATED ONLY WHEN YOU ENTERS THE WORLD
then it would be different
nope, when mc loads
Top 5 magic coordinates the 1st place:
:/
those are the default coordanites when the instance is created
Try to log player username in main menu
What version do you using?
1.21.1
oh ur on 1.16.5?
1.16.5 -> MinecraftClient.getInstance().getUserName()
1.17-1.21.1 -> Minecraft.getInstance().player.getEntityName()
oh
then ur getting confused
maybe player is only not null when player joins a world in 1.16.5
and mojang made a change in a later update to make player not null on startup
Why mojang so likes to relocate values
Cant you just check if its null?
if (target == null) return; this is what i do before trying to get the name