Posted August 16, 20214 yr 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
August 19, 20214 yr 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 August 20, 20214 yr by nomadsky link broke
August 20, 20214 yr 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)"
August 20, 20214 yr 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"
August 20, 20214 yr 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.