gmod622 Posted August 7, 2013 Posted August 7, 2013 hello! The title explains everything. what i want to have is a random generated number pre item(which i do), but now i want to display that item. Do i still use the ItemStack.StackTagCompoud or what? Please help! What i have so far: package com.gmod622.SickMod.item; import java.util.List; import com.gmod622.SickMod.tile.TileEntityLicense; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class LicenseItemClass extends Item { public LicenseItemClass(int par1) { super(par1); this.setCreativeTab(CreativeTabs.tabMaterials); } public static int theRandom; public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { //here you can use the information about the itemstack nbt //ex: if(par1ItemStack.stackTagCompound == null){ //here we know the nbt is null par1ItemStack.stackTagCompound = new NBTTagCompound(); }else { theRandom = par1ItemStack.stackTagCompound.getInteger("myRandomNumber"); if(theRandom == 0){ //here we DONT have anythin on the stack compound par1ItemStack.stackTagCompound.setInteger("myRandomNumber", (int)(Math.random()*100000));//generate a number between 0-100 and place it on the nbt }else{ System.out.println("the number of this item is: "+theRandom); } } return par1ItemStack; } } Quote Not new to java >> New to modding.
GotoLink Posted August 7, 2013 Posted August 7, 2013 @SideOnly(Side.CLIENT) /** * allows items to add custom lines of information to the mouseover description */ public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {} In Item class. Not sure if that is what you want. Quote
gmod622 Posted August 7, 2013 Author Posted August 7, 2013 I have a randomly generated number by using ItemStackNBT. if i would do that all of the ids will be the same on the cards Quote Not new to java >> New to modding.
GotoLink Posted August 7, 2013 Posted August 7, 2013 The first argument from that method is the ItemStack. Get the id from its NBT, then add this id to the list. It will be displayed different for each. Quote
gmod622 Posted August 8, 2013 Author Posted August 8, 2013 Well, can you be just a little bit more discriptive Quote Not new to java >> New to modding.
Mew Posted August 8, 2013 Posted August 8, 2013 Something like: // package here // imports here public class ItemRandomIDItem extends Item { // typical Item stuff here public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4 { NBTTagCompound stackCompound = ItemStack.getItemStackNBTTagCompount(); // whatever it is to get it int idToDisplay = stackCompound.getInteger("theRandomID"); par3List.add("ID: " + idToDisplay); } // other Item stuff } Quote I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
gmod622 Posted August 8, 2013 Author Posted August 8, 2013 this line: NBTTagCompound stackCompound = ItemStack.getItemStackNBTTagCompound(); // whatever it is to get it getItemStackNBTTagCompound isnt a method( I really newbie with ItemStacks and NBTs, sorry) Quote Not new to java >> New to modding.
Mew Posted August 8, 2013 Posted August 8, 2013 I know it isn't. I just wrote that with the comment saying, WHATEVER IT IS. meaning I have no idea what the method is, but I know it's there... Quote I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
Recommended Posts
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.