Jump to content

[1.11.2]Problem with saving capability


Recommended Posts


I have added throwable weapon to my mod and I want to let any entity, that was hit by that weapon to drop it, when it dies. I have created a capability to store all weapons "inside" the entity, but there is some problem with saving the data to NBT anr the game instantly crashes. Is there anything wrong with this code.


public class SpearsInStorage implements IStorage<ISpearsIn>{
    public NBTTagCompound writeNBT(Capability<ISpearsIn> capability, ISpearsIn instance, EnumFacing side) 
        NBTTagCompound compound = new NBTTagCompound();
        ArrayList<ItemStack> list = instance.getSpearsIn();
        int n=1;
        for (ItemStack spear:list)
                NBTTagCompound nbt = spear.serializeNBT();
                compound.setTag("Spear"+n, nbt);
        compound.setBoolean("HasSpears", true);
        return compound;
    public void readNBT(Capability<ISpearsIn> capability, ISpearsIn instance, EnumFacing side, NBTBase nbt)
        for (int n=1;n<64; n++)
                NBTTagCompound compound = ((NBTTagCompound)nbt).getCompoundTag("Spear"+n);
                ItemStack spear = new ItemStack(compound);
            catch (Exception e)


I used this tutorial when creating the capability: http://www.planetminecraft.com/blog/forge-tutorial-capability-system/. I have already added a different capability to my mod and it worked without problems.

Thanks for any help.

Edited by fcelon
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.

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.


  • Create New...

Important Information

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