Jump to content

[solved]How to put a randomly generated number into a lore?


gmod622

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.