Posted March 21, 201510 yr 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"); } }
March 21, 201510 yr 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
March 22, 201510 yr Author Thank you both! I changed it to extend BlockBush, it seems to work perfectly now!
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.