Jump to content

[SOLVED] [1.16.1] How to check if player can take a stack?


RubyNaxela

Recommended Posts

Hello,
What's the method that checks if player can take a certain stack? Like, if the player has 35.5 full stacks of dirt in their inventory, they still can take a stack of 32 blocks of dirt, but can't take either a stack of  33 dirt or a stack of any amount of cobblestone.

Edited by RubyNaxela
Link to comment
Share on other sites

1 hour ago, RubyNaxela said:

Hello,
What's the method that checks if player can take a certain stack? Like, if the player has 35.5 full stacks of dirt in their inventory, they still can take a stack of 32 blocks of dirt, but can't take either a stack of  33 dirt or a stack of any amount of cobblestone.

PlayerInventory#addItemStackToInventory 's javadoc:
"Adds the stack to the first empty slot in the player's inventory. Returns {@code false} if it's not possible to place the entire stack in the inventory."

Everything said above may be absolutely wrong. No rights reserved.

Link to comment
Share on other sites

There's also:

ItemStackHandler.insert(stack, true).isEmpty()

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 hours ago, Dzuchun said:

PlayerInventory#addItemStackToInventory 's javadoc

Wait a minute... where can I get Minecraft source with javadoc? I've always used the .jar that is included in Forge MDK decompiled with Fernflower whenever I need to take a look at the game code.

Link to comment
Share on other sites

20 minutes ago, RubyNaxela said:

Wait a minute... where can I get Minecraft source with javadoc?

Its in your external resources.

image.png

The first one is most of the code, client-extra.jar has a lot of the recipes, blockstates, and such.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Is this Eclipse? Apparently it has a different initial gradle script than IntelliJ - which I am using. I don't have two forge libraries. I only have one which contains the compiled .jar file.
And, yes, I also have client-extra and I use it as well.

Link to comment
Share on other sites

Thank you all for trying to point me out where to find the source/recomp library, but I know where would it be, it is just not present in my External Libraries list now, when I work with 1.16.1. The only way I can access it is from file explorer. Maybe some configuration error. Anyway, this thread seems to have deviated much from the topic.

I wrote a function:

public static void giveItemStack(PlayerEntity player, ItemStack stack) {
  if (!player.addItemStackToInventory(stack)) {
    player.dropItem(stack, false);
  }
}

that now works pretty much the same as the /give command, which is exactly what I wanted.

7 hours ago, Dzuchun said:

PlayerInventory#addItemStackToInventory returns false if it's not possible to place the entire stack in the inventory.

Thanks @Dzuchun for that precious piece of information.

Link to comment
Share on other sites

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.