PhilipChonacky Posted May 31, 2019 Share Posted May 31, 2019 Hi, I've been testing basic modding in 1.13 and getting trouble connecting to the model files for items & blocks I believe I am correctly assigning rResourceLocations, and the files are in the right place, but the logs indicate IO errors locating them This is an excerpt from my class for creating items. itemList is an ArrayList<Item> which will be assigned to a static list in the main method (ChickenMod.ITEMS) iterated in another class for registration (The iteration of the <Block> Array (ChickenMod.BLOCKS) is to add the required ItemBlocks to the registration list. private static void NewItem(String name, ItemGroup tab) { Item thisItem = new Item(new Properties().group(tab)) .setRegistryName(ChickenMOD.MODID,name); itemList.add(thisItem); public static List<Item> MakeItems() { ChickenMod.LOGGER.info("HELLO from MakeItems"); NewItem ("test_item", ItemGroup.MISC); for (Block thisBlock:ChickenMod.BLOCKS) { Item thisItem = new ItemBlock(thisBlock, new Properties().group(ChickenMod.ITEMTAB)).setRegistryName(thisBlock.getRegistryName()); ChickenMod.LOGGER.info("HELLO from MakeItems-> block tab registry" ); itemList.add(thisItem); } return itemList; } The static Method is triggered by a field assignment in the main class: public static List<Item> ITEMS = ModItems.MakeItems(); The list is later iterated for Event Registration: //Register Items @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { ChickenMOD.LOGGER.info("HELLO from Registry :: ITEMS"); for (Item thisItem : ChickenMod.ITEMS) { event.getRegistry().register(thisItem); } } I'm using a similar method for custom blocks: trigger a static method (via field assignment) to a list (of type <Block>) which is later iterated to register to the appropriate Event Bus (with similar results) The Items and blocks are being registered (I can access them in game), but they get the generic texture assignment which indicates the resources were no properly loaded. An excerpt from the log file: [26May2019 20:38:49.568] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Exception loading blockstate definition: chicken_mod:blockstates/test_block.json: java.io.FileNotFoundException: chicken_mod:blockstates/test_block.json [26May2019 20:38:50.410] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Unable to load model: 'chicken_mod:test_item#inventory' referenced from: chicken_mod:test_item#inventory: java.io.FileNotFoundException: chicken_mod:models/item/test_item.json [26May2019 20:38:50.410] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Unable to load model: 'chicken_mod:test_block#inventory' referenced from: chicken_mod:test_block#inventory: java.io.FileNotFoundException: chicken_mod:models/item/test_block.json The project as a whole can be found here: https://github.com/pchonacky/randombits.git I am aware there are probably more graceful ways to do this, but I am still working out what will work best - just trying to get it to work for now. Thanks in advance for your replies. /Philip Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 31, 2019 Share Posted May 31, 2019 Your system will not work. Registry entries MUST be instantinated in the appropriate registry event, now more than ever. Don't ever use static inializers for registry entries. Rework this right now, before it gets too big. You will also make your code much more readable and will write way less code. The code in your repository doesn't match the code you've posted. So yeah, fix the static initializer issue first, then I can debug your repository. Quote Link to comment Share on other sites More sharing options...
DavidM Posted May 31, 2019 Share Posted May 31, 2019 7 minutes ago, PhilipChonacky said: ChickenMod.LOGGER.info("HELLO from MakeItems-> block tab registry" ); Please remove useless loggings like this when you release the mod. As far as I could tell, the console warnings does not match your current repo. Please update your repo if they are not up to date. Quote 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. Link to comment Share on other sites More sharing options...
PhilipChonacky Posted May 31, 2019 Author Share Posted May 31, 2019 (edited) 1 hour ago, V0idWa1k3r said: Your system will not work. Registry entries MUST be instantinated in the appropriate registry event, now more than ever. Don't ever use static inializers for registry entries. Rework this right now, before it gets too big. You will also make your code much more readable and will write way less code. The code in your repository doesn't match the code you've posted. So yeah, fix the static initializer issue first, then I can debug your repository. It looks like my issue was I hadn't refreshed the assets folder in my IDE (eclipse) after making changes to the JSON files - it works now. ...as to the other issue: Are you implying I should register in the same classes where I initialize (after making non-static)? or just use non-static fields for my entries? BTW- The repository was updated after I posted the clips, so the clips can be ignored - repository is more up to date /Philip Edited May 31, 2019 by PhilipChonacky clarification Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 31, 2019 Share Posted May 31, 2019 (edited) 19 minutes ago, PhilipChonacky said: ...as to the other issue: Are you implying I should register in the same classes where I initialize (after making non-static)? or just use non-static fields for my entries? Instantinate in the registry event. event.registerAll(new BlockA(), new BlockB(), new Block(Material.IRON).setRegistryName(...), new ...) 19 minutes ago, PhilipChonacky said: It looks like my issue was I hadn't refreshed the assets folder in my IDE (eclipse) after making changes to the JSON files - it works now. One of the many reasons I chose a different IDE... Edited May 31, 2019 by V0idWa1k3r Quote Link to comment Share on other sites More sharing options...
PhilipChonacky Posted May 31, 2019 Author Share Posted May 31, 2019 5 minutes ago, V0idWa1k3r said: Instantinate in the registry event. event.registerAll(new BlockA(), new BlockB(), new Block(Material.IRON).setRegistryName(...), new ...) One of the many reasons I chose a different IDE... That brings up the challenge of how I would pass the requisite ItemBlocks to the Item registry, or would you recommend I separately instantiate an identical Block there new Item (new ItemBlock (new Block() , new Properties())... Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 31, 2019 Share Posted May 31, 2019 6 minutes ago, PhilipChonacky said: new Item (new ItemBlock (new Block() , new Properties())... This would not work since new Block() != new Block(). You must pass the same object to the ItemBlock that you have registered, not an identical one. 6 minutes ago, PhilipChonacky said: That brings up the challenge of how I would pass the requisite ItemBlocks to the Item registry https://mcforge.readthedocs.io/en/1.13.x/concepts/registries/#injecting-registry-values-into-fields Quote Link to comment Share on other sites More sharing options...
PhilipChonacky Posted May 31, 2019 Author Share Posted May 31, 2019 6 minutes ago, V0idWa1k3r said: This would not work since new Block() != new Block(). You must pass the same object to the ItemBlock that you have registered, not an identical one. https://mcforge.readthedocs.io/en/1.13.x/concepts/registries/#injecting-registry-values-into-fields So create a Block Object holder field that matches the registry name of the Block, and then instantiate an ItemBlock of the object in the Item Registry method? Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 31, 2019 Share Posted May 31, 2019 Yes, that is correct. Quote Link to comment Share on other sites More sharing options...
PhilipChonacky Posted May 31, 2019 Author Share Posted May 31, 2019 (edited) Thanks, I think I just learned more about how this modding works in the post 1.9 world than many hours of reading the documentation [and reading several misleading tutorials] Edited May 31, 2019 by PhilipChonacky Quote Link to comment Share on other sites More sharing options...
PhilipChonacky Posted May 31, 2019 Author Share Posted May 31, 2019 In conclusion, I could have paired all that previous mess down to this: @Mod.EventBusSubscriber(modid=ChickenMod.MODID, bus=Mod.EventBusSubscriber.Bus.MOD) @ObjectHolder(ChickenMod.MODID) public static class RegistryEvents { public static final Block test_block=null; public static final Item test_item=null; @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { blockRegistryEvent.getRegistry().registerAll( new Block(Block.Properties.create(Material.IRON)).setRegistryName(ChickenMod.MODID,"test_block")); } @SubscribeEvent public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) { itemRegistryEvent.getRegistry().registerAll( (Item)new ItemBlock(test_block,new Item.Properties().group(ITEMTAB)).setRegistryName(test_block.getRegistryName()), new Item(new Item.Properties().group(ITEMTAB)).setRegistryName(ChickenMod.MODID,"test_item") ); } } I may make some changes to scale up [and possibly find a better IDE] /P [aka mush4brains] Quote Link to comment Share on other sites More sharing options...
Cadiboo Posted June 6, 2019 Share Posted June 6, 2019 You can see an example of registering ItemBlocks automatically here, but this comes with the overhead of iterating the entire blocks registry. 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) Link to comment Share on other sites More sharing options...
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.