Jump to content

Inventory unique ID for same item?


Morteboule

Recommended Posts

Hello,

 

In fact i have 2 weapons magazine in my inventory and each one has it s own number of ammo inside (ex: one has 3  and the other has 5) but it's the same item, number of ammo is a rand in the constructor.

 

When i press a key i would like my weapon consumes one of magazine item but first taking the variable number of ammo inside it but i don't know how to acceed this value (to know wich one the weapon magazine the game will consume).

The 2 weapons magazines are not stackable.

 

Is there a solution?

 

Thanks

Link to comment
Share on other sites

Thanks for your reply.

 

I've setted this.setMaxDamage(this.maxBullet); in constructor but when want to set the actual damage value (number of bullet who is randomly choosen) it ask for an itemstack but i don't have one in constructor.

How can i set damage in constructor ?(Will be only used for display)

 

public ItemMagazine(int id, int par2maxbullet) {
	super(id);
	this.maxStackSize = 1;
	this.maxBullet = par2maxbullet;
	this.bullet = itemRand.nextInt(this.maxBullet - 1) + 1;
	this.setMaxDamage(this.maxBullet);

	setCreativeTab(CreativeTabs.tabCombat);
}

 

And even if i can set damage, how can i get it in my ItemGun? (imagine i have 2 differents magazines)

 

Thanks!

 

 

Link to comment
Share on other sites

You don't set CURRENT damage in the constructor.  The Item class is a singleton, only one of them exists at a time.*

 

Each stack of your Item class is where the current damage comes in.  You'd need to look through the player's inventory for those.

 

*Exceptions exist.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I don't get it.

In this;

 

@SideOnly(Side.CLIENT)
public void reloadingWeapon(Entity player, ItemStack itemStack)
{
	if(player instanceof EntityPlayer)
	{
		//System.out.println("ReloadingWeapon");
		if(((EntityPlayer)player).inventory.hasItem(this.bulletID))	
		{

			((EntityPlayer)player).inventory.consumeInventoryItem(this.bulletID);

		}
	}

}

 

How can i look for the actual damage of the item (which is the actual number of bullet in the magazine) before consume it?

Link to comment
Share on other sites

You need to look at the item stack damages.  "Consume" just makes the stack size go down by 1.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.