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

Hello,

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.

Code:

public class SpearsInStorage implements IStorage<ISpearsIn>{
    
    @Override
    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);
                n=n+1;
            }
        compound.setBoolean("HasSpears", true);
        return compound;
    }
    
    @Override
    public void readNBT(Capability<ISpearsIn> capability, ISpearsIn instance, EnumFacing side, NBTBase nbt)
    {
        for (int n=1;n<64; n++)
        {
            try
            {
                NBTTagCompound compound = ((NBTTagCompound)nbt).getCompoundTag("Spear"+n);
                ItemStack spear = new ItemStack(compound);
                instance.addSpear(spear);
            }
            catch (Exception e)
            {
                n=64;
            }
        }
    }

}

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

  • Author

This is my first mod and I'm not very experienced with Java, sorry for that. Thanks anyway.

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.