Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Execute command from within mod


namarino41
 Share

Recommended Posts

Hello. I'm creating an item that executes a command when you use it. Don't ask why, there's a reason why I'm going this route instead of just calling the code the command actually executes. Can someone help with this? Everything resource I've found has been for older versions. Would appreciate any help you can provide. Thank you!

Link to comment
Share on other sites

47 minutes ago, namarino41 said:

Can anyone give me a little more detail? I'm on 1.16.5. 

In the package net.minecraft.command there is a class Commands.class that has the functions that execute commands. If you read the code you'll be able to see how it's done.

Link to comment
Share on other sites

On 7/11/2021 at 5:27 AM, namarino41 said:

Hello. I'm creating an item that executes a command when you use it. Don't ask why, there's a reason why I'm going this route instead of just calling the code the command actually executes. Can someone help with this? Everything resource I've found has been for older versions. Would appreciate any help you can provide. Thank you!

I have the same problem too, but I still can't figure it out. Did you find anything helpful?

Link to comment
Share on other sites

Posted (edited)
10 hours ago, diesieben07 said:

The answers were already given above...?

Those were hardly answers. Would be nice to be given some examples. Could you provide us with some more help?

Edited by namarino41
Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

You have been told exactly which method you need to call. If you don't know how to call methods you need to go and learn Java before modding.

I know how to call methods, thanks. There are other things you need to pass into those methods that I can't get, like the commandsource.

Link to comment
Share on other sites

Posted (edited)
6 minutes ago, diesieben07 said:

Look at where Minecraft calls this method and see what it does to create the CommandSource.

Ok will do. I would recommend being a little more polite in the future also. I've seen a number of your posts and many of them come across as pretty rude and condescending. Don't assume that because someone is asking a question you think is stupid, he's deserving of that sort of attitude. Ignorance isn't stupidity.

Edited by namarino41
Link to comment
Share on other sites

1 minute ago, namarino41 said:

Ok will do. I would recommend being a little more polite in the future also. I've seen a number of your posts and many of them come across as pretty rude and condescending. Don't assume that because someone is asking a question you think is stupid, he's deserving of that sort of attitude. Ignorance isn't stupidity.

I am perfectly polite, just direct and to the point.

  • Like 1
Link to comment
Share on other sites

8 hours ago, namarino41 said:

I know how to call methods, thanks. There are other things you need to pass into those methods that I can't get, like the commandsource.

I can remember that there was a Dummy CommandSource, unfortunately I don't know whether it still exists and if so in which class, I also don't know whether you should use it.

which command do you want to execute? since there is usually another possibility to execute the command code without using a command

Link to comment
Share on other sites

18 minutes ago, Luis_ST said:

I can remember that there was a Dummy CommandSource, unfortunately I don't know whether it still exists and if so in which class, I also don't know whether you should use it.

which command do you want to execute? since there is usually another possibility to execute the command code without using a command

Yeah unfortunately there are some commands that another mod makes available and I want to call those. Sounds weird, but there's a reason for it, trust me haha. Problem I'm facing right now is I can't seem to get a server instance that isn't null...

Link to comment
Share on other sites

28 minutes ago, namarino41 said:

Yeah unfortunately there are some commands that another mod makes available and I want to call those. Sounds weird, but there's a reason for it, trust me haha. Problem I'm facing right now is I can't seem to get a server instance that isn't null...

Hmm. Can you make the other mod a dependency and then call the methods from the other mod directly? I'm not experienced at all in mods let alone inter-mod functionality, but if that's possible, it'd be the right way to do it, I think.

Link to comment
Share on other sites

1 hour ago, Luis_ST said:

I can remember that there was a Dummy CommandSource

ICommandSource.DUMMY

The second parameter is a string where is the command inserted, e.g. "/gamemode survival". And then it will just print an error message if the command cannot be executed.

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.

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.