Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10]Posting messages to chat client-side
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Chlod

[1.7.10]Posting messages to chat client-side

By Chlod, July 27, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Chlod    0

Chlod

Chlod    0

  • Tree Puncher
  • Chlod
  • Members
  • 0
  • 9 posts
Posted July 27, 2016

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

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted July 27, 2016

PlayerLoggedInEvent, though Ibelieve 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.

  • Quote

Share this post


Link to post
Share on other sites

Chlod    0

Chlod

Chlod    0

  • Tree Puncher
  • Chlod
  • Members
  • 0
  • 9 posts
Posted July 27, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Matryoshika    116

Matryoshika

Matryoshika    116

  • Dragon Slayer
  • Matryoshika
  • Forge Modder
  • 116
  • 518 posts
Posted July 27, 2016

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"
        }
}

  • Quote

Share this post


Link to post
Share on other sites

Chlod    0

Chlod

Chlod    0

  • Tree Puncher
  • Chlod
  • Members
  • 0
  • 9 posts
Posted July 27, 2016

Ok, I did it. Now, how about the chat message now?

  • Quote

Share this post


Link to post
Share on other sites

Ernio    598

Ernio

Ernio    598

  • Reality Controller
  • Ernio
  • Forge Modder
  • 598
  • 2638 posts
Posted July 27, 2016

EntityPlayer#addChatComponentMessage to write message from client-side to client-chat.

 

  • Quote

Share this post


Link to post
Share on other sites

Chlod    0

Chlod

Chlod    0

  • Tree Puncher
  • Chlod
  • Members
  • 0
  • 9 posts
Posted July 27, 2016

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));
        }
}

  • Quote

Share this post


Link to post
Share on other sites

Ernio    598

Ernio

Ernio    598

  • Reality Controller
  • Ernio
  • Forge Modder
  • 598
  • 2638 posts
Posted July 27, 2016

This will fire anytime ANY player joins world.

You need:

if (event.entity == Minecraft#thePlayer)

And ONLY that.

  • Quote

Share this post


Link to post
Share on other sites

Chlod    0

Chlod

Chlod    0

  • Tree Puncher
  • Chlod
  • Members
  • 0
  • 9 posts
Posted July 28, 2016

Ok... it doesn't fire at all. With the new changes and the past one.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted July 28, 2016

It should be @SubscribeEvent, not @EventHandler. Might help you to check out a tutorial on using Forge Events.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • bismuth210
      [1.12.2] Killing fireworks in unloaded chunks

      By bismuth210 · Posted 7 minutes ago

      I'm creating a custom gamemode using forge in which players get teleported around regularly. I've run into a problem when I do the following:   I spawn a firework rocket near a player I teleport the player to a different location I wait a couple of seconds (or minutes) I teleport the player back to the same location as in step 1. Doing this will show the firework spawned in step 1 in step 4, despite significant time having passed in 3. This video shows what I mean:   I suspect the reason for why this happens is because once I teleport the player somewhere else, the chunk with the firework is no longer loaded and doesn't get updated.   Is there a simple way for me to simply "get rid" of all active fireworks shortly before teleporting players so that this doesn't occur? Or do I really have to forcibly keep all chunks loaded? To be more clear: I don't want to disable fireworks all together, but I don't want remnants of old fireworks showing up when I teleport players. "Killing" all firework rockets when I teleport a player would work fine, but I don't know if/how I can do that.   I've tried using /kill @e[type=!player] But that doesn't work for firework rockets apparently.
    • RunKeish
      Forge 14.4 crashes on statup

      By RunKeish · Posted 7 minutes ago

      It finally worked! Thankyou so much. The installation was dodgy for me so I had to download JDK8 using:       ~$ sudo apt install openjdk-8-jdk openjdk-8-jre   Followed by:     ~$ update-java-alternatives --config java   Then select the java-8-openjdk-amd64/jre/bin/java from the list (to make java 8 the default, can switch and whatever but it works!!!)   Thanks a tonne!
    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 18 minutes ago

      OK, it works.Tthanks.     I wonder is there better way for doing it instead of creating new thread?    System.out.println("Turning off"); Thread thread = new Thread(new CloseGui()); thread.start(); //CloseGui class public void run() { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("closing"); Minecraft.getMinecraft().player.closeScreen(); }  
    • diesieben07
      [1.12.2] How can I close GUI in Forge?

      By diesieben07 · Posted 34 minutes ago

      Then you must first let the GUI open (GuiOpenEvent fires before its open!) and then call:
    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 43 minutes ago

      I did it, but I think it's only clientside prevention. I gotta send real packet "close gui" to trigger serverside InventoryCloseEvent (or something like that).
  • Topics

    • bismuth210
      0
      [1.12.2] Killing fireworks in unloaded chunks

      By bismuth210
      Started 7 minutes ago

    • RunKeish
      4
      Forge 14.4 crashes on statup

      By RunKeish
      Started 2 hours ago

    • Filip4223
      4
      [1.12.2] How can I close GUI in Forge?

      By Filip4223
      Started 58 minutes ago

    • Differentiation
      12
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By Differentiation
      Started 9 hours ago

    • DragonITA
      4
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started 3 hours ago

  • Who's Online (See full list)

    • bismuth210
    • geduardcatalindev
    • Enterman
    • EmerProd
    • DavidM
    • Differentiation
    • RunKeish
    • Filip4223
    • diesieben07
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10]Posting messages to chat client-side
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community