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.

Featured Replies

Posted

I've been trying to do this for some hours now but can't seem to get this line to work...

Minecraft.getInstance().player.sendMessage(new TextComponentString("test"));

If you think there's something else that's messing things up feel free to check, note that this is my first time with forge. 

package com.generic_name.mod.core.event;

import com.generic_name.mod.TheMod;

import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid = TheMod.MOD_ID, bus = Bus.FORGE)
public class EventHandler {

	@SubscribeEvent
	public static void onLogging(final ClientPlayerNetworkEvent.LoggedInEvent event) {
		Minecraft.getInstance().player.sendMessage(new TextComponentString("test"));
	}
	
}

thank you for the help

  • Author

I'm trying to create a macro mod for a for 1.16.5 but most examples I can find of similar projects are so old that the code has been changed, i've been trying myself to just send a message when the player logins to get  "Minecraft.getInstance().player.sendMessage(new TextComponentString("test"));" to work but to be honest it feels like i'm just brute forcing it without it ever working. Just crashing when logging into the server... 

It feels like it should be simple but I don't get why it won't work...

Here's the whole code; (yes I asked a qustion about this before but without basically any details)

package com.name.themod.core.event;

import com.name.themod.TheMod;

import net.minecraft.client.Minecraft;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid = TheMod.MOD_ID, bus = Bus.FORGE)
public class EventHandler {

	@SubscribeEvent
	public static void onLogging(final ClientPlayerNetworkEvent.LoggedInEvent event) {
		Minecraft.getInstance().player.sendMessage(new TextComponentString("test"));
	}
	
}

I've used this as an example https://www.tabnine.com/code/java/classes/net.minecraft.util.text.TextComponentString but it says "TextComponentString" doesn't work, i've tried to change it to "StringTextComponent" but that doesn't work either., if anyone knows why this doesn't work i'd be grateful for the help!

Edited by nomadsky
link broke

  • Author

now it highlights "sendMessage" in red and if I hover over it it says "The method sendMessage(ITextComponent, UUID) in the type ClientPlayerEntity is not applicable for the arguments (StringTextComponent)"

  • Author

I've updated the line to include ITextComponent "Minecraft.getInstance().player.sendMessage((ITextComponent)new StringTextComponent("Test"));" but it still gives the same error with "sendMessage"

  • Author

I don't know if this is correct but I managed to get this to work;

@SuppressWarnings("resource")
@SubscribeEvent
public static void onLogging(final ClientPlayerNetworkEvent.LoggedInEvent event) {
	Minecraft.getInstance().player.sendMessage((ITextComponent)new StringTextComponent("Test"), null);
}

 

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...

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.