Jump to content

Recommended Posts

Posted

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;
	}





}

 

Not new to java >> New to modding.

Posted

@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.

Posted

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

Not new to java >> New to modding.

Posted

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
}

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 xD

Posted

this line:         NBTTagCompound stackCompound = ItemStack.getItemStackNBTTagCompound(); // whatever it is to get it

 

getItemStackNBTTagCompound isnt a method( I really newbie with ItemStacks and NBTs, sorry)

 

Not new to java >> New to modding.

Posted

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...

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 xD

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.