Posted January 28, 20169 yr 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.
January 28, 20169 yr 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] http://i.imgur.com/CoLGhBP.png][/img] [spoiler=two or more stacks] http://i.imgur.com/99YNuO9.png][/img] Any ideas to get a single integer? Many thanks agains.
January 28, 20169 yr 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.