Jump to content

[1.7.10]Posting messages to chat client-side


Chlod

Recommended Posts

I'm trying to post a message to players, when they login, saying they need to update to the latest version. Now, I've done the whole "getting-the-version" thing. I just need to know what code to put to send the message ONLY WHEN the player logs into the game.

 

Thanks in advance :D

Developer of Chlod's Mod! Project Link: http://minecraft.curseforge.com/projects/chlods-mod

Link to comment
Share on other sites

PlayerLoggedInEvent, though I believe this event is fired only on the server side; if so and you absolutely must have an event that is fired on the client side (i.e. your mod is a client-side only mod), you can use EntityJoinWorldEvent and check for EntityPlayer before sending the message.

So now, what do I do to check if the Entity is a player, and how do I send the message?

 

EDIT: I can't find a tutorial for this exact version and topic on Google, so don't ask me to Google it. Done that already.

Developer of Chlod's Mod! Project Link: http://minecraft.curseforge.com/projects/chlods-mod

Link to comment
Share on other sites

Done outside IDE, cannot guarantee if it will work from copy/paste, but the gist of it should be clear.

 

As this is for a client-side only mod, you could instead likely cast it directly to Minecraft#getMinecraft()#thePlayer() or whatever the structure of that is again.

public void getPlayer(EntityJoinWorldEvent event){
        //Check if the entity is what we are looking for.
        if(event.entity instanceof EntityPlayer){
                //If its a player, cast the entity to EntityPlayer.
                EntityPlayer player = (EntityPlayer) event.entity;
                //Now you use "player" instead of "event.entity"
        }
}

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

I did it! Thanks guys! :D

Here's the results:

@EventHandler
public void getPlayer(EntityJoinWorldEvent event){
	//Credits: Matryoshika, Ernio and coolAlias on the Minecraft Forge Forums
        if(event.entity instanceof EntityPlayer){
                EntityPlayer player = Minecraft.getMinecraft().thePlayer; 
                    player.addChatMessage(new ChatComponentText("text));
        }
}

Developer of Chlod's Mod! Project Link: http://minecraft.curseforge.com/projects/chlods-mod

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.