Jump to content

[1.7.10] Save Different Numbers For The Same Item


Recommended Posts

I'm creating a balance for an item, and everytime you add money to that balance, the balance variable goes up. But the problem is that the balance is the same for all the items. So if I added $100 to an item, it would add to everybody elses items aswell. I hope I explained it right

Link to comment
Share on other sites

Every ItemStack has an NBTTagCompound associated with it (ItemStack#stackTagCompound). You can store any data you want there.


Ok, so I already have it set-up with NBT, but it is the same on all the items, what am I doing wrong

package com.bugzoo.FinancialMod;

import java.util.List;

import net.minecraft.entity.Entity;
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.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;

public class ItemDebitCard extends Item {
	public ItemDebitCard(){

	int UniquePin = 1000 + (int)(Math.random()*9999); 
	public static double balance;

	    public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
	    	 itemStack.stackTagCompound = new NBTTagCompound();
	    	 itemStack.stackTagCompound.setString("owner", player.getDisplayName());
	    	 itemStack.stackTagCompound.setInteger("pin", UniquePin);
	    	 itemStack.stackTagCompound.setDouble("balance", balance);
	    	 player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + "Your Unique Pin is " + UniquePin));

	    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
	    	 if (itemStack.stackTagCompound != null) {
                     String owner = itemStack.stackTagCompound.getString("owner");
                     String pin = itemStack.stackTagCompound.getString("pin");
                     list.add("Owner: " + owner);
                     list.add("Balance: " + balance);
                     if (!owner.equals(player.getDisplayName())) {
                    	  list.add("Pin: " + EnumChatFormatting.OBFUSCATED + pin);
    		    	 } else {
    		    		 list.add("Pin: " + pin);

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.

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.

  • Create New...

Important Information

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