Jump to content

Function called for Items in Chests?


Draco18s

Recommended Posts

I have an item that applies a passive effect to the player that's carrying it, and I can remove this effect when the item is dropped, but I can't seem to find a spot that will let me know that the item was removed from the player's inventory and placed into another object's inventory.

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

I know 2 ways to check if an special Item is inside of the Players Inventory.

 

First way is from the item itself (onUpdate() function).

 

Second way is from an entityliving update handler. with that you should can scan the inventory of the player.

 

I think this shoud be what you are asking. If not explain it in more detail.

 

 

Link to comment
Share on other sites

I want to know when it's NOT in the player's inventory.

 

And scanning every inventory of every player on a server ever tick is not a viable solution.

 

I only need the function called once (the frame that it leaves the player's inventory) but I need something.

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

I'm not sure that's all that viable either, as these effects are unique (each has a separate UUID for the SharedMonsterAttribute system, so that they stack), so I need to remove exactly the one that was placed into the chest.

 

I'd have to add several flags to every player. :\  If they have any, then I need to loop through their entire inventory and verify each one.

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

Whenever one of these items is added to a player's inventory, store its UUID in a Map in IExtendedEntityProperties or someplace. Then, either find a way to inject code (ASM?) or edit base classes so that the InventoryPlayer checks for your Item onInventoryChanged, decrStackSize etc. and before setting the itemstack to null, remove its UUID from the map. That's the only way I can think of that wouldn't require doing lots of checks every tick.  :-\

Link to comment
Share on other sites

Moritz and I found a solution that works well enough:

 

onUpdate, if the player has an inventory open, remove effect.  So the effect is suppressed while they're looking in a chest.

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

I got another problem for you. What happends when the player (standart keybinding) is Pressing Q? (Means drop a item in your hand)

 

It gets tossed into the world as an EntityItem, and because THAT receives updates, it's easy to go "oh, hey, I've been dropped.  Hey NBT, what was the player's entity ID?"

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

You can also use the ItemTossEvent.

 

Because of the way my items are built, I'm already using the EntityItemUpdate function (as there are effects which use it) so tying into that isn't difficult and keeps everything inside my Item class.

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

.  Putting items into item frames doesn't trigger any kind of function either!  And doing that doesn't require opening a GUI!

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

That will be triggered before the block trigger the putItemin function^^"

 

Actually, it's not.  I checked.

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

Well if it's triggered after, you could check if the block being right clicked on is an Item Frame (or were Item Frame entities?), and then get the stored item from its TileEntity.

 

But even if this works, you still have the problem that this is not very reliable. You might have missed other vanilla features or other mods could easily add other features that take an item from your inventory by right clicking on something.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

Well if it's triggered after, you could check if the block being right clicked on is an Item Frame (or were Item Frame entities?), and then get the stored item from its TileEntity.

 

It's not triggered before OR after, none of the item's functions are called.

 

I think the problem is how you are doing your effect on the item.

It is bringing a lot of stupid issues because of this.

 

How would you make an item that gives the player bonus health while they are carrying it?

 

Edit: You could use the EntityInteractEvent and check for EntityItemFrame.

 

I am trying to do this without events, but if I have to for this case I will.

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

Hi.

 

Just a suggestion - if it's too expensive to check the inventory every tick, why not check (say) every 20 ticks.  A delay of 1 second will probably be unnoticeable to the player I imagine, depending on what "effect" you are applying.  Even if it is noticeable, perhaps you can turn it into a feature (eg - "the unholy aura effect lasts for 10 seconds after you throw away the skull of putrescence", or similar).

 

And to be honest I doubt it really takes that much extra time to check a player's inventory slots for a particular item ID.  You could try it with a profiler and see if it is a significant slowdown or not.

 

All the other solutions sound a bit fragile to me.

 

Cheers

  TGG

 

Link to comment
Share on other sites

And to be honest I doubt it really takes that much extra time to check a player's inventory slots for a particular item ID

 

And then read that item's NBT data. :|

This isn't "oh, Item ID 1322 increases your health" it "Item ID 1322 {["onOwned":"increaseHealth"}]" vs. "Item ID 1322 {["onOwned":"increaseSpeed"}]" vs. "Item ID 1322 {["onUpdate":"heal1"}]" vs. "Item ID 1322 {["onRightClick":"causeLightning"}]" vs....

 

Anyway, if we're going to call things features, I think it would be a more interesting "feature" that items in frames are permanent boosts. :P

It's like a litch's phylactery!

 

It just isn't meaningful in SSP: no one can try and sneak into your base and "destroy" your powerbase.

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

Now there's an idea for a mod :)

 

You mean the one I'm working on?

 

At last check I have over 67 million different items which may or may not have enchantments.

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

Lol draco, I'm giving you cred++; just for the signature you have on MCF there, nice one :)

 

My signature arose from the fact that I tried to kindly remind someone that they shouldn't post in mod threads about updates.  I was all "hey, I just found out myself, but your post is technically against the TOS, didn't want to get you in trouble, just thought I'd let you know."

Someone decided I was being a total asshat.

Flames ensued.

 

I ended up reporting my own post to the mods for calling myself an asshole.

 

So I created my signature in an effort to deter such events in the future.

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.