Jump to content

why is registerItems and registerRenders events firing before preinit?


skeddles

Recommended Posts

I thought I did this just how I did last time, but for some reason when I run this code, the register items and renders events in the item class come before the preInit event from my main class. What did I do wrong?

 

showing the order:

[13:37:42] [main/INFO] [FML]: Applying holder lookups
[13:37:42] [main/INFO] [FML]: Holder lookups applied
[13:37:42] [main/INFO]: [STDOUT]: SIGN VARIETY registerItems() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[13:37:42] [main/INFO] [FML]: Applying holder lookups
[13:37:42] [main/INFO] [FML]: Holder lookups applied
[13:37:42] [main/INFO] [FML]: Applying holder lookups
[13:37:42] [main/INFO] [FML]: Holder lookups applied
[13:37:42] [main/INFO]: [STDOUT]: SIGN VARIETY registerRenders() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[13:37:42] [main/INFO] [FML]: Applying holder lookups
[13:37:42] [main/INFO] [FML]: Holder lookups applied
[13:37:42] [main/INFO] [FML]: Injecting itemstacks
[13:37:42] [main/INFO] [FML]: Itemstack injection complete
[13:37:42] [Forge Version Check/INFO] [ForgeVersionCheck]: [forge] Found status: UP_TO_DATE Target: null
[13:37:42] [Thread-3/INFO] [FML]: Using sync timing. 200 frames of Display.update took 53019200 nanos
[13:37:43] [Sound Library Loader/INFO]: Starting up SoundSystem...
[13:37:43] [Thread-5/INFO]: Initializing LWJGL OpenAL
[13:37:43] [Thread-5/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[13:37:43] [Thread-5/INFO]: OpenAL initialized.
[13:37:43] [Sound Library Loader/INFO]: Sound engine started
[13:37:45] [main/INFO] [FML]: Max texture size: 16384
[13:37:45] [main/INFO]: Created: 512x512 textures-atlas
[13:37:46] [main/INFO]: [STDOUT]: signvariety:init
[13:37:46] [main/INFO]: [STDOUT]: signvariety:preInit
[13:37:46] [main/INFO]: [STDOUT]: SIGN VARIETY init() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[13:37:46] [main/INFO] [FML]: Injecting itemstacks

 

main java file:

 

package signvariety;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

@Mod(modid = signvariety.MODID, version = signvariety.VERSION)
public class signvariety
{
    public static final String MODID = "signvariety";
    public static final String VERSION = "1.0.0";

    @EventHandler
    public void preInit(FMLInitializationEvent event) {
        Items.init();
    }
}

 

items java file

 

package signvariety;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber(modid="signvariety")
public class Items {


    private static Item mySign;

    public static void init () {
        System.out.println("SIGN VARIETY init() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

        mySign = new SignItem("mySign");
    }

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        System.out.println("SIGN VARIETY registerItems() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

        //event.getRegistry().registerAll(mySign);

    }


    @SubscribeEvent
    public static void registerRenders(ModelRegistryEvent event) {

        System.out.println("SIGN VARIETY registerRenders() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

        //ModelLoader.setCustomModelResourceLocation(mySign, 0, new ModelResourceLocation(mySign.getRegistryName(), "inventory"));
    }
}
Link to comment
Share on other sites

13 minutes ago, skeddles said:

public void preInit(FMLInitializationEvent event)

Even though this is named preInit it actually fires during init due to the parameter you've specified.

 

13 minutes ago, skeddles said:

public static void init () {  mySign = new SignItem("mySign"); }

Don't do this. Instantinate your items in the appropriate registry event and there only.

 

 

Edited by V0idWa1k3r
  • Like 1
Link to comment
Share on other sites

3 minutes ago, V0idWa1k3r said:

Even though this is named preInit it actually fires during init due to the parameter you've specified.

 

Don't do this. Instantinate your items in the appropriate registry event and there only. 

 

 

Is that registerItems? I moved it there and it seems to work.  I was following this guide which tells you to do it the other way.

Link to comment
Share on other sites

1 hour ago, V0idWa1k3r said:

If you need a reference to that object later you can use ObjectHolders.

Or you could just instantiate the object directly. IE

RegistryEvent()

Object o = new Object()

Event.register(o)

 

Obviously you could add all of the objects into a set via their constructor for the simplicity of registering. Plus ObjectHolder is broken in Java 9 and will probably not be in the 1.13 release of forge.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

On 10/10/2018 at 6:31 AM, Animefan8888 said:

Or you could just instantiate the object directly. IE

RegistryEvent()

Object o = new Object()

Event.register(o)

 

Obviously you could add all of the objects into a set via their constructor for the simplicity of registering. Plus ObjectHolder is broken in Java 9 and will probably not be in the 1.13 release of forge.

Why won’t they be in 1.13? I think that they’re a great addition, and are vital due to their potential for adding & removing mods ingame

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

47 minutes ago, Cadiboo said:

Why won’t they be in 1.13? I think that they’re a great addition, and are vital due to their potential for adding & removing mods ingame

The modules added in java 9, ObjectHolder uses reflection to populate the variables.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

The modules added in java 9, ObjectHolder uses reflection to populate the variables.

I don’t understand, I’ll make a new topic

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.