Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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");

   

    }

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.

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.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

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).

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Well its all good then. They way you said it made it sound as if it was a static method.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

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
*/
}

  • Author

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

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).

That's why I always have my register call at the very end of the constructor, everything about the item has been finished up.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Thanks for the clarification.

BUT: That textures not working thing isn't reproducible for me. Oh well, still good to know.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.