Jump to content

[SOLVED] Help with NBT crash.


TesterTesting135

Recommended Posts

Hello, so I am trying to make an item lock that prevents you from dropping items so you don't accidentally lose them. I save NBT data to it, but I have a problem. If I try to save data to a block I've already made, which saves the NBT when you break it and shows it in the tooltip, it gives a null pointer exception.

Add information and getItemCount methods in my block class:

@Override
public void addInformation(ItemStack itemstack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    tooltip.add("Makes cobblestone and compressed cobblestone with upgrades at a stack per tick. Uses LOADS of power when upgraded.");
    tooltip.add("Will auto-eject items.");
    NBTTagCompound tagCompound = itemstack.getTagCompound();
    if (tagCompound != null) {
        int energy = tagCompound.getInteger("energy");
       //Crashing Line int sizeIn = getItemCount(tagCompound, "itemsIn");
        int sizeOut = getItemCount(tagCompound, "itemsOut");
        String translated = I18n.format("message.tm.cobble_generator", energy, sizeIn, sizeOut);
        translated = COMPILE.matcher(translated).replaceAll("\u00a7");
        Collections.addAll(tooltip, StringUtils.split(translated, "\n"));
    }
}
private int getItemCount(NBTTagCompound tagCompound, String itemsIn2) {
    int sizeIn = 0;
    NBTTagCompound compoundIn = (NBTTagCompound) tagCompound.getTag(itemsIn2);
   //Crashing line NBTTagList itemsIn = compoundIn.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < itemsIn.tagCount(); i++) {
        NBTTagCompound itemTags = itemsIn.getCompoundTagAt(i);
        if (!new ItemStack(itemTags).isEmpty()) {
            sizeIn++;
        }
    }
    return sizeIn;
}

I think this is because of the "NBTTagCompound tagCompound = itemstack.getTagCompound();" line which gets all the NBT data, including the locking NBT boolean.

Is there anything I can do to fix this?

 

Note: This is a duplicate because I posted this in the wrong place. Sorry.

Edited by TesterTesting135
Solved
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.