Jump to content

[1.12.2] chat bot / chat listener not listening


kekmane

Recommended Posts

package wmwwmnn.mod;


import java.awt.List;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ServerChatEvent;
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.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import wmwwmnn.mod.proxy.CommonProxy;
import wmwwmnn.mod.util.ref;
import net.minecraftforge.client.event.ClientChatEvent;
@Mod(modid = ref.MOD_ID, name = ref.NAME, version = ref.VERSION) 
public class Main {

	@Instance
	public static Main Instance;
	
	@SidedProxy(clientSide = ref.CLIENT_PROXY_CLASS, serverSide = ref.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{
	
	}
	
	@EventHandler
	public static void init(FMLInitializationEvent event)
	{
		MinecraftForge.EVENT_BUS.register(new ClientChatEvent(null));
	}
	
	@EventHandler
	public static void Postinit(FMLPostInitializationEvent event)
	{

	}
	@Mod.EventBusSubscriber
	public class MyForgeEventHandler {
		
	 	@SubscribeEvent
	 	
	 	public void onChat(ClientChatEvent event) {
	 		System.out.println("msg");
	 		String msg = event.getMessage();
	 		System.out.println("ClientChatEvent: " + msg);
	 		if (msg.contains("Hello")) {
	 			Minecraft.getMinecraft().player.sendChatMessage("Hi Yourself!");
	 		} else if (msg.contains("Bye")) {
	 			Minecraft.getMinecraft().player.sendChatMessage("Later!");
	 		}
	 	}
	 	}
}
	 	

im a noob btw im trying to port a bot from a javascript api to a mod instead of nodejs,

Link to comment
Share on other sites

yeah i did it the right way but its giving me an error on the event bus but its saying that i should create a variable of my handler, i guess it doesnt thing that myforgeeventhandler is real, 

 

package wmwwmnn.mod;


import java.awt.List;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ServerChatEvent;
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.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import wmwwmnn.mod.proxy.CommonProxy;
import wmwwmnn.mod.util.ref;
import net.minecraftforge.client.event.ClientChatEvent;
@Mod(modid = ref.MOD_ID, name = ref.NAME, version = ref.VERSION) 
public class Main {s
	@Instance
	public static Main Instance;
	
	@SidedProxy(clientSide = ref.CLIENT_PROXY_CLASS, serverSide = ref.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{
	
	}
	
	@EventHandler
	public static void init(FMLInitializationEvent event)
	{
		MinecraftForge.EVENT_BUS.register(MyForgeEventHandler()));
	}
	
	@EventHandler
	public static void Postinit(FMLPostInitializationEvent event)
	{

	}
	public class MyForgeEventHandler {
		
	 	@SubscribeEvent
	 	
	 	public void onChat(ClientChatEvent event) {
	 		System.out.println("msg");
	 		String msg = event.getMessage();
	 		System.out.println("ClientChatEvent: " + msg);
	 		if (msg.contains("Hello")) {
	 			Minecraft.getMinecraft().player.sendChatMessage("Hi Yourself!");
	 		} else if (msg.contains("Bye")) {
	 			Minecraft.getMinecraft().player.sendChatMessage("Later!");
	 		}
	 	}
	 	}
}
	 	

 

Link to comment
Share on other sites

MinecraftForge.EVENT_BUS.register(MyForgeEventHandler()));

to

MinecraftForge.EVENT_BUS.register(new MyForgeEventHandler());

 

This is basic Java and you really should learn the basics for it before you start. Learning the absolutely needed basics can be done fairly quickly.

Also, you should ignore upper/lower case.

Link to comment
Share on other sites

3 hours ago, CAS_ual_TY said:

MinecraftForge.EVENT_BUS.register(MyForgeEventHandler()));

to

MinecraftForge.EVENT_BUS.register(new MyForgeEventHandler());

 

This is basic Java and you really should learn the basics for it before you start. Learning the absolutely needed basics can be done fairly quickly.

Also, you should ignore upper/lower case.

tried that already. i would have pasted that version but i just posted the current one that i had

 

also didnt work

Edited by kekmane
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.