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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • What MC version? What's the IP? Are any mods needed to be able to join?
    • Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20   I found this code : KeyMapping.click(Minecraft.getInstance().options.keyUp.getKey()); But it doesn't seems to work   And i found this one : Minecraft.getInstance().options.keyUp.setDown(true); wich works but doesn't exactly do what i want , it doesn't release the key so for exemple i can't make him run. Minecraft.getInstance().options.keyUp.setDown(true); Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(true); doesn't make him run
    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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