Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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.