Jump to content

[Solved] Only client-side chat, how to react to message send by player (me)?


Recommended Posts

Posted

Hello,

 

I am at really early phase of learning how to mod Minecraft with forge, but I was unable to google and learn few things. One of them is how to work with chat.

 

From what I understand, there are two ways how to write a mod. One way is client only (I suppose there is no interaction with server), and the other way is mod communicating with server.

 

I would like to create the mod that will work only in my single player game (I, for now, have no intentions of leaving this working on any server). My mod should take over player and control his movement, be able to mine, craft, eventually, etc. But I am only at the beginning now. Mod would react to command posted to chat "/runbot".

 

I understand that in order to find out that message "/runbot" was sent to chat, I should @SubscribeEvent? But what event would it be? I would imagine maybe overriding some method, that would take string as parameter, which I would then compared to "/runbot" and if comparison succeeded, I would start my bot. Is that how would I do that? And what event(s) should I subscribe to in order to read chat message send by me and myself only.

 

I searched this forum thoroughly, but haven't find satisfactory answer. Thanks in advance for any help provided!


Edit(s):

* Apparently I was confused about how the 'clientside' and 'serverside' are working. It is perfectly described in this tutorial.


Working solution: Only client-side chat reaction to commands send by player

 

First of all, there is no need to subscribe any event or anything like this - only to register command via proxy. In my design (inspired probably by wuppy's tutorials), I have class ClientProxy that contains public void registerRenderers() method with contents as follows:

 

public class ClientProxy extends CommonProxy {
    @Override
    public void registerRenderers() {
        ClientCommandHandler.instance.registerCommand(new TestCommand()); // This is the chat command registration I will talk about a bit bellow
    }
}

 

In my main mod class (for example: ExampleMod.java) I used following code to make my ClientProxy accessible:

@SidedProxy(clientSide = "com.example.examplemod.ClientProxy")
public static CommonProxy proxy;

 

And in the very same class in init method I called proxy.registerRenderers().

 

Registration of the command in the first snippet of code is provided by ClientCommandHandler method registerCommand(). Command definition is then defined in the class TestCommand, which has to extend from CommandBase class. There are, of course, some methods to override. See the code bellow.

 

public class TestCommand extends CommandBase {


    @Override
    public String getCommandName()
    {
        return "TestCommand";
    }

    @Override
    public String getCommandUsage(ICommandSender p_71518_1_)
    {
        return "/TestCommand <FirstParam> <SecondParam> [ThirdParam]";
    }

    // Older versions (<1.9) had instead of execute method processCommand method (without MinecraftServer parameter)
    @Override
    public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws WrongUsageException {
        
        // Makes minecraft show returned content of getCommandUsage() method 
        if (args.length < 2)
            wrongUsage(sender);

        // Display something to chat || do something else entirely
        // In versions < 1.9, there was new ChatTextComponent instantiated instead of TextComponentString
        sender.addChatMessage(new TextComponentString("Something to be displayed in chat..."));


    }

    public void wrongUsage(ICommandSender sender) throws WrongUsageException {
        throw new WrongUsageException(getCommandUsage(sender));
    }
}

Posted

Hello,

 

I am at really early phase of learning how to mod Minecraft with forge, but I was unable to google and learn few things. One of them is how to work with chat.

 

From what I understand, there are two ways how to write a mod. One way is client only (I suppose there is no interaction with server), and the other way is mod communicating with server.

 

I would like to create the mod that will work only in my single player game (I, for now, have no intentions of leaving this working on any server). My mod should take over player and control his movement, be able to mine, craft, eventually, etc. But I am only at the beginning now. Mod would react to command posted to chat "/runbot".

 

I understand that in order to find out that message "/runbot" was sent to chat, I should @SubscribeEvent? But what event would it be? I would imagine maybe overriding some method, that would take string as parameter, which I would then compared to "/runbot" and if comparison succeeded, I would start my bot. Is that how would I do that? And what event(s) should I subscribe to in order to read chat message send by me and myself only.

 

I searched this forum thoroughly, but haven't find satisfactory answer. Thanks in advance for any help provided!


Edit(s):

* Apparently I was confused about how the 'clientside' and 'serverside' are working. It is perfectly described in this tutorial.


Working solution: Only client-side chat reaction to commands send by player

 

First of all, there is no need to subscribe any event or anything like this - only to register command via proxy. In my design (inspired probably by wuppy's tutorials), I have class ClientProxy that contains public void registerRenderers() method with contents as follows:

 

public class ClientProxy extends CommonProxy {
    @Override
    public void registerRenderers() {
        ClientCommandHandler.instance.registerCommand(new TestCommand()); // This is the chat command registration I will talk about a bit bellow
    }
}

 

In my main mod class (for example: ExampleMod.java) I used following code to make my ClientProxy accessible:

@SidedProxy(clientSide = "com.example.examplemod.ClientProxy")
public static CommonProxy proxy;

 

And in the very same class in init method I called proxy.registerRenderers().

 

Registration of the command in the first snippet of code is provided by ClientCommandHandler method registerCommand(). Command definition is then defined in the class TestCommand, which has to extend from CommandBase class. There are, of course, some methods to override. See the code bellow.

 

public class TestCommand extends CommandBase {


    @Override
    public String getCommandName()
    {
        return "TestCommand";
    }

    @Override
    public String getCommandUsage(ICommandSender p_71518_1_)
    {
        return "/TestCommand <FirstParam> <SecondParam> [ThirdParam]";
    }

    // Older versions (<1.9) had instead of execute method processCommand method (without MinecraftServer parameter)
    @Override
    public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws WrongUsageException {
        
        // Makes minecraft show returned content of getCommandUsage() method 
        if (args.length < 2)
            wrongUsage(sender);

        // Display something to chat || do something else entirely
        // In versions < 1.9, there was new ChatTextComponent instantiated instead of TextComponentString
        sender.addChatMessage(new TextComponentString("Something to be displayed in chat..."));


    }

    public void wrongUsage(ICommandSender sender) throws WrongUsageException {
        throw new WrongUsageException(getCommandUsage(sender));
    }
}

Posted

Hello,

 

I am at really early phase of learning how to mod Minecraft with forge, but I was unable to google and learn few things. One of them is how to work with chat.

 

From what I understand, there are two ways how to write a mod. One way is client only (I suppose there is no interaction with server), and the other way is mod communicating with server.

 

I would like to create the mod that will work only in my single player game (I, for now, have no intentions of leaving this working on any server).

 

No, in Minecraft (and many other games) there is client side and server side. The client side does rendering and is different per player. The server side does updating tasks etc.

Posted

Hello,

 

I am at really early phase of learning how to mod Minecraft with forge, but I was unable to google and learn few things. One of them is how to work with chat.

 

From what I understand, there are two ways how to write a mod. One way is client only (I suppose there is no interaction with server), and the other way is mod communicating with server.

 

I would like to create the mod that will work only in my single player game (I, for now, have no intentions of leaving this working on any server).

 

No, in Minecraft (and many other games) there is client side and server side. The client side does rendering and is different per player. The server side does updating tasks etc.

Posted

Thank you for your reply.

 

So even when I want to make 'single player' mod, I have to count in the 'server side'.

 

If I want to react to message sent from the 'client' (I manually type in the game "/runbot"), I have to intercept this message "on server"? How will I do it then, please?

Posted

Thank you for your reply.

 

So even when I want to make 'single player' mod, I have to count in the 'server side'.

 

If I want to react to message sent from the 'client' (I manually type in the game "/runbot"), I have to intercept this message "on server"? How will I do it then, please?

Posted
No, in Minecraft (and many other games) there is client side and server side. The client side does rendering and is different per player. The server side does updating tasks etc.

 

Note that Survival Single Player is still a Client/Server relationship.

 

It's a local server thread with a single player connected.

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
No, in Minecraft (and many other games) there is client side and server side. The client side does rendering and is different per player. The server side does updating tasks etc.

 

Note that Survival Single Player is still a Client/Server relationship.

 

It's a local server thread with a single player connected.

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

Again, thanks for your replies, Draco18s & diesieben07, I put to use both of them.

 

Now when I believe I solved my problem I also updated original post to be more descriptive and contained my solution. Would you mind looking at the facts I provided and validating them? I would like to avoid confusing visitors coming from search engine.

Posted

Again, thanks for your replies, Draco18s & diesieben07, I put to use both of them.

 

Now when I believe I solved my problem I also updated original post to be more descriptive and contained my solution. Would you mind looking at the facts I provided and validating them? I would like to avoid confusing visitors coming from search engine.

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

    • ahh yes I mean waystone. Thank you very much helped alot  cheers mate!
    • Do you mean waystones?   You can use KubeJS to remove and add a changed recipe for it: https://www.curseforge.com/minecraft/mc-mods/kubejs   Add KubeJS and start the modpack once to generate the files for the mod   In your modpack folder, you will find now a kubejs folder Go to server_scripts (create the folder if missing) - yes, also for singleplayer, use the server_scripts folder Create a new file "reciperemove.js" Edit this file and add the recipe for the waypoint mod: ServerEvents.recipes(event => { let toRemove = [ {output: 'waystones:example_item'}, ]; for (const remove of toRemove) { event.remove(remove); } }) Just make sure you are using the correct item ID   Create another file "recipes.js" in the server_scripts folder and use: ServerEvents.recipes(event => { event.shaped( Item.of('waystones:example_item'), [ 'AAA', 'BCB', 'AAA' ], { A: 'minecraft:stone', B: 'waystones:item_1', C: 'waystones:item_2' } ) })   The Letter Block with AAA etc is a crafting table - so there you define the recipe and the items      
    • I am currently making a modpack for myself and I want to change the recipe for waypoints*. How do I do this? Is there a simply way to change an existing recipe (or to delete the old one and make a new one). I only need a for 1 single player world. My coding Knowledge is limited to arduinos but I feel I could teach myself some Java if needed *waypoint mod by BlayTheNinth
    • Tired of the same old iron sword and pickaxe? Dive into a world of enhanced possibilities with Droid's Implements! This exciting addition to your Minecraft experience introduces:   Four Unique Weapons:    Daggers: Quick, cheap, and effective, great for agility. Applies Weakness for one minute. Warhammers: A powerful option for defeating strong enemies. Applies Harming for a quarter of a second, making it ineffective against the undead. Spears: A balanced weapon with fair damage and speed. Applies Mining Fatigue, making escape difficult for cornered enemies. Clubs: Hard-hitting yet slow, the club is a robust alternative to the sword. Applies Slowness, increasing the chance of catching your enemy.   Two Handy Tools:   The Mining Hammer: A worthwhile alternative to the pickaxe, the Mining Hammer mines in a 3x3 area, making mining stone more efficient. The Heavy Shovel: A beneficial substitute to the shovel, the Mining Hammer mines in a 3x3 area, making mining sand and gravel more efficient.   Damage Comparison: Dagger > Spear > Sword = Club > Warhammer     Check it out now!
  • Topics

×
×
  • Create New...

Important Information

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