Jump to content

Recommended Posts

Posted

My question is how can one detect when an itemStack is being clicked on another specific item. for instance, if item1 = 1 and item2 = 2, (in the inventory, such the normal behavior is to have the ItemStacks switch places), if ItemStack 1 is being clicked on ItemStack 2, then do something. I have looked into various events and the potential of capabilities for the setItem method in ItemStack, yet i do not see a 'good' way of doing this function. How might I be able to implement such a function.

NOTE: Unless it is made in a way to guarantee that it will not cause any 'excessive' processing, if if it is the ONLY way, I do not care for some player event where the player inventory is checked every tick. Also, I do not care if it is a suggestion or the 'asnwer,' I mearly wish to know of what my potentials here are, what might work, what does, or just give up suggestions are all appreciated. 

 

EDIT: Or how might I find a way to detect changes in the ContainerPlayer class, for instance, is their an event for that?

EDIT: Due to issues in finding a potential answer to this, I shall specify further: I would like to add in a unique, custom way of 'crafting' recipes, where if item A is clicked on item B in slot, then both (ignoring specifics such as stack size) would be deleted from slot and replaced with item C. This would simply search from potential recipes to find matches. At this point, I am giving up on finding any reasonable solution.

Posted

Here's an option:

Override IContainerListener and add the listener to the container when it is created using Container.addListener. Perhaps the sendSlotContents method is the one you're looking for?

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Posted

Looked into this a bit, but to specify, I am talking about for the player's inventory. How to detect if a specific ItemStack is clicked on another specific ItemStack in the player's inventory.

Posted

Then my current question is of the most important, how should I do this. I say this in the respect of what is the best way. Is there a good hook I can use, or should I just put some if statements in the player tick event? Would prefer not to, but if that is the way, then so be it.

Posted
how can one detect when an itemStack is being clicked on another specific item.

or should I just put some if statements in the player tick event?

Well if you're looking for a item replacing another item via clicking. Tick Event won't cover that. You'd need something that would trigger with a "On Inventory" or "On Slot(container)" change that would know what the old and new ItemStack was for a Slot

 

This may not be 100% related, but it's close http://www.minecraftforge.net/forum/index.php?topic=42833.0

 

It's to do with Capabilities for ItemStacks, but I believe it can be easily applied to what you're trying to accomplish, yes it makes use of attaching a IContainerListener but that's so you can detect when something changes.

 

EDIT:

 

Well i guess you COULD use the tick event, but you'd have to store the old instance after each tick so you can compare and "See" the differences

Slot[6] was apple, next tick Slot[6] is now a cookie, do logic. But then of course you're scanning the Player inventory 2x each tick (old inv state you saved previous tick, and current inventory current tick) could take a bit of processing to run those two loops every tick

Posted
But then of course you're scanning the Player inventory 2x each tick (old inv state you saved previous tick, and current inventory current tick) could take a bit of processing to run those two loops every tick

 

That's actually an O(n) operation, not an O(2n).  You're still doing one loop, you're just comparing "old vs. new" and then either Doing Stuff or not, then saving new to old.  You don't need to loop twice.

 

But yes, not the most efficient way to do things.

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.

Posted

Oh, Sorry. I don't think you need a Capability for what you're trying to do. Sorry if my suggestion lead you astray. I was hoping some info for using a IContainerListener would have helped. As your desired result is:

 

Holding Item A

Click on Item B (in inventory)

Magic happens??

 

Perhaps someone more versed will see this. Apologies for not being helpful

Posted

No, its not your fault, this is just a tricky subject, for the desired result. I would like to avoid using reflection, but the only way I seem to be able to do this is by either gaining access of some form to player inventory, or through itemStack, not the later, since itemstack is used everywhere and it is final. Just more searching in the forge and minecraft jars for me, is all

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.