American2050 Posted December 27, 2017 Posted December 27, 2017 (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 December 27, 2017 by American2050 Quote
American2050 Posted December 27, 2017 Author Posted December 27, 2017 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. Quote
American2050 Posted December 27, 2017 Author Posted December 27, 2017 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. Quote
American2050 Posted December 27, 2017 Author Posted December 27, 2017 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. Quote
American2050 Posted December 28, 2017 Author Posted December 28, 2017 (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 December 28, 2017 by American2050 Quote
American2050 Posted December 28, 2017 Author Posted December 28, 2017 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 Quote
Recommended Posts
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.