Ah, that's an easy mistake to make. Done it myself many occasions, but usually there is an error Hope you get it all working!
Mostly. It now crashes because of line 46(list.add(EnumChatFormatting.GREEN + "Souls:" + souls) I guess because of the souls but that I can figure out on my own. Thank you so much for your help. You for sure deserve a spot in the credits
I may still have troubles but I have definably come a lot farther.
Actually, sorry, I was wrong about that. The ItemStack in addInformation will only be an instance of your Item. <facepalm>
Anyway, try removing '+ souls' and see if it prints. Are you certain it's this line? What's the error message?
Sorry for the late reply, I had to sleep. It is that line, I don't know why but I guess its something to do with the souls int. I don't remember the error but It just linked back to that line. I'm guessing it was something pretty simple but I will rewrite it and see if I can find out how.
Hmm, a new smaller problem is roadblocking me now. How do I get a int(i) from 1 method to another. I think the problem was that. But wait, Ahhhhhhh so confusing. This code looks like it should work The onCreated is called once on creation, correct? That sets the integer "souls" for the whole item, correct? Then addInformation should be able to read from itself to get an integer from existing tags.
Sorry for sort of spamming here but this is my code now
package SoulsMod;
import java.util.List;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SoulBottleBasic extends Item
{
private static String textureName;
public SoulBottleBasic(int id, String textureName)
{
super(id);
setCreativeTab(SoulsMod.soulsModTab);
this.textureName = textureName;
setMaxStackSize(1);
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister register)
{
this.itemIcon = register.registerIcon("soulsmod:" + textureName);
}
@SideOnly(Side.CLIENT)
public void onCreated(ItemStack itemStack, List list)
{
int i = 0;
itemStack.stackTagCompound = new NBTTagCompound();
itemStack.stackTagCompound.setInteger("souls", i);
}
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean j)
{
itemStack.stackTagCompound.getInteger("souls");
list.add(EnumChatFormatting.GREEN + "Souls:");
}
}
And here is an important chunk in the crash console
2013-09-06 11:00:42 [INFO] [STDOUT] A detailed walkthrough of the error, its code path and all known details is as follows:
2013-09-06 11:00:42 [INFO] [STDOUT] ---------------------------------------------------------------------------------------
2013-09-06 11:00:42 [INFO] [STDOUT]
2013-09-06 11:00:42 [INFO] [STDOUT] -- Head --
2013-09-06 11:00:42 [INFO] [STDOUT] Stacktrace:
2013-09-06 11:00:42 [INFO] [STDOUT] at SoulsMod.SoulBottleBasic.addInformation(SoulBottleBasic.java:46)<-----------------------:
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.item.ItemStack.getTooltip(ItemStack.java:662)<--------------------------------:
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.inventory.GuiContainerCreative.updateCreativeSearch(GuiContainerCreative.java:389)
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.inventory.GuiContainerCreative.setCurrentCreativeTab(GuiContainerCreative.java:575)
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.inventory.GuiContainerCreative.mouseMovedOrUp(GuiContainerCreative.java:476)
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:218)
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.inventory.GuiContainerCreative.handleMouseInput(GuiContainerCreative.java:594)
2013-09-06 11:00:42 [INFO] [STDOUT] at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)
2013-09-06 11:00:42 [INFO] [STDOUT]
I made a mistake previously telling you I got an error doing list.add(blahblahblahstuff + souls), the error was on the line "int souls = itemStack.stackTagCompound.getInteger("souls");" It crashes trying to get an integer. That I'm not sure of a fix to myself.
Ok 1 more post before I stop chain posting. I tried adding SoulDrops(xpOrb drop thing) that didn't work so I just deleted those few lines in the EventHandler class. But after deleting them returning it back to its original state it crashes on "MinecraftForge.EVENT_BUS.register(new EventHandler());" Any Idea as to why this is? Sort of strange if you ask me seeing as technically I didn't change anything.
Try putting a println in onCreated to see if it's getting called. One thing to note is that it is client side only, and generally you don't want to do important things on just the client (such as creating a new tag compound). I'd create the new tag compound in the constructor, as well as set it's initial value there.
Later on, when you add souls, be sure to add them both on the server side and the client side as well, since the client needs to have the information for addInformation.
Basically what's happening, I'm guessing, is that there is itemstack.stackTagCompound is null, possibly because onCreated may not be working as you think.
As for the EventHandler, are you sure you didn't change anything else? Post your EventHandler code.
Try putting a println in onCreated to see if it's getting called. One thing to note is that it is client side only, and generally you don't want to do important things on just the client (such as creating a new tag compound). I'd create the new tag compound in the constructor, as well as set it's initial value there.
Later on, when you add souls, be sure to add them both on the server side and the client side as well, since the client needs to have the information for addInformation.
Basically what's happening, I'm guessing, is that there is itemstack.stackTagCompound is null, possibly because onCreated may not be working as you think.
As for the EventHandler, are you sure you didn't change anything else? Post your EventHandler code.
Slightly confused on what you mean on create the tag compound in the constructor. I did fix the EventHandler though. I put
"public void onMobKilled(LivingDeathEvent event, World world, int par1, int par2, par3, par4)"
I thought you needed to add theses things to spawn in XPorbs on the entitys death.
Once again, sorry for the late reply. I tried printing something in the onCreated line and nothing. It's not doing anything. Do you know the reason for that though?
Try putting '@Override' above all the methods you can. That tells the compiler to use your version of the method rather than the version in the parent class (in this case, the Item class, where it does nothing).
Keep in mind also that 'onCreated', according to its documentation, is only called when an item is crafted or smelted, so if you're just grabbing your item out of the Creative Tabs, then I don't think it's called. I may be wrong about that, though, as I'm just going by what the method claims it does, not personal experience.
That's because your method has the incorrect signature, meaning it will never be called by vanilla code. Look in the Item class for the 'onCreated' method, copy its signature and put that in your custom Item with the @Override and it will work.
A method signature consists of the method name, which you have, and the parameters passed to it, which do not match for you here. Two methods can only have the same signature if they are either in completely different classes or if you are Overriding the parent method with the same signature.
@SideOnly is only declaring that the NEXT method is for the designated side, be it server or client. You should put the @Override between that and the method. Also another way to check if the method is created correctly is to highlight the word, like onCreated and then hover the mouse over it and it will tell you what class it originates in. Also the search function in eclipse works good too. There is another way to do those things though, like if you want to have more than one item or block trigger something like an achievement when created, use a crafting handler, this will store all those items and blocks in one class, not the actual item or block code, and will trigger your achievement then. This is a sure way of making sure it works.
That's because your method has the incorrect signature, meaning it will never be called by vanilla code. Look in the Item class for the 'onCreated' method, copy its signature and put that in your custom Item with the @Override and it will work.
A method signature consists of the method name, which you have, and the parameters passed to it, which do not match for you here. Two methods can only have the same signature if they are either in completely different classes or if you are Overriding the parent method with the same signature.
Yes the way the method is written....using the same exact code written for the method you want....
example
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par2, float par3, float par4, float par5)
{
The method above has 9 parameters...if I wanted to override this method I would have to make sure I had the same 9 parameters. So have a look in the item class and see how the method for onCreated is written and use it the same way, or as I was suggesting earlier to use a crafting handler, will do the same thing.
Ah, that's an easy mistake to make. Done it myself many occasions, but usually there is an error Hope you get it all working!
Mostly. It now crashes because of line 46(list.add(EnumChatFormatting.GREEN + "Souls:" + souls) I guess because of the souls but that I can figure out on my own. Thank you so much for your help. You for sure deserve a spot in the credits
I may still have troubles but I have definably come a lot farther.
addInformation's ItemStack parameter is NOT necessarily an instance of your itemSorry - that's wrong. Doh.
Why you so helpful But I still don't know how to fix it from that
Anyway, try removing '+ souls' and see if it prints. Are you certain it's this line? What's the error message?
Sorry for the late reply, I had to sleep. It is that line, I don't know why but I guess its something to do with the souls int. I don't remember the error but It just linked back to that line. I'm guessing it was something pretty simple but I will rewrite it and see if I can find out how.
And here is an important chunk in the crash console
I made a mistake previously telling you I got an error doing list.add(blahblahblahstuff + souls), the error was on the line "int souls = itemStack.stackTagCompound.getInteger("souls");" It crashes trying to get an integer. That I'm not sure of a fix to myself.
Later on, when you add souls, be sure to add them both on the server side and the client side as well, since the client needs to have the information for addInformation.
Basically what's happening, I'm guessing, is that there is itemstack.stackTagCompound is null, possibly because onCreated may not be working as you think.
As for the EventHandler, are you sure you didn't change anything else? Post your EventHandler code.
Slightly confused on what you mean on create the tag compound in the constructor. I did fix the EventHandler though. I put
"public void onMobKilled(LivingDeathEvent event, World world, int par1, int par2, par3, par4)"
I thought you needed to add theses things to spawn in XPorbs on the entitys death.
Did you check to see if onCreated is being called? Put a println in there and see.
Sorry for the wait I was at a game convention for a couple days. I will try what you said and post again though.
Keep in mind also that 'onCreated', according to its documentation, is only called when an item is crafted or smelted, so if you're just grabbing your item out of the Creative Tabs, then I don't think it's called. I may be wrong about that, though, as I'm just going by what the method claims it does, not personal experience.
A method signature consists of the method name, which you have, and the parameters passed to it, which do not match for you here. Two methods can only have the same signature if they are either in completely different classes or if you are Overriding the parent method with the same signature.
Best explanation of that I have seen yet....
Find out how I generate....coolAlias...world structure generation and rotation tool...
example
The method above has 9 parameters...if I wanted to override this method I would have to make sure I had the same 9 parameters. So have a look in the item class and see how the method for onCreated is written and use it the same way, or as I was suggesting earlier to use a crafting handler, will do the same thing.
Find out how I generate....coolAlias...world structure generation and rotation tool...