Jump to content

[SOLVED] addChatMessage() doesn't recognize argument as IChatComponent


JoelJansenD

Recommended Posts

Good evening lads and lasses,

 

I am having a little problem while trying to display a chat message with an item. I want to do this through the addChatMessage() method, however it thinks my given argument is a String and not an IChatComponent. I have tried looking through the source however it didn't help me. Browsing the web and the Forge forum haven't given me an answer either.

 

@Override
public boolean func_111207_a(ItemStack itemstack, EntityPlayer player, EntityLivingBase target){
if(!target.worldObj.isRemote){
	player.addChatMessage("Test");
}
return false;
}

 

This is what the troubling part of the code looks like. I have done exactly the same thing as some examples on the internet, that all worked perfectly fine according to the original programmer. Even directly copied a bit once, however it didn't work...

 

Summary

the method addChatMessage thinks the given argument is a String instead of IChatComponent

Link to comment
Share on other sites

Thanks for the quick responses! :)

 

Of course it "thinks" it is a String, because it IS a String.

Pass an instance of IChatComponent. You probably want ChatComponentText. The tutorials you are looking at are for older minecraft versions.

Haha, I had figured it's a String which led to my confusion. I'll look into ChatComponentText. Thank you.

 

Here's how I handle incoming chat. Maybe it'll help you a little.

 

String formatted = event.message.getUnformattedText().replaceAll("§(.)", "§$1§l");
event.message = new ChatComponentText(formatted);

 

event.message is an IChatComponent.

I'll look into this one as well if diesieben07's solution doesn't work. Thank you.

 

 

EDIT: diesieben07's solution was perfect, thank you :D

Link to comment
Share on other sites

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.