Jump to content

[1.7.10] [SOLVED] register Icons causes exception in updating screen event?


Athire

Recommended Posts

Hello all! I'm almost done  updating my code from 1.6 to 1.7, but I'm coming across a srtange issue. I was trying to get a flower texture to load, but for some reason the standard SetBlockTextureName() wasn't working. I tried using Icons instead, and that caused the texture to load correctly. However when I go into the creative inventory and switch to a new tab, the game crashes due to a null pointer in BlockFlower.getSubBlocks(). When I comment out the registerIcons() function, the error goes away.

 

Also, I realize that the way I've named my textures does not follow the current convention, I will be updating that as soon as my code works correctly in 1.7.

 

Any help you guys could give me would be very much appreciated! Thank you in advance!

 

P.S. the spoilers button seems to be broken, it's not a long file so I'll just paste it here. Sorry for any inconvenience.

 

public class nightsbaneBlock extends BlockFlower

{

@SideOnly(Side.CLIENT)

private IIcon NightsbaneTexture;

 

public nightsbaneBlock()

{

super(1);

//this.setBlockTextureName("innerpower:InnerPower_NightsbaneBlock");

this.setBlockName("InrPwrNightsbane");

}

 

 

public Block idDropped(int metadata, Random random, int fortune)

{

return this;

}

/**

    * Gets the block's texture. Args: side, meta

    */

 

  @SideOnly(Side.CLIENT)

    @Override

    public IIcon getIcon(int p_149691_1_, int p_149691_2_)

    {

    return this.NightsbaneTexture;

    }

 

    @SideOnly(Side.CLIENT)

    @Override

    public void registerBlockIcons(IIconRegister reg)

    {

    this.NightsbaneTexture=reg.registerIcon("innerpower:InnerPower_Nightsbane");

    }

 

}

Link to comment
Share on other sites

Hi

 

FYI Here are the steps I used to troubleshoot the problem...

 

From BlockFlower::

    private IIcon[] field_149861_N;

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_)
    {
        for (int i = 0; i < this.field_149861_N.length; ++i)
        {
            p_149666_3_.add(new ItemStack(p_149666_1_, 1, i));
        }
    }

 

An NPE in getSubBlocks can only be caused if field_149861_N is null.  Your console error message would have shown that line number, alternatively you can use your debugger to set a breakpoint there and see it directly

http://www.terryanderson.ca/debugging/run.html

and

http://www.vogella.com/tutorials/EclipseDebugging/article.html

 

why is field_149861_n null?  probably because you haven't initialised it.

BlockFlower does it here

    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_149861_N = new IIcon[field_149860_M[this.field_149862_O].length];

        for (int i = 0; i < this.field_149861_N.length; ++i)
        {
            this.field_149861_N[i] = p_149651_1_.registerIcon(field_149860_M[this.field_149862_O][i]);
        }
    }

so either you need to call registerBlockIcons, or set field_149861_N yourself, or override getSubBlocks to return your subblock instead of the vanilla flower subblocks, or override BlockBush instead of BlockFlower.  Depends on what you plan to do with your block.

 

-TGG

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.