Posted October 29, 201411 yr how can I store an ItemStack in an NBT (it's for a tileEntity Inventory). The thing is, is that it's not with a GUI, so I don't want to implement IInventory. Can someone help? The proud(ish) developer of Ancients
October 29, 201411 yr https://github.com/Eternaldoom/Realms-of-Chaos/blob/1.8/com/eternaldoom/realmsofchaos/blocks/TileEntityDisplayCase.java Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
October 29, 201411 yr Author Does this allow for the ItemStack to be stored in the NBT of a TileEntity? It looks like you are just setting the NBT for the ItemStack. The proud(ish) developer of Ancients
October 29, 201411 yr In writeToNBT, I'm setting a compound tag with the data from the itemstack, and reading it in readFromNBT. Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
October 29, 201411 yr Why not use IInventory? Even if you dont use a gui (which is totally missing the point of why people use IInventory) it is still the interface to use when creating a inventory. it gives compatibility between mods and minecraft hoppers. And if you look in the ItemStack class you can see that there are methods for writing an stack to NBT and methods for loading a stack from NBT. Use those. http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
October 29, 201411 yr Author I found loadItemStackFromNBT() but what is the other function to get an NBT tag from an ItemStack? I don't want to use IInventory mainly because I don't want my mod to be easily automatable with other mods because I will add my own kind of automation, I will probably add a single block to add compatibility instead of having to use autonomus activators (from Thermal Expansion) to interact with my blocks. The proud(ish) developer of Ancients
October 29, 201411 yr you can get the NBTTagCompound from an ItemStack with the getTagCompound() method. Note that by default an ItemStack does not have an NBTTagCompound so you need to check for that, and create one if null. to load an ItemStack from nbt you need ItemStack.loadItemStackFromNBT(tag). and to save an ItemStack to nbt you need stack.writeToNBT(tag). http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
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.