Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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.

  • Author

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

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.