I have a block with a tile entity that compares arrays of items thrown in it, and creates a new item if the array matches a recipe I have stored elsewhere. This means that I need to store the item(arrays) in an NBT tag. However, NBTTagCompound doesn't have any setters or getters for items or item arrays. How do I store an item in an NBT tag?
Rollback Post to RevisionRollBack
Teleporting XP, for when you want to improve performance with XP farms
ItemStack implements INBTSerializable<NBTTagCompound>, so use INBTSerializable#serializeNBT to serialise an ItemStack to an NBTTagCompound.
Use an NBTTagList to store a collection of non-numeric NBT tags (e.g. NBTTagCompound).
Normally if you're dealing with a list of ItemStacks, you should use an IItemHandler implementation like ItemStackHandler and let it handle storing and serialising the ItemStacks for you.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Further to this, you can look at how vanilla tile entities store items, like the chest. They use exactly what Choonster just explained, but you can see an example of it in vanilla code. FYI I don't think they use IItemHandler though.
I have a block with a tile entity that compares arrays of items thrown in it, and creates a new item if the array matches a recipe I have stored elsewhere. This means that I need to store the item(arrays) in an NBT tag. However, NBTTagCompound doesn't have any setters or getters for items or item arrays. How do I store an item in an NBT tag?
Teleporting XP, for when you want to improve performance with XP farms
ItemStack implements INBTSerializable<NBTTagCompound>, so use INBTSerializable#serializeNBT to serialise an ItemStack to an NBTTagCompound.
Use an NBTTagList to store a collection of non-numeric NBT tags (e.g. NBTTagCompound).
Normally if you're dealing with a list of ItemStacks, you should use an IItemHandler implementation like ItemStackHandler and let it handle storing and serialising the ItemStacks for you.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Further to this, you can look at how vanilla tile entities store items, like the chest. They use exactly what Choonster just explained, but you can see an example of it in vanilla code. FYI I don't think they use IItemHandler though.