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

Hi!

 

I'm interested i know how to calculate the total count of specified items in player's inventory and then print it in integer number.

 

Many thanks.

  • Author

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.

				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

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.