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

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.

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.

  • 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.

  • 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.

  • 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.

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.