Jump to content

Recommended Posts

Posted

Okay hi again, I am having another problem but this time I am trying to send a chat message to a player who joins a world with my mod in it.

I have looked around and found what I thought was the solution but its not working and everything else I find explains the same thing.

 

Code:ChatHandler

public class ChatHandler
{
    @SubscribeEvent
    public void onPlayerLog(PlayerEvent.PlayerLoggedOutEvent event)
    {

        event.player.addChatMessage(new ChatComponentTranslation("msg.message_ocelot.txt"));
    }
}

Code:Main Class code note just the regester

@Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new DropHandler());
        MinecraftForge.EVENT_BUS.register(new ChatHandler());
        LogHelper.info("Init Complete!");


    }

Code: en_US.lang

#Chat Localizations
msg.message_ocelot.txt=Kill ocelot for its tooth

 

I think it might be were I'm registering it but I'm not sure

 

Thanks in advanced

~SureShotM/Leo~

~SureShotM/Leo~ gaming coding all around fun!

Posted

Okay hi again, I am having another problem but this time I am trying to send a chat message to a player who joins a world with my mod in it.

I have looked around and found what I thought was the solution but its not working and everything else I find explains the same thing.

 

Code:ChatHandler

public class ChatHandler
{
    @SubscribeEvent
    public void onPlayerLog(PlayerEvent.PlayerLoggedOutEvent event)
    {

        event.player.addChatMessage(new ChatComponentTranslation("msg.message_ocelot.txt"));
    }
}

Code:Main Class code note just the regester

@Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new DropHandler());
        MinecraftForge.EVENT_BUS.register(new ChatHandler());
        LogHelper.info("Init Complete!");


    }

Code: en_US.lang

#Chat Localizations
msg.message_ocelot.txt=Kill ocelot for its tooth

 

I think it might be were I'm registering it but I'm not sure

 

Thanks in advanced

~SureShotM/Leo~

 

im fairly new modder but the event handler is a PlayerLoggedOutEvent if you want it for when the player logs it should be PlayerLoggedInEvent or something like that

Posted

Okay hi again, I am having another problem but this time I am trying to send a chat message to a player who joins a world with my mod in it.

I have looked around and found what I thought was the solution but its not working and everything else I find explains the same thing.

 

Code:ChatHandler

public class ChatHandler
{
    @SubscribeEvent
    public void onPlayerLog(PlayerEvent.PlayerLoggedOutEvent event)
    {

        event.player.addChatMessage(new ChatComponentTranslation("msg.message_ocelot.txt"));
    }
}

Code:Main Class code note just the regester

@Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new DropHandler());
        MinecraftForge.EVENT_BUS.register(new ChatHandler());
        LogHelper.info("Init Complete!");


    }

Code: en_US.lang

#Chat Localizations
msg.message_ocelot.txt=Kill ocelot for its tooth

 

I think it might be were I'm registering it but I'm not sure

 

Thanks in advanced

~SureShotM/Leo~

 

im fairly new modder but the event handler is a PlayerLoggedOutEvent if you want it for when the player logs it should be PlayerLoggedInEvent or something like that

 

oops I forgot to change it back when I was testing, Besides that note I just changed it back and it still doesn't work.

~SureShotM/Leo~ gaming coding all around fun!

Posted

if you want to translate the text to the one in your lang file i would do this

 

String stringToFormat = "modid.some.text";
player.addChatMessage(new ChatCompentText(I18n.format(stringToFormat, new Object[0])));

 

if its the registering of the event i dont know

Posted

if you want to translate the text to the one in your lang file i would do this

 

String stringToFormat = "modid.some.text";
player.addChatMessage(new ChatCompentText(I18n.format(stringToFormat, new Object[0]));

 

if its the registering of the event i dont know

Not to be a sticker here but one what is I18n supposed to be and second you need to remove the semi colon that is in between the parenthesis or it will through an error, other then that Ill give this a try and see if it helps

 

~SureShotM/Leo~ gaming coding all around fun!

Posted

the class I18n is mojangs official formatter to translate the given string to the text in the lang file for the currently selected language

 

as of the second semicolon i spotted that and updated right before you posted

Posted

the class I18n is mojangs official formatter to translate the given string to the text in the lang file for the currently selected language

 

as of the second semicolon i spotted that and updated right before you posted

 

O ok never knew that was how mojang runs that, and after trying it out that way it still did not work, I will keep it as is for now and I'll continue seeing if I can figure it out.

~SureShotM/Leo~ gaming coding all around fun!

Posted

the class I18n is mojangs official formatter to translate the given string to the text in the lang file for the currently selected language

 

as of the second semicolon i spotted that and updated right before you posted

 

O ok never knew that was how mojang runs that, and after trying it out that way it still did not work, I will keep it as is for now and I'll continue seeing if I can figure it out.

 

by seeing it do you mean untranslated text

Posted

the class I18n is mojangs official formatter to translate the given string to the text in the lang file for the currently selected language

 

as of the second semicolon i spotted that and updated right before you posted

 

O ok never knew that was how mojang runs that, and after trying it out that way it still did not work, I will keep it as is for now and I'll continue seeing if I can figure it out.

 

by seeing it do you mean untranslated text

well I'm using seeing as a loose term I mean that I'll continue to try to get it to work and keep looking back to this form if any other solutions come up. If you mean that seeing it in chat as untranslated text no I do not mean that.

I would like to note that all I am trying to do is send a chat message to on world enter/logging in

~SureShotM/Leo~ gaming coding all around fun!

Posted

here is the solution

 

note i am using a proxy and i have registerd in the FMLCommonHandler

 

EventHandler

public class PlayerEventHandler
{
@SubscribeEvent
public void onPlayerLog(PlayerEvent.PlayerLoggedInEvent event)
{
	event.player.addChatMessage(I18n.format("msg.message_ocelot.txt", newObject[0]));
}
}

 

LangFile

#Chat Localizations
msg.message_ocelot.txt=Kill ocelot for its tooth

 

ClientProxy

public class ClientProxy extends CommonProxy
{
@Override public void registerEventHandlers()
{
	FMLCommonHandler.instance().bus().register(new PlayerEventHandler());
}
}

 

ServerProxy

public class ServerProxy extends CommonProxy
{
public void registerEventHandlers() {} //Does nothing server side
}

 

CommonProxy

public abstract class CommonProxy implements IProxy
        @Override public void init()
{
	registerEventHandlers();
}

public void preInit() {}
public void postInit() {}
}

 

IProxy

public interface IProxy
{
public abstract void init();
public abstract void preInit();
public abstract void postInit();

public abstract void registerEventHandlers();
}

 

Main Mod File

@Mod(modid = "modId", version = "modVersion")
public class PlayersMod
{
@SidedProxy(serverSide = "modPackage.ServerProxy", modId = "modId", clientSide = "modPackage.ClientProxy")
public static IProxy proxy;;
    
    @Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
	proxy.init();
    }

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	proxy.postInit();
}

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	proxy.preInit();
}
}

 

screenshot in game: https://www.dropbox.com/s/kmc2xl3a47rioeb/2014-10-23_07.05.51.png?dl=0

Posted

here is the solution

 

note i am using a proxy and i have registerd in the FMLCommonHandler

 

EventHandler

public class PlayerEventHandler
{
@SubscribeEvent
public void onPlayerLog(PlayerEvent.PlayerLoggedInEvent event)
{
	event.player.addChatMessage(I18n.format("msg.message_ocelot.txt", newObject[0]));
}
}

 

LangFile

#Chat Localizations
msg.message_ocelot.txt=Kill ocelot for its tooth

 

ClientProxy

public class ClientProxy extends CommonProxy
{
@Override public void registerEventHandlers()
{
	FMLCommonHandler.instance().bus().register(new PlayerEventHandler());
}
}

 

ServerProxy

public class ServerProxy extends CommonProxy
{
public void registerEventHandlers() {} //Does nothing server side
}

 

CommonProxy

public class CommonProxy implements IProxy
        @Override public void init()
{
	registerEventHandlers();
}

public void preInit() {}
public void postInit() {}
}

 

IProxy

public interface IProxy
{
public abstract void init();
public abstract void preInit();
public abstract void postInit();

public abstract void registerEventHandlers();
}

 

Main Mod File

@Mod(modid = "modId", version = "modVersion")
public class PlayersMod
{
@SidedProxy(serverSide = "modPackage.ServerProxy", modId = "modId", clientSide = "modPackage.ClientProxy")
public static IProxy proxy;;
    
    @Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
	proxy.init();
    }

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	proxy.postInit();
}

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	proxy.preInit();
}
}

 

screenshot in game: https://www.dropbox.com/s/kmc2xl3a47rioeb/2014-10-23_07.05.51.png?dl=0

Your amazing that is exactly what I needed, now just kinda a side questing, in my lang file or at least for the message can I have the text have color and or bold and is this possible.

Sorry I don't work with lang files enough.

~SureShotM/Leo~ gaming coding all around fun!

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.