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 was using addItemStackToInventory on the player inventory. However I noticed it only returns true if there is an empty slot. But it doesn't return true in the case there is already some stack with that item and still room for it.
(Or it's returning true, but not actually adding the stack) Doing some testing still.
Is there other method that would do this?

Edited by American2050

  • Author
2 minutes ago, diesieben07 said:

ItemHandlerHelper.giveItemToPlayer.

This will only do it if the player can hold it, otherway it will drop the items to the floor. I was trying to prevent that, but I guess I can implement my of checks in order to determine if the player will be able to hold it.

  • Author

Thanks. It's working almost perfectly. Just for some reason I couldn't find out yet, if while the method it giving me the items and my inventory is all full except 1 slot and my active hand is in that slot, I get 1 itemstack but the rest starts spawning on the floor.

I guess I will have to copy the method and see why that happens and change behavior.

PS: If items start filling the last empty slot on my inventory and my hand wasn't there, it keeps filling correctly.

  • Author

Actually, as soon as I select in my hand any of the stacks, it start putting content on a new empty slot, instead of the one with still room for more items on it.

  • Author

So I have an item that is trying to put items on player inventory onUpdate and every X tics.

Using the ItemHandlerHelper.giveItemToPlayer as you mentioned. I give the player, let's say 4 Stone Bricks.

Now lets say I have slots 1 thru 9 empty, and this item is in my inventory, doing it's thing.

My "hand" is on slot 9 (My slot selected as main hand)

The item starts placing 4 Stone bricks at a time on slot 1 that was empty. So it goes (4-8-12-16 and so on)

As soon as I "move my hand" to slot 1, then the item starts placing items on slot 2 (The next empty slot available) and it doesn't keep popping items on slot 1 even when it still has room to accept more items. Then if I move hand to slot 2, it stops popping blocks there and goes to slot 3 and so on and so on.
ย 

I believe I now know what the error is, will do some testing tomorrow and post updates

Edited by American2050

  • Author
Just now, diesieben07 said:

That... is very strange and I cannot see from the code why it would do that.

I believe I figured out what the problem is, will do some tests tomorrow and let you know. I believe at some point in my code I was checking for empty slots and passing the prefered slot instead of passing -1 so probably (most likely) that is messing.

I will update after I do testings ;)

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.