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

Hello, everyone.

I'm new to Forge and modding. I decided to try to make a couple of mods.

 

My first mod is to send a message in the public chat when client sees a certain message in the chat. Some sort of a bot.

So, here is what I got:

@EventHandler
    public void onChatRecieved(ClientChatReceivedEvent e){
    	if (e.message.getUnformattedTextForChat().contains("Bot, hi")){
    		Minecraft.getMinecraft().thePlayer.sendChatMessage("Troll");
    	}
    }

Full .class

 

package me.Artur_Gamez;

import net.minecraft.client.Minecraft;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid=Main.MODID, name=Main.MODNAME, version=Main.MODVER)
public class Main
{
    //Set the ID of the mod (Should be lower case).
    public static final String MODID = "Test Mod";
    //Set the "Name" of the mod.
    public static final String MODNAME = "Bot";
    //Set the version of the mod.
    public static final String MODVER = "0.0.1";

    @Instance(value = Main.MODID)
    public static Main instance;
        
    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
        
    }
        
    @EventHandler
    public void load(FMLInitializationEvent event){
    	FMLCommonHandler.instance().bus().register(this);

    }
        
    @EventHandler
    public void postInit(FMLPostInitializationEvent event){
    	
    }
    
    @EventHandler
    public void onChatRecieved(ClientChatReceivedEvent e){
    	if (e.message.getUnformattedTextForChat().contains("Bot, hi")){
    		Minecraft.getMinecraft().thePlayer.sendChatMessage("Troll");
    	}
    }
}

 

 

For some reason, this code is not working and I don't know why. When I say "Bot, hi" in the chat, it doesn't send "Troll" in the chat.

 

Can anyone help me? Will be much appreciated. :)

Well, for starters, you would have to retrieve the player that sent the text "Bot, hi". Then, send a message to that player.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Thanks you guys for replying to this thread. I read the replies and got some questions.

 

Well, for starters, you would have to retrieve the player that sent the text "Bot, hi". Then, send a message to that player.

 

I believe you think this mod is going to be a server side. No. I'm trying to create this mod for a client, so the client is going to be on a vanilla server.

The reason I do this, is I do not own this server. If I did, I could have just created a plugin for it.

 


 

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

 

Could you please explain what you mean by that?

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

 

Could you please explain what you mean by that?

 

Minecraft.getMinecraft().thePlayer is the client side local player.  If the bot tries to access this it will simply access itself.

 

If the code is running on a server, it will simply crash.  That's it, server's 404.  Game over man, game over.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

You have to talk to the server to send something back to the player.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

  • Author

You have to talk to the server to send something back to the player.

 

I want to make it like Twitch Bot. Its going to do something if a player typed something in the chat. And I dont want to touch the server side.

  • Author

ClientChatReceivedEvent is a forge event, not an FML lifecycle event like FMLPreInitializationEvent.

Read a tutorial on forge events.

 

Do you mean I registered the event wrong?

He's probably a very "bold" person. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

  • Author

Ok, so. I think that I got the event part. But the question is, how to get client to send a message in the server chat?

 

He's probably a very "bold" person. :P

 

Ha ha. Ha. You are a very "funny" person. -.-

  • 2 months later...

Well after just testing this for a project i'm working on. Your issue is this line.

 

if (e.message.getUnformattedTextForChat().contains("Bot, hi")){

 

You need to change it to this

if (e.message.getUnformattedText().contains("Bot, hi")){

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.