Jump to content

[Forge 1.8] Count total number of items


Lord_Rius

Recommended Posts

int i

foreach itemstack in inventory

  i+=itemstack.size

Many thanks for your answer, with your help i'm using this piece of code and works, but it shows me by one hand total count of items in inventory and by other hand independent count of every stack i have...

 

int count = 0;
		for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++)
		{
			ItemStack Stack = player.inventory.getStackInSlot(slot);

			if (Stack != null && Stack.getItem().equals(Items.arrow))
			{
				int total = count += Stack.stackSize;
				String arrowsCount = String.valueOf(total);

 

Some screenshots, i've different string color depending count number

 

[spoiler=only 1 stack]

width=95 height=61http://i.imgur.com/CoLGhBP.png][/img]

 

[spoiler=two or more stacks]

width=100 height=68http://i.imgur.com/99YNuO9.png][/img]

 

 

Any ideas to get a single integer?

 

Many thanks agains.

Link to comment
Share on other sites

				int total = count += Stack.stackSize;
                                        String arrowsCount = String.valueOf(total);

 

 

 

wait what. what are you doing there and why.

you want to have the total amount, so evaluate the string AFTER the loop and use the variable count. the variable total is redefined for each loop iteration so will always be only the count of the actual stack

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.