I just can't seem to figure this one out. I copied the code for saving my slots from a TileEntity nbt read write section I've created in the past. The TE works fine, but this IInventory doesn't seem to want to save. There must be a spot I'm missing a markDirty() [which contains the writeToNBT inside it]... Any ideas?
Rollback Post to RevisionRollBack
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
public void markDirty()
for (int i = 0; i < getSizeInventory(); ++i)
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
itemslots[i] = null;
because first you have to save your content and then you can set all slots to null.
P.S. the line Minecraft.getMinecraft().thePlayer will crash your minecraft when exexuted on client side. I suggest you to pass the EntityPlayer instance that opened the backpack in your constructor, save it in a variable and then reuse it
Soo Minecraft class is client only. (that means that the MC class loader will skip it). And nbt requires both sides for it to be functional. So instead of Minecraft.getMinecraft().thePlayer you need to save the player in the class and use it in the mark dirty method. Try launching the mod on the server and you'll get an error. SO you cant use Minecraft.getMinecraft().thePlayer it the code is ever going to run on server. aka it's not rendering classes or guis
Also you are setting all the slots to null when saving and that does not make much sense
Edit: Wops I didn't see the comment above! I didn't refresh the site before posting. Sorry for duplicate reply!