Jump to content

Recommended Posts

Posted (edited)

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

Posted

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.

Posted (edited)

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

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