Jump to content

Help getting started


Malonromani

Recommended Posts

Hello, I am very new to Minecraft modding, and I wanted to create a test mod just to see how everything works.  I thought I could at least try to show a chat message saying "Hello World" when the player starts up a world.

 

The problem is, I don't know where to start.

 

The example mod that comes with the MDK doesn't really explain what it's doing.  I can see that it is adding listener methods to a FMLJavaModLoadingContext object,  and the comments say that it is registering these methods for modloading.

 

I don't know what any of that means.

 

Could someone help walk me through the example, and maybe help me get my Hello World project going?

Link to comment
Share on other sites

I would say read through the forge documentation and maybe look through some of Mcjty tutorials. If you don't have an intermediate understanding of Java, please go learn the language.

 

To answer your question, FMLJavaModLoadingContext is basically a helper to get the current mod's event bus to register mod specific events. IEventBus#addListener basically takes in a Consumer that contains a parameter extending Event, the base for all forge events. Since Consumer is a functional interface, we can use Java 8 to reference specific functions within our class that has a parameter extending Event. This is why you see:

modEventbus.addListener(this::function);

This allows us to specify a specific event type to execute for. 

 

As for your hello world project, you can look within the forge source provided to find the correct event you might need to use (e.g. PlayerEvent$PlayerLoggedInEvent should work). If you looked at the reference calls it makes, you would see that the event is called on the forge event bus, so you would need to either add a listener to a non-static method or subscribe it to your mod's event bus using an annotation on a static method. From there, you will probably find the method PlayerEntity#sendStatusMessage. Note that this method only has relevance on the logical server.

 

Hope this helps.

Link to comment
Share on other sites

Thanks for the tutorial link.  I've had a hard time finding any tutorials or beginner-level code examples for 1.15.

 

Java was my first coding language, but I've mostly been using C# since 2012, so I'm a little rusty, and some things like annotations are new to me.  I'm also more used to programming business software rather than games.

 

I'm still confused about the event bus. Does it pick up events from the Minecraft application?  I don't quite see how it connects.  Maybe I need to relearn how event listeners and handlers work.  I'll try looking at it again tomorrow when I'm more awake.

 

I'm also not sure how to look at the Forge source.  The documentation site is just a few examples and not much else, as far as I can tell.

Link to comment
Share on other sites

This is where they are in Eclipse, IntelliJ will have a similar window, as will any other IDE.

image.png.1d8cea26c2b45093a49323c355a050db.png

The first one is all of the code and assets provided by Forge, the second one will have loot tables, blockstate files, models, and textures.

I happen to have 1.14 open currently, but this is consistent across versions.

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.

Link to comment
Share on other sites

23 minutes ago, Draco18s said:

This is where they are in Eclipse, IntelliJ will have a similar window, as will any other IDE.

image.png.1d8cea26c2b45093a49323c355a050db.png

The first one is all of the code and assets provided by Forge, the second one will have loot tables, blockstate files, models, and textures.

I happen to have 1.14 open currently, but this is consistent across versions.

The client-extra.jar is the one with the loot tables and such, the second forge jar is the launcher I believe.

  • Like 1
Link to comment
Share on other sites

1 hour ago, Ugdhar said:

The client-extra.jar is the one with the loot tables and such, the second forge jar is the launcher I believe.

Oops, yes,  you're right. I made that before I had my morning caffeine.

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.

Link to comment
Share on other sites

Oh geez, I somehow didn't notice the "External Libraries" section in Intellij's sidebar underneath the project. I was too busy looking at the folders inside the project.  This is what I get for trying to learn my way around a new IDE and a new set of libraries all at once.

 

Thanks for pointing that out, as well as letting me know which libraries in the list to look at.

 

I also found the event bus code, and along with the explanation, it's making a lot more sense to me now. It's one big object keeping a map of all listener methods to the objects they're listening to. 

 

Edit:

Thanks to everyone's help, I was able to register a PlayerLoggedInEvent listener with the EVENT_BUS and got my "Hello World!"

Malon Hello World Success.png

Edited by Malonromani
  • Like 1
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.