Jump to content

Send message trough player 1.16.5


nomadsky

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

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

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

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