Jump to content

Recommended Posts

Posted (edited)

Trying to make sure I understand the lifecycle and best practices properly. The problem is, many tutorials, code examples, and even the docs, use practices that are either definitely outdated or contradict the logic that many people here have put forward. So I'm just going to start putting them here when I see something I think is like that. If anyone can clarify on any given code example, that would be great. I'll try to make the code examples isolated and clear what particular practice or aspect I am asking about.

Edited by devguydan
Outdated

I hate signatures, they're too distracting

Posted

First, I often have been seeing this. Where it is recommended to register/create blocks, items and entities in pre-init. Instead of in EventHandlers. I even saw one case where it was said EventHandlers run B4 pre-init, but after debugging, I found that was not the case. What is the current best practice in this regard?  

 

Here is an example of this practice

/**
 * Run before anything else. Read your config, create blocks, items, etc, and register them with the GameRegistry
 */
public void preInit()
{
  // register my Items, Blocks, Entities, etc
}

 

I hate signatures, they're too distracting

Posted (edited)

Registering stuff in the registry events specifically designed for registering blocks, items, etc. is usually best practice unless you have a good reason to do otherwise (you'll know if you run into that kind of situation).  Using the registry events generally puts things in the right execution order "automagically", as well as letting other modders predict when certain things will happen in a general sense even if they've never seen your source or don't even know your mod will be running alongside theirs (eg. if they're altering something fairly global).

 

As for when you create the stuff...you'll get varied answers.  I usually try to create whatever I'm going to register directly in the registration call if doing so is feasible.

 

Edit: Righto, I should've posted what Ugdhar did, but I'm half asleep and didn't think of it :P

Edited by Laike_Endaril
Posted

1. As for good tutorials, TGG made a text-based one (personally, I would say this is one of the best tutorials out there as it explains every single concept in great detail (apart from the usage of the common proxy)) :

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample

 

2. Forge has an event handling system which makes processes like registering items and blocks easier. Always instantiate and register blocks/items in the corresponding event.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

See that’s what I mean.  He uses common proxy and he doesn’t use even handlers for registration. Yet every one still recommends him as an example?

  • Like 1

I hate signatures, they're too distracting

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.