skeddles Posted October 9, 2018 Posted October 9, 2018 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")); } } Quote
V0idWa1k3r Posted October 9, 2018 Posted October 9, 2018 (edited) 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 October 9, 2018 by V0idWa1k3r 1 Quote
skeddles Posted October 9, 2018 Author Posted October 9, 2018 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. Quote
V0idWa1k3r Posted October 9, 2018 Posted October 9, 2018 6 minutes ago, skeddles said: Is that registerItems? Yeah. In general anything that is a part of the registry should be instantinated in the appropriate registry event. If you need a reference to that object later you can use ObjectHolders. 1 Quote
Animefan8888 Posted October 9, 2018 Posted October 9, 2018 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. Quote 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.
Cadiboo Posted October 12, 2018 Posted October 12, 2018 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 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Animefan8888 Posted October 12, 2018 Posted October 12, 2018 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. Quote 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.
Cadiboo Posted October 12, 2018 Posted October 12, 2018 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 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Recommended Posts
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.