Jump to content

[Forge 1.15.2] Item Filter help


NindyBun

Recommended Posts

My item container works fine, it acts as a normal bag; but I want to turn it into a filter, so how can I make my item container set/remove "ghost" items instead of setting/removing the physical item in a slot? Thanks in advance.

Note: I am asleep so I won't be able to answer till I wake up.

Link to comment
Share on other sites

I may not understand the context, but why don't you want to store "physical" items (I guess, you were talking about ItemStack)?

Can you also explain more, what do you mean at all?

P.S. Or you mean "ghost" items like in crafting table when you click on recipe?

Edited by Soft-fur dragon
Link to comment
Share on other sites

I'm pretty sure that you could override the Container#slotClick method, it handles what happens when, well, you click on a slot... the logic for it is quite obfuscated and confusing however... so there may be a better way to do it

EDIT: If I'm not mistaken, the code between lines 290 and 342 of the Container class are the ones which handles when the player is holding an ItemStack, and clicks on a slot of the container

Edited by kiou.23
Link to comment
Share on other sites

I did "ghost" items once, and this is the ItemStackHandler subclass:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/industry/inventory/FilterStackHandler.java

Looking at it now, I think line 23 is wrong, should be return stack.copy() (or pass a copy to super and return the original).

But I haven't messed with it in a while. The extract method is correct though.

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

6 hours ago, Draco18s said:

I did "ghost" items once, and this is the ItemStackHandler subclass:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/industry/inventory/FilterStackHandler.java

Looking at it now, I think line 23 is wrong, should be return stack.copy() (or pass a copy to super and return the original).

But I haven't messed with it in a while. The extract method is correct though.

So I returned stack.copy() and I am still holding the stack, but when I try to set stack in slot, it doesn't set the ItemStack.

Link to comment
Share on other sites

8 hours ago, Soft-fur dragon said:

I may not understand the context, but why don't you want to store "physical" items (I guess, you were talking about ItemStack)?

Can you also explain more, what do you mean at all?

P.S. Or you mean "ghost" items like in crafting table when you click on recipe?

Basically I want to make an Item Filter that allows the player to set a copy of the held item stack into a slot. 

Link to comment
Share on other sites

Show your code. Would be best if you posted a link to a git repo.

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

Why do you have both of these lines?

Why did you change this line? I told you that method was correct. By returning what's IN the slot you allow item duplication (remember, you're trying to create ghosts! Players can't acquire ghosts!)

Why do you have this method? You (1) aren't using it and (2) you aren't using imports and (3) you can just inline it's contents anywhere you would reference it.

OrElseThrow() is a thing. So is ifPresent(), which would obliviate the need for this static method anyway.

Jesus H Christ why are you comparing strings here.

And of course the rest of that if-stack is a bunch of absolutely nonsense. You're checking if the player's held stack is equal to any of the upgrades already applied or if the held stack is Fortune or Silk Touch and that one of the existing upgrades is the other (so either (a) there's an identical upgrade applied or (b) you generate a Fortune/Silk Touch pair) then if the held stack is an upgrade (why was this not checked first?) and the held stack has the same item as the selected inventory slot's item, return true. If any of that is false, prevent insertion.

Not only are all of those checks fucking nonsense, and done out of order, but what if the slot is empty? Your method returns false if the slot is empty, preventing the slot from ever being not-empty.

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

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.