Jump to content

Recommended Posts

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

Posted

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.

Posted

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.

Posted

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?

Posted

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.

Posted

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.

Posted

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.

Posted

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

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

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