Jump to content

[1.7.10] Is there any way to get the location of an ItemStack?


PrincessRTFM

Recommended Posts

I have an ItemStack object, and I know that's it's going to be inside either an EntityLiving's inventory, or an IInventory TileEntity. I want to get the location in the world of the container, regardless of which one it is. I can use different code for each scenario if I need to, but I haven't found any way to do this yet. Is it even possible, or am I out of luck?

Link to comment
Share on other sites

ItemStacks themself don't have a reference to the inventory they are in, so you have to find another way. Where do you get the ItemStack from?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Why do you need to know which inventory contains the stack?

As he said, because the item is being used as an RF container, and it's supposed to do different things depending on whether it's in the player's inventory or in a tile entity's inventory (I assume if it's in a tile entity, it charges that entity up, but if it's in a player's inventory, it instead charges the items in his inventory; that's the usual battery design).

 

ItemStacks have NBT data stored in their stackTagCompound member. One thing you could do is override the useItemRightClick() method; whenever a player right-clicks the item, it "activates" it, which in reality just stores that player's UUID in the NBT tags for later use.

 

As for clearing that tag when the item is put into a TileEntity's inventory...I'm not sure about that. If they were all your own tile entities, you could just make a custom slot class that extends slot but overrides the putStack() method to clear the tag. But since they're likely other people's containers...I'm not sure where to go from there.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Why do you need to know which inventory contains the stack?

As he said, because the item is being used as an RF container, and it's supposed to do different things depending on whether it's in the player's inventory or in a tile entity's inventory (I assume if it's in a tile entity, it charges that entity up, but if it's in a player's inventory, it instead charges the items in his inventory; that's the usual battery design).

 

ItemStacks have NBT data stored in their stackTagCompound member. One thing you could do is override the useItemRightClick() method; whenever a player right-clicks the item, it "activates" it, which in reality just stores that player's UUID in the NBT tags for later use.

 

As for clearing that tag when the item is put into a TileEntity's inventory...I'm not sure about that. If they were all your own tile entities, you could just make a custom slot class that extends slot but overrides the putStack() method to clear the tag. But since they're likely other people's containers...I'm not sure where to go from there.

 

Actually, I'm making a "raw" version of the capacitor (because the final one is OP) and I want the raw one to need to be charged to finish it, like it's being "infused" with RF. Think Draconic Evolution's charged draconium blocks. But I want to require that the player do this in a block, instead of having (for example) an EnderIO wireless charge in their house that crafts it in their inventory. If I can't do that, I guess I could just up the power required to craft it or something.

 

Also I'm not a he.

Link to comment
Share on other sites

You don't need special inventory detection code. Just use the normal IEnergyContainerItem and it should work with things like the Wireless Charger and Energetic Infuser.

 

But I don't want it to work with the Wireless Charger. I wanted it to only charge up in a charging block, not a player's inventory. Can't find a way to make that happen, so I've just put it on my todo list with a low priority.

Link to comment
Share on other sites

Do you have access to the charger recipes? If so you could just add a charger recipe.

 

I could probably use IMC for that, I think Thermal Expansion allows that sort of thing, but then it would only work in one specific block. I guess I can't make it work the way I was hoping to, but thanks to everyone who responded for the help!

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.