Posted January 4, 201610 yr So, I am using the ItemPickupEvent to check for items, and add a weight amount to the player that is parsed from my json. This all works fine except for this: ItemStack item = event.pickedUp.getEntityItem(); int multiplier = item.stackSize; It seems as though "multiplier" always returns 0. I could of sworn in 1.7.10, I never had this issue. Is there a new way of getting the stackSize with this event? I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.
January 4, 201610 yr ItemPickupEvent is fired after the ItemStack is added to the player's inventory with InventoryPlayer#addItemStackToInventory , which sets the ItemStack 's stack size to 0. You'll probably want to subscribe to EntityItemPickupEvent instead, since it's fired before the ItemStack is modified. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 4, 201610 yr Author So those two events are slightly like RenderGameOverlayEvent.pre/post, correct? I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.
January 4, 201610 yr Author Hm, alright. I'm using that now and it works quite well. Now, my other question is: is InventoryPlayer#inventoryChanged become true when anything enters or leaves the inventory? Or is it only in some cases? I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.
January 4, 201610 yr Author Yes, it is always true as long as you have something in your inventory. Now, this was a problem, considering when the final item was removed, it wouldn't update. All I had to do was move how I set my weight into the checker for the inventoryChanged boolean, and only run the code if my newWeight (weight to be set), is not equal to my current weight. Here is how I do it in case someone is curious: //Put in a LivingUpdateEvent. Simply set the player and my props for ease of access. /* Start update inventory */ InventoryPlayer inv = player.inventory; if(inv.inventoryChanged) { float currentWeight = props.getCurrentWeight(); float newWeight = 0; for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack item = inv.getStackInSlot(i); int multiplier = 1; if(item != null) { multiplier = item.stackSize; try { float weight = WeightLimitJson.getItemWeight(item.getItem()) * multiplier; newWeight += weight; }catch (IOException e) { e.printStackTrace(); } } } if(!player.worldObj.isRemote && newWeight != currentWeight) props.setWeight(newWeight); } I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.
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.