Something important I forgot to mention - you should only be changing NBT on the server, and this method is client-side only. That means the server will crash when you try to access NBT because it still doesn't have a compound, whereas if you create it on the server it syncs automatically with the client.
In the addInformation method, try checking if itemstack.stackTagCompound is null and, if so, create a new one.
Do the same anywhere else you have access to an ItemStack version of your SoulBottle, such as onItemUse or in your EventHandler when you try to add souls. All of these places should check for null NBT compound and create a new one if necessary.
EDIT: Looked at Item code for onCreated method - it is NOT @SideOnly(Side.CLIENT), so why did you add that to yours???
Something important I forgot to mention - you should only be changing NBT on the server, and this method is client-side only. That means the server will crash when you try to access NBT because it still doesn't have a compound, whereas if you create it on the server it syncs automatically with the client.
In the addInformation method, try checking if itemstack.stackTagCompound is null and, if so, create a new one.
Do the same anywhere else you have access to an ItemStack version of your SoulBottle, such as onItemUse or in your EventHandler when you try to add souls. All of these places should check for null NBT compound and create a new one if necessary.
EDIT: Looked at Item code for onCreated method - it is NOT @SideOnly(Side.CLIENT), so why did you add that to yours???
It was in a tutorial I read. So I should just put @Override and thats it? And create a new NBT compound in addInformation?
I don't see why you would add it when the base code method doesn't use it, unless you have a very specific purpose in mind.
Yes, try my above suggestions.
I don't know what to do anymore I have tried so many combinations of things such as Side.SERVER or no creating an NBTTagCompound but nothing has worked so far. Either it doesn't add any information at all or it crashes and gives me an error on setItemTag and ItemInformation. So I know it has something to do with setting integers, therefor probably the NBTTagCompound.
Since you've tried lots of times, here is the code for addInformation; as a bonus, it will print in italics
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4)
{
if (itemstack.stackTagCompound == null)
{
itemstack.stackTagCompound = new NBTTagCompound();
itemstack.stackTagCompound.setInteger("Souls", 0);
}
list.add(EnumChatFormatting.ITALIC + "Contains " + itemstack.stackTagCompound.getInteger("Souls"));
}
Use the same code for setting the stack tag compound in your other methods. Here is onCreated:
@Override
public void onCreated(ItemStack itemstack, World world, EntityPlayer player)
{
if (itemstack.stackTagCompound == null)
{
itemstack.stackTagCompound = new NBTTagCompound();
itemstack.stackTagCompound.setInteger("Souls", 0);
}
}
Note that it is almost exactly the same as the first method. You need to check in all methods that could access your itemstack, just in case one of the other methods isn't called first. For example, onCreated may not be called if you don't actually craft your item, at which point addInformation would crash if you didn't check there as well.
Also note that none of these methods are using the '@SideOnly' annotation because the vanilla method doesn't use it, either.
In the future, NEVER put '@SideOnly' annotation in front of your methods, not for CLIENT or for SERVER, UNLESS the vanilla method you are overriding also has it. Only when you really understand why these are used in certain situations should you even think about using them on your own methods. Generally, it's better for your method to just run on both sides the same way.
Since you've tried lots of times, here is the code for addInformation; as a bonus, it will print in italics
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4)
{
if (itemstack.stackTagCompound == null)
{
itemstack.stackTagCompound = new NBTTagCompound();
itemstack.stackTagCompound.setInteger("Souls", 0);
}
list.add(EnumChatFormatting.ITALIC + "Contains " + itemstack.stackTagCompound.getInteger("Souls"));
}
Use the same code for setting the stack tag compound in your other methods. Here is onCreated:
@Override
public void onCreated(ItemStack itemstack, World world, EntityPlayer player)
{
if (itemstack.stackTagCompound == null)
{
itemstack.stackTagCompound = new NBTTagCompound();
itemstack.stackTagCompound.setInteger("Souls", 0);
}
}
Note that it is almost exactly the same as the first method. You need to check in all methods that could access your itemstack, just in case one of the other methods isn't called first. For example, onCreated may not be called if you don't actually craft your item, at which point addInformation would crash if you didn't check there as well.
Also note that none of these methods are using the '@SideOnly' annotation because the vanilla method doesn't use it, either.
In the future, NEVER put '@SideOnly' annotation in front of your methods, not for CLIENT or for SERVER, UNLESS the vanilla method you are overriding also has it. Only when you really understand why these are used in certain situations should you even think about using them on your own methods. Generally, it's better for your method to just run on both sides the same way.
Ahh thanks so much! I guess it's a good thing that why it didn't previously work makes a lot of sense to me now. My I ask though because I forgot when I was learning Java, what does != do differently from == ?
Forgot about a previous part of the whole thing, adding the souls in via events. I am slightly familiar with events in another mod I'm making, however I have no clue what I would do to A: drop a soul entity and B: Make the bottle check if the soul was picked up and add a soul.
What do you mean it doesn't exist? It is in the Item class - isn't that the class that your soul bottle extends?
I think it's something else wrong because when I Override it crashes. So I don't know whats wrong.
Don't know if thats too relevant to the problem.
In the addInformation method, try checking if itemstack.stackTagCompound is null and, if so, create a new one.
Do the same anywhere else you have access to an ItemStack version of your SoulBottle, such as onItemUse or in your EventHandler when you try to add souls. All of these places should check for null NBT compound and create a new one if necessary.
EDIT: Looked at Item code for onCreated method - it is NOT @SideOnly(Side.CLIENT), so why did you add that to yours???
It was in a tutorial I read. So I should just put @Override and thats it? And create a new NBT compound in addInformation?
Yes, try my above suggestions.
I don't know what to do anymore I have tried so many combinations of things such as Side.SERVER or no creating an NBTTagCompound but nothing has worked so far. Either it doesn't add any information at all or it crashes and gives me an error on setItemTag and ItemInformation. So I know it has something to do with setting integers, therefor probably the NBTTagCompound.
Use the same code for setting the stack tag compound in your other methods. Here is onCreated:
Note that it is almost exactly the same as the first method. You need to check in all methods that could access your itemstack, just in case one of the other methods isn't called first. For example, onCreated may not be called if you don't actually craft your item, at which point addInformation would crash if you didn't check there as well.
Also note that none of these methods are using the '@SideOnly' annotation because the vanilla method doesn't use it, either.
In the future, NEVER put '@SideOnly' annotation in front of your methods, not for CLIENT or for SERVER, UNLESS the vanilla method you are overriding also has it. Only when you really understand why these are used in certain situations should you even think about using them on your own methods. Generally, it's better for your method to just run on both sides the same way.
Ahh thanks so much! I guess it's a good thing that why it didn't previously work makes a lot of sense to me now. My I ask though because I forgot when I was learning Java, what does != do differently from == ?