Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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

  • Author

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.

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.

  • Author

Well, can you be just a little bit more discriptive

Not new to java >> New to modding.

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

  • Author

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.