Posted October 4, 20196 yr Here is the code ( I've deleted most of the stuff just to make it more clear) public int maxAmmo; public int ammo; public GunBase(String name, CreativeTabs creativetab, int maxAmmo) { super(name, creativetab); setMaxStackSize(1); this.maxAmmo = maxAmmo; this.ammo = maxAmmo; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { EntityPlayer player = (EntityPlayer) entityIn; ItemStack itemstack = player.getHeldItemMainhand(); if(itemstack.areItemsEqual(itemstack, stack)) { NBTTagCompound compound; if (itemstack.hasTagCompound()) { compound = itemstack.getTagCompound(); } else { compound = new NBTTagCompound(); } compound.setInteger("MaxAmmo", this.maxAmmo); compound.setInteger("Ammo", this.ammo); stack.setTagCompound(compound); } } I've set maxammo and ammo in the constructor, aren't they going to have their own instance? There aren't any static method as well, but the result is same kind of item shares the nbt tag. How do I fix it?
October 5, 20196 yr Author 21 hours ago, diesieben07 said: There is only one instance of your item class. This is why ItemStack is a thing, which represents an actual item in an inventory. The Item class represents the type of item as a whole. You need to store your data only in the ItemStack. If you are going to use the raw stack NBT you should also prefix your entries with your mod ID to avoid conflicts. Edited October 5, 20196 yr by poopoodice
October 5, 20196 yr Author 27 minutes ago, diesieben07 said: This is in your item class. I am going to create another class for the ammo thing, am I correct? Should I use events such as playertick or something like that? Edited October 5, 20196 yr by poopoodice
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.