Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
TheTrue_DV

Counting occupied slots in an inventory.

Question

Basically... I want to have my robot hover over to a chest, count how many occupied slots there are and do something based on that count.

What I tried was:

 

Assuming that "ic" is "component.inventory_controller"

 

`ic.getAllStacks(sides.front)`

I was assuming that would offer something along the lines of 'ic.getAllStacks(sides.front).slotsOccupied() which would return what I was looking for... I found 'ic.getAllStacks(sides.front).count()' which I thought would do exactly what I wanted!

Then I found out that did the exact same thing as 'ic.getInventorySize()'. Returning the total number of slots in the entire inventory... I don't really understand why we have two functions that do the exact same thing, but oh well...

The other options are `.getAll()` and `.reset()`.

 

The solution i've gone for, which is incredibly memory intensive, is to `.getAll()`and then interate through that map to count each slot that isn't "air" and then return that number... It works, but I really struggle to believe there isn't a function premade for that...

 

So question is:

 

Is there a better way of going about that?

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.