Posted May 9, 20178 yr 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 May 9, 20178 yr by fcelon
May 9, 20178 yr 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.