Jump to content

[1.15.2] Client side, access PlayerController


MetalHurlant

Recommended Posts

Hi, I am new here. I downloaded the mdk and tried basic things as log something when an event is triggered or a sound played.


I spent my afternoon and evening trying to find a way to make my player do something (walking, use its item, ...) but I did not found how to do it.
I know it was possible in 1.14.4, because I used the autoFish mod, I used as example.

 

But I did not found the way to access the PlayerController. 

I found that I need to import it:

import net.minecraft.client.Minecraft;

In this class I found:

public static Minecraft getInstance() {
    return instance;
}

And I expected to use this instance to get the PlayerController

 

So in the mdk I tried this:

@Mod("examplemod")
public class ExampleMod
{
    private Minecraft minecraftClient;

    public ExampleMod() {
        this.minecraftClient = Minecraft.getInstance();
    }
}

 

I am able to generate the .jar but when I launch Minecraft I get:

java.lang.NoSuchMethodError: net.minecraft.client.Minecraft.getInstance()Lnet/minecraft/client/Minecraft;

 

Does someone know how to do?

 

Thank you ?

 

 

Link to comment
Share on other sites

2 hours ago, unassigned said:

You need to read up on sides. You can't directly access minecraft in your mod constructor like that, as the server has no idea what the client Minecraft class is.

@unassigned Thanks, it helped me understand that there is a difference between physical and logical server/client.

 

But I can not figure how this should work.

I tried:

ExampleMod.java

@Mod("examplemod")
public class ExampleMod
{
    public ExampleMod() {
        DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ExampleModClient.register());
    }
}

 

ExampleModeClient.java

public class ExampleModClient
{
    private static final Logger LOGGER = LogManager.getLogger();

    public static void register() {
        LOGGER.info("ExampleMod: register");
        Minecraft minecraftClient = Minecraft.getInstance();
    }
}

 

But I get the same thing that before.

 

I think that the thing I need is the minimal code to get the minecraft client object.

 

Thanks you

 

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

You need to use the gradle build task to export your mod after you're done, otherwise it will not be re-obfuscated and not work outside the development environment.

Ok thanks. I am now able to do something ?

 

I juste needed to use .\gradlew build and not graddle jar to generate my .jar (in Powershell)

 

Have a good day all

 

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