Jump to content

Setting Display Name Clientside


Gnomorian

Recommended Posts

hi i found an event PlayerEvent.NameFormat

which i can use to set the players display name on login and get it to call again using the function refreshDisplayName() in EntityPlayer.

@SubscribeEvent
public void onLoginEvent(PlayerEvent.NameFormat event) {
	Random rand = new Random();
	System.out.println("players displayname = "+ event.displayname);
	System.out.println("players username = "+ event.username);
	if(event.displayname.startsWith("Player")) 
	{
		String name = "Gnomorian"+rand.nextInt(10);
		System.out.println("setting the display Name to: "+ name);
		event.displayname = name;
	}
	System.out.println("players new displayname = "+ event.displayname);
	System.out.println("players new username = "+ event.username);
}

 

although this doesn't work client side, was wondering if anyone knew a way to set it clientside.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

This should work. Where do you call refreshDisplayName?

im calling it from a keybind, im aware i need a packet to get this to the server, but i dont want the server to be involved, which is where the trouble is, when i surround the pasted code above with isremote, the name no longer changes, when i look at refreshdisplay name, it calls ForgeEventFactory which calls the event i posted above, which wont run because its surrounded with isremote, what a shame.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

Not sure I follow here.You call refreshDisplayName from a Keybind? Sounds weird to me, but ok.

Define "surround with isremote". Do you check for isRemote = true or false?

this is correct, if(event.entity.worldobject.isremote){}

then the code above goes in it.

 

it turns out im wrong before, the event does call, i got the chat output when pressing the keybind:

 

[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBKeybindHandler:onKeyPress:17]: KEY PRESSED!
[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBNameHandler:onLoginEvent:14]: players displayname = Player312
[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBNameHandler:onLoginEvent:15]: players username = Player312
[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBNameHandler:onLoginEvent:19]: setting the display Name to: Gnomorian9
[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBNameHandler:onLoginEvent:22]: players new displayname = Gnomorian9
[23:38:30] [Client thread/INFO] [sTDOUT]: [nz.co.crookedhill.branding.handler.GGBNameHandler:onLoginEvent:23]: players new username = Player312
[23:38:38] [server thread/INFO]: <Player312> tet

 

as you can see because of the test to see if isremote is true the display name remains Player312, every time i press the key it says the same thing however (other than the variable number at the end) the original name is always Player312 not the one it ses i changed it to: "players new displayname = Gnomorian9", does this mean that is a copy of the name so setting it is useless?

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

Yes, you are not setting player.username. You are only setting the display name...

i cant set the username, its final.

and when i set the username, cording to that, even the display name never sets, it always returns the old display name + old username.

however iv just found when i call player.getDisplayName() it has the new one, this is really odd.

ill try getting the server running and add 2 players to see if there nameplates change.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

your not getting my point i think, or i'm not understanding this, the thing that is strange is the when calling the event you say the display name is the only thing being changed, thats fine, thats meant to happen, the strange thing is that is not happening at all. it is not getting changed. according to that event anyhow. cording to the player object it is changed, the event said it isnt changed, if my saying that makes sence.

 

however running the game with 2 clients has showed me that the displayName above the heads of the player doesnt update, found an event to render a nameplate above a player, but not  edit or hide an existing one. thanks for the help.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

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.