somarani Posted July 4, 2014 Share Posted July 4, 2014 Hi, I'm updating my mod from forge 1.6.4 to forge 1.7.2 and I'm following some tutorials online. In almost all the tutorial I've seen, the blocks are registered under the init method. But whenever I did that, the block texture wouldn't show. The only way I could get the block texture to load was to register my block the my main mod class constructor. Which is the better way to do it? Here is what I have: public SoulCraft(){ //This is my constructor GameRegistry.registerBlock(infusedStone, "infusedstone"); } Quote Link to comment Share on other sites More sharing options...
Achilleus Posted July 4, 2014 Share Posted July 4, 2014 I always register mine in my main class and put the textures in the constructor in the blocks class. Quote Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 4, 2014 Share Posted July 4, 2014 My blocks are registered in the static method of my main class(technically inside the static method of a different class that is initialized by the static method of my main class), but the init method should be equally valid. Can't imagine why it would effect your textures but, if for curiosity's sake, you tried registering them in preInit I would like to know if you get the same problem. Quote Link to comment Share on other sites More sharing options...
Kwibble Posted July 4, 2014 Share Posted July 4, 2014 Here is an example modfile: package com.kwibble.mod; // imports. I can't remember what they are @Mod(modid = "dummymod", name = "Dummy Mod", version = "1.0.0") public class ModDummy { @Mod.Instance("dummymod") public static ModDummy instance; public static Block dummy_block; @EventHandler public void preInit(FMLPreInitializationEvent event) { dummy_block = ( new BlockDummy()).setCreativeTab(CreativeTabs.tabBlock); } } Here is BlockDummy: package com.kwibble.mod.block; // imports public class BlockDummy extends Block { public BlockDummy() { this.setBlockName("dummy_block"); this.setTextureName("dummy_block"); // Other stuff you/need to make this block. Or you could chain them when you instantiate the dummy_block variable GameRegistry.registerBlock(this, "block_dummy_block"); } // Other block stuff if you want it } This is basically the setup that I use (aside from the bad coding practise shown in that example... Bad Kwibble) and it works perfectly fine for me. Quote We all stuff up sometimes... But I seem to be at the bottom of that pot. Link to comment Share on other sites More sharing options...
Kwibble Posted July 4, 2014 Share Posted July 4, 2014 My blocks are registered in the static method of my main class(technically inside the static method of a different class that is initialized by the static method of my main class), but the init method should be equally valid. Can't imagine why it would effect your textures but, if for curiosity's sake, you tried registering them in preInit I would like to know if you get the same problem. Okay, first thins first. NONE OF YOUR INITLIAZATION EVENTS (PRE, POST, OR OTHERWISE) SHOULD BE STATIC. Now that that is taken care of... Always register your blocks/items in the PRE initialization event, unless they are reliant on another mods items/blocks. @OP I also forgot to mention, you don't need a constructor in your mod class. At all. Forge "constructs" your class via the initialization methods, so a constructor is not needed (at least to my knowledge). Quote We all stuff up sometimes... But I seem to be at the bottom of that pot. Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 4, 2014 Share Posted July 4, 2014 None of my initialization methods are static.... I just register my blocks from a static block.... Quote Link to comment Share on other sites More sharing options...
Kwibble Posted July 4, 2014 Share Posted July 4, 2014 Well its all good then. They way you said it made it sound as if it was a static method. Quote We all stuff up sometimes... But I seem to be at the bottom of that pot. Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 4, 2014 Share Posted July 4, 2014 Well, it is a static method. But it's not one of my init methods. It's just a static block. Like this: static{ /* * stuff */ } Quote Link to comment Share on other sites More sharing options...
somarani Posted July 4, 2014 Author Share Posted July 4, 2014 If I register the block in the preInit method, the texture doesn't show up, also, If I create the object in the preInit method the texutre doesn't show up either. To get the texture to work, I either have to do this line - "GameRegistry.registerBlock(this, "infusedstone");" in the constructor for the block, or the constructor of the Main mod class. This is what I have now and it works, is this the bad way of doing it, and is there a better way? Main Mod Class - http://pastebin.com/kbPPv4Ee Block class - http://pastebin.com/69haC0bu Quote Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 4, 2014 Share Posted July 4, 2014 I've been told that registering your block during construction is technically incorrect. You can get around this by having a method public Block register(){ GameRegistry.register(this, this.getUnlocalizedName()); return this; } and when you create your block: public static final Block myBlock = new MyBlock().register(); because you can guarantee that the Block is created before you call GameRegistry.register(args). Quote Link to comment Share on other sites More sharing options...
Kwibble Posted July 4, 2014 Share Posted July 4, 2014 That's why I always have my register call at the very end of the constructor, everything about the item has been finished up. Quote We all stuff up sometimes... But I seem to be at the bottom of that pot. Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 4, 2014 Share Posted July 4, 2014 The purists still don't like that. But that's why I call them purists. Quote Link to comment Share on other sites More sharing options...
MoxEmerald Posted July 5, 2014 Share Posted July 5, 2014 Thanks for the clarification. BUT: That textures not working thing isn't reproducible for me. Oh well, still good to know. Quote 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.