Jump to content

How to filter inventory items that only contains a certein action?


Psvxe

Recommended Posts

I've tried a few things but none of them do exactly what I want it to do.

 

I don't want to write up all kind of food but instead I want to figure out what they use as food by checking their inventory. Now the problem is that they coud have different items beside food too in their inventory. 

This is why I came up with the idea to filter the items by the menu action they have. However, the API doesn't contain a method for that.

 

So now I'm working on my own method.

 

This is my concept idea;

 

  1. Get all items in inventory and put them in a arrayList
  2. Figure out if items in inventory has the action "Eat"
  3. If not, remove from arrayList.

Now I'm just not sure how I'm going to create this.

 

Any help is welcome!

Link to comment
Share on other sites

inventory.filter(new Filter<Item>() {
            public boolean match(Item item) {
                return item.hasAction("Eat");
            }
        });

Something like this?

 

 

 

List<Item> items = Arrays.asList(getInventory().getItems()).stream().filter(s -> s.hasAction("Eat")).collect(Collectors.toList());

 

I'll try both of them. Looks promising. And way smoother than what I did.. haha Thanks!

Link to comment
Share on other sites

This is where i need to learn better methods all the ones above look better than what i would have done lel.

I would have gotten a all the items in inventory then for each item check if it has the action and if it does add it to a array list >.>

 

My way seems t0o much -  Im such a nub atm aha

Edited by Fruity
Link to comment
Share on other sites

This is where i need to learn better methods all the ones above look better than what i would have done lel.

I would have gotten a all the items in inventory then for each item check if it has the action and if it does add it to a array list >.>

 

My way seems t0o much -  Im such a nub atm aha

 

The methods above only became accessible to us a couple of weeks ago so dw, yours was pretty much the way to go before that ;)

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
Reply to this topic...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...