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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, I was trying to play a MOD in my preferred language, but I see that only some items are translated, and I go to debug and I get this information (the only thing that is translated is the bestiary):   [14sep.2024 17:14:36.415] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: mowziesmobs:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 394 column 2 path $.config.mowziesmobs.ice_crystal_attack_multiplier) [14sep.2024 17:14:36.421] [Render thread/WARN] [net.minecraft.client.resources.language.ClientLanguage/]: Skipped language file: iceandfire:lang/es_es.json (com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1349 column 4 path $.iceandfire.sound.subtitle.dragonflute)   Is that the reason why everything is not translated? , and is there any way to fix it? Thanks
    • I got my model to render from the models renderToBuffer method. But still not quite what I want. I want to render the model from my renderer's render method. I feel that having access to the renderer and its methods will open some doors for me later down the line. //EntityRendererProvider.Context pContext = ; I want this //ToaPlayerRenderer render = new ToaPlayerRenderer(pContext, false); // if I can get the above line to work, having the methods from the renderer class would be incredibly helpful down the line RenderType rendertype = model.renderType(p.getSkinTextureLocation()); // this should be something like render.getTextureLocation() VertexConsumer vertexconsumer = buffer.getBuffer(rendertype); model.renderToBuffer(stack, vertexconsumer, paLights, 1, 1, 1, 1, 1); // I don't want the render to happen here since it doesn't use the renderer //model.render(p, 1f, pTicks, stack, buffer, paLights); I want to render the model using this It is certainly getting closer though. Probably. I am still worried that even if pContext is initialized this new instance of the renderer class will still hit me with the classic and all too familiar "can't use static method in non-static context"
    • Hello, I am learning how to create Multipart Entities and I tried creating a PartEntity based on the EnderDragonPart code. However, when I tested summoning the entity in the game, the PartEntity appeared at position x 0, y 0, z 0 within the game. I tried to make it follow the main entity, and after testing again, the part entity followed the main entity but seemed to teleport back to x 0, y 0, z 0 every tick (I'm just guessing). I don't know how to fix this can someone help me? My github https://github.com/SteveKK666/Forge-NewWorld-1.20.1/tree/master/src/main/java/net/kk/newworldmod/entity/custom Illustration  https://drive.google.com/file/d/157SPvyQCE8GcsRXyQQkD4Dyhalz6LjBn/view?usp=drive_link Sorry for my English; I’m not very good at it. 
    • its still crashing with the same message
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.