Your code should work exactly the same whether it is on a dedicated server or not, so if you're getting strange behavior, the first place I'd look is in your Container class. Make sure all of your slots are in the location you think they are, that none overlap, etc.
Also, when debugging your code, ALWAYS disable / remove any other mods that might be affecting it, such as Inventory Tweaks, otherwise it becomes very difficult to figure out if the bug is in your code, or caused by something else.
Ok, now thank for your help found the problem.
I think its the Merge Item stack method haven't read your Item Storage tutorial just the player one.
But I have now the problem how can I get the Inventory in the Merge method when I want to use the custom player inventory?
Container class:
public class ContainerCustomPlayer extends Container{
// Armor Slots
for (i = 0; i < 4; ++i){
this.addSlotToContainer(new SLOT_ARMOR(player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 44, -1 + i * 18, i));
}
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i){
for (int j = 0; j < 9; ++j){
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 91 + i * 18));
}
}
//Hotbar
for (i = 0; i < 9; ++i){
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 149));
}
inventory2 = inventoryCustom;
}
@Override
public boolean canInteractWith(EntityPlayer player){
return true;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/
public ItemStack transferStackInSlot(EntityPlayer player, int par2){
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack()){
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// Either armor slot or custom item slot was clicked
if (par2 < INV_START){
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)){
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else{
// if item is our custom item
if (itemstack1.getItem() instanceof MagicItemBase){
if (!this.mergeItemStack(itemstack1, 0, InventoryCustomPlayer.INV_SIZE, false)){
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor){
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)){
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START){
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false)){
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1){
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)){
return null;
}
}
}
if (itemstack1.stackSize == 0){
slot.putStack((ItemStack) null);
}
else{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize){
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
}
//IMPORTANT to override the mergeItemStack method if your inventory stack size limit is 1
/**
* Vanilla method fails to account for stack size limits of one, resulting in only one
* item getting placed in the slot and the rest disappearing into thin air; vanilla
* method also fails to check whether stack is valid for slot
*/
@Override
protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards)
{
boolean flag1 = false;
int k = (backwards ? end - 1 : start);
Slot slot;
ItemStack itemstack1;
if (stack.isStackable())
{
while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start))
{
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack();
if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
}
if (itemstack1 != null && itemstack1.getItem() == stack.getItem() &&
(!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) &&
ItemStack.areItemStackTagsEqual(stack, itemstack1))
{
int l = itemstack1.stackSize + stack.stackSize;
if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) {
stack.stackSize = 0;
itemstack1.stackSize = l;
inventory2.markDirty();
flag1 = true;
} else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) {
stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = stack.getMaxStackSize();
inventory2.markDirty();
flag1 = true;
}
}
k += (backwards ? -1 : 1);
}
}
if (stack.stackSize > 0)
{
k = (backwards ? end - 1 : start);
while (!backwards && k < end || backwards && k >= start) {
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack();
if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
}
if (itemstack1 == null) {
int l = stack.stackSize;
if (l <= slot.getSlotStackLimit()) {
slot.putStack(stack.copy());
stack.stackSize = 0;
inventory2.markDirty();
flag1 = true;
break;
} else {
putStackInSlot(k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage()));
stack.stackSize -= slot.getSlotStackLimit();
inventory2.markDirty();
flag1 = true;
}
}
k += (backwards ? -1 : 1);
}
}
return flag1;
}
}
That is some very bizarre behavior indeed, but unless you modified the mergeItemStack method, I can tell you with 99.9% certainty it is not that The method is only called from transferStackInSlot, which is only called when shift-clicking in your inventory, and it does not look like you shift-clicked at all in your demo of the problem. Not only that, but I have tested the method pretty thoroughly
It seems more like a problem in your actual IInventory implementation, or perhaps in some other aspect of your code, whether in how you handle the inventory in your IEEP class or how you open the gui in the first place.
All in all, it's a pretty difficult type of bug to track down, but at least it's reproducible.
Maybe someday - the forum editor is extremely fickle and entirely unpleasant to work with even almost a year after the 'improvement.'
Besides, there really aren't THAT many differences - the flow and logic is all the same regardless of Minecraft version, so as long as you are competent enough to realize that, for example, packets are no longer sent the same way, it is trivial to update the code to work with whatever version you are on.
You have to keep in mind that the purpose of this tutorial is simply to show you how to create the inventory aspects; packet handling, key handling, and even IEEP are all extraneous bits of information that you should either already know how to do or take the time to learn about them BEFORE tackling this tutorial, which is the reason they are listed in the PREREQUISITES section:
Prerequisites:
1 - You should already have your Main Mod, CommonProxy and ClientProxy set up. If you don't know about that, check out TechGuy543's excellent
tutorial.
2 - Know how to use IExtendedEntityProperties; best if you already have one set up.
3 - Know how to use KeyBindings; best if you already have one set up.
4 - Know how to use Packets; best if you've already set up a PacketHandler.
5 - Familiarity with IInventory and Containers is helpful, but not essential.
I have Known already all that stuff and had it but how i said i am opening the gui currently trough a block and i have mixed server and client side.
Ps. wouldn't it be possible to write the forum post in an Editor and to just copy and paste it?
I don't see how rewriting the tutorial would help with your block / mixing up server and client situation...
Re: using an editor - that's what I do, but the forum editor almost always chomps it to bits with its automatic parsing of text / BBCode into what it thinks I meant, rather than just showing what I wrote as it is. What should take a few minutes ends up taking 20 or an hour, and sometimes even then the formatting is just so mangled that I just give up and leave the post as it originally was (hopefully...).
Great tutorial but trying to update all of the code is really confusing and i would find it a lot easier if yo could rewrite it so that it is more clear and easier to understand what is going on in the code (1.6 code was horrible)
Great tutorial but trying to update all of the code is really confusing and i would find it a lot easier if yo could rewrite it so that it is more clear and easier to understand what is going on in the code (1.6 code was horrible)
1.6 code wasn't so bad, but the way most people handled packets back then was indeed terrible. Still, all of the concepts remain identical with very few changes (aside from the network code) from 1.6 to 1.8.
Since you should already have a decent grasp on basic Minecraft modding, such as Items and Blocks, before tackling this tutorial, updating the code is a great way to make sure you really understand what's going on, rather than just copy/pasting everything.
Can you help me then I have updated everything I know that code works but when I try it the Gui does not open trying to use code for both 1.7.10 and 1.8 but i have only worked on 1.7.10 so far
Can you help me then I have updated everything I know that code works but when I try it the Gui does not open trying to use code for both 1.7.10 and 1.8 but i have only worked on 1.7.10 so far
Well what version are you aiming for? You can't use code from two different versions. Also, which kind of inventory are you making, an Item-based one or a player/IEEP-based one?
Item Inventory and right now I am coding for 1.7.10 I have no errors in the code and have updated it all correctly and changed the Key press from I to B but when I am in game the GUI does not pop up
If you want to look at the code I can send you the Files
Item Inventory and right now I am coding for 1.7.10 I have no errors in the code and have updated it all correctly and changed the Key press from I to B but when I am in game the GUI does not pop up
If you want to look at the code I can send you the Files
I'm not going to download any files, sorry. Do you have a Github or Bitbucket repository? I would look at it there.
Otherwise, for starters, post your key handling code and IGuiHandler.
You didn't register your IGuiHandler. You must do so during one of the FML initialization events.
Also, you should initialize your items during FMLPreInitializationEvent, not inlined like you have, and you also need to register your item.
Finally, it seems you are correct - I do need to update the main post, because the Item code is pretty terrible. You shouldn't be trying to handle key presses anywhere except in a KeyHandler class, and you should be making a KeyBinding, and you have to send a packet. There's a LOT that goes into making this work, which is why I caution in the tutorial that it is not for beginners.
There is information on all of the things that you will need, both in this tutorial, the one for a Custom Player Inventory, in my other tutorials, and in other people's tutorials throughout the web. You will need to do some searching and lots of reading.
You didn't register your IGuiHandler. You must do so during one of the FML initialization events.
Also, you should initialize your items during FMLPreInitializationEvent, not inlined like you have, and you also need to register your item.
Finally, it seems you are correct - I do need to update the main post, because the Item code is pretty terrible. You shouldn't be trying to handle key presses anywhere except in a KeyHandler class, and you should be making a KeyBinding, and you have to send a packet. There's a LOT that goes into making this work, which is why I caution in the tutorial that it is not for beginners.
There is information on all of the things that you will need, both in this tutorial, the one for a Custom Player Inventory, in my other tutorials, and in other people's tutorials throughout the web. You will need to do some searching and lots of reading.
Thanks a ton i did forget to register the two and it works now and Also if you would like to use my Github code as an example for other people it works perfectly now I will also make the KeyHandler class
Thanks a ton i did forget to register the two and it works now and Also if you would like to use my Github code as an example for other people it works perfectly now I will also make the KeyHandler class
Ahem. It's mentioned some of my other tutorials as well as my profile, but looks like this one got left out xD
Sorry again, the tutorial on the main page truly is outdated, now that I am looking through the code. If it weren't such a gamble editing it, I would fix it, but for now you can see on the demo I linked earlier - I redid the entire code surrounding how the inventory is saved.
You can see the Item class is much simpler now, and the part now responsible for making sure the data is saved is in the IInventory implementation. Those are links to the 1.7.10 version, but there is a 1.8 branch as well.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYour code should work exactly the same whether it is on a dedicated server or not, so if you're getting strange behavior, the first place I'd look is in your Container class. Make sure all of your slots are in the location you think they are, that none overlap, etc.
Also, when debugging your code, ALWAYS disable / remove any other mods that might be affecting it, such as Inventory Tweaks, otherwise it becomes very difficult to figure out if the bug is in your code, or caused by something else.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumOh wow, yeah I have added one slot twice, well that was stupid. Thanks!!!!
Flux Networks - CurseForge - Source Code
Practical Logistics 2 - CurseForge - Source Code
Calculator - CurseForge - Source Code
Bagelsmore - CurseForge - Source Code
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumBut I have now the problem how can I get the Inventory in the Merge method when I want to use the custom player inventory?Container class:
private final InventoryCustomPlayer inventory2;
private static final int ARMOR_START = InventoryCustomPlayer.INV_SIZE, ARMOR_END = ARMOR_START+3,INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,HOTBAR_END = HOTBAR_START+8;
public ContainerCustomPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer inventoryCustom){
int i; //custom Slots
this.addSlotToContainer(new SLOT_POUCH(inventoryCustom, 0, 116, -1));
this.addSlotToContainer(new SLOT_POUCH(inventoryCustom, 1, 116, 17));
this.addSlotToContainer(new SLOT_POUCH(inventoryCustom, 2, 116, 35));
this.addSlotToContainer(new SLOT_POUCH(inventoryCustom, 3, 116, 53));
this.addSlotToContainer(new SLOT_POUCH(inventoryCustom, 4, 116, 71));
// Armor Slots
for (i = 0; i < 4; ++i){
this.addSlotToContainer(new SLOT_ARMOR(player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 44, -1 + i * 18, i));
}
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i){
for (int j = 0; j < 9; ++j){
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 91 + i * 18));
}
}
//Hotbar
for (i = 0; i < 9; ++i){
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 149));
}
inventory2 = inventoryCustom;
} @Override
public boolean canInteractWith(EntityPlayer player){
return true;
} /**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/ public ItemStack transferStackInSlot(EntityPlayer player, int par2){
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack()){
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// Either armor slot or custom item slot was clicked
if (par2 < INV_START){
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)){
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else{
// if item is our custom item
if (itemstack1.getItem() instanceof MagicItemBase){
if (!this.mergeItemStack(itemstack1, 0, InventoryCustomPlayer.INV_SIZE, false)){
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor){
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)){
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START){
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false)){
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1){
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)){
return null;
}
}
}
if (itemstack1.stackSize == 0){
slot.putStack((ItemStack) null);
}
else{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize){
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
} //IMPORTANT to override the mergeItemStack method if your inventory stack size limit is 1
/**
* Vanilla method fails to account for stack size limits of one, resulting in only one
* item getting placed in the slot and the rest disappearing into thin air; vanilla
* method also fails to check whether stack is valid for slot
*/
@Override
protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards)
{
boolean flag1 = false;
int k = (backwards ? end - 1 : start);
Slot slot;
ItemStack itemstack1; if (stack.isStackable())
{
while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start))
{
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack(); if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
} if (itemstack1 != null && itemstack1.getItem() == stack.getItem() &&
(!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) &&
ItemStack.areItemStackTagsEqual(stack, itemstack1))
{
int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) {
stack.stackSize = 0;
itemstack1.stackSize = l;
inventory2.markDirty();
flag1 = true;
} else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) {
stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = stack.getMaxStackSize();
inventory2.markDirty();
flag1 = true;
}
} k += (backwards ? -1 : 1);
}
} if (stack.stackSize > 0)
{
k = (backwards ? end - 1 : start); while (!backwards && k < end || backwards && k >= start) {
slot = (Slot) inventorySlots.get(k);
itemstack1 = slot.getStack(); if (!slot.isItemValid(stack)) {
k += (backwards ? -1 : 1);
continue;
} if (itemstack1 == null) {
int l = stack.stackSize; if (l <= slot.getSlotStackLimit()) {
slot.putStack(stack.copy());
stack.stackSize = 0;
inventory2.markDirty();
flag1 = true;
break;
} else {
putStackInSlot(k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage()));
stack.stackSize -= slot.getSlotStackLimit();
inventory2.markDirty();
flag1 = true;
}
} k += (backwards ? -1 : 1);
}
} return flag1;
} }
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThat is some very bizarre behavior indeed, but unless you modified the mergeItemStack method, I can tell you with 99.9% certainty it is not that
The method is only called from transferStackInSlot, which is only called when shift-clicking in your inventory, and it does not look like you shift-clicked at all in your demo of the problem. Not only that, but I have tested the method pretty thoroughly 
It seems more like a problem in your actual IInventory implementation, or perhaps in some other aspect of your code, whether in how you handle the inventory in your IEEP class or how you open the gui in the first place.
All in all, it's a pretty difficult type of bug to track down, but at least it's reproducible.
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumok... fixed it can't believe how stupid I was...
I though that worldIsRemote returns true when its server side but it looks like it is exactly the other way :/
But its working thank you for your help.
Oh and could you update your main post? There are extreme differences between the main thread and your repository.
(Your repository helped me also to understand the mana packet handling ^^)
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumMaybe someday - the forum editor is extremely fickle and entirely unpleasant to work with even almost a year after the 'improvement.'
Besides, there really aren't THAT many differences - the flow and logic is all the same regardless of Minecraft version, so as long as you are competent enough to realize that, for example, packets are no longer sent the same way, it is trivial to update the code to work with whatever version you are on.
You have to keep in mind that the purpose of this tutorial is simply to show you how to create the inventory aspects; packet handling, key handling, and even IEEP are all extraneous bits of information that you should either already know how to do or take the time to learn about them BEFORE tackling this tutorial, which is the reason they are listed in the PREREQUISITES section:
Prerequisites:
1 - You should already have your Main Mod, CommonProxy and ClientProxy set up. If you don't know about that, check out TechGuy543's excellent
tutorial.
2 - Know how to use IExtendedEntityProperties; best if you already have one set up.
3 - Know how to use KeyBindings; best if you already have one set up.
4 - Know how to use Packets; best if you've already set up a PacketHandler.
5 - Familiarity with IInventory and Containers is helpful, but not essential.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI have Known already all that stuff and had it but how i said i am opening the gui currently trough a block and i have mixed server and client side.
Ps. wouldn't it be possible to write the forum post in an Editor and to just copy and paste it?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI don't see how rewriting the tutorial would help with your block / mixing up server and client situation...
Re: using an editor - that's what I do, but the forum editor almost always chomps it to bits with its automatic parsing of text / BBCode into what it thinks I meant, rather than just showing what I wrote as it is. What should take a few minutes ends up taking 20 or an hour, and sometimes even then the formatting is just so mangled that I just give up and leave the post as it originally was (hopefully...).
Great tutorial but trying to update all of the code is really confusing and i would find it a lot easier if yo could rewrite it so that it is more clear and easier to understand what is going on in the code (1.6 code was horrible)
-
View User Profile
-
View Posts
-
Send Message
Curse Premium1.6 code wasn't so bad, but the way most people handled packets back then was indeed terrible. Still, all of the concepts remain identical with very few changes (aside from the network code) from 1.6 to 1.8.
Since you should already have a decent grasp on basic Minecraft modding, such as Items and Blocks, before tackling this tutorial, updating the code is a great way to make sure you really understand what's going on, rather than just copy/pasting everything.
Can you help me then I have updated everything I know that code works but when I try it the Gui does not open trying to use code for both 1.7.10 and 1.8 but i have only worked on 1.7.10 so far
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWell what version are you aiming for? You can't use code from two different versions. Also, which kind of inventory are you making, an Item-based one or a player/IEEP-based one?
Item Inventory and right now I am coding for 1.7.10 I have no errors in the code and have updated it all correctly and changed the Key press from I to B but when I am in game the GUI does not pop up
If you want to look at the code I can send you the Files
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI'm not going to download any files, sorry. Do you have a Github or Bitbucket repository? I would look at it there.
Otherwise, for starters, post your key handling code and IGuiHandler.
Here Is the GitHub link to it all of the code has no errors on my side
https://github.com/KingZero/BackPack/tree/master
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou didn't register your IGuiHandler. You must do so during one of the FML initialization events.
Also, you should initialize your items during FMLPreInitializationEvent, not inlined like you have, and you also need to register your item.
Finally, it seems you are correct - I do need to update the main post, because the Item code is pretty terrible. You shouldn't be trying to handle key presses anywhere except in a KeyHandler class, and you should be making a KeyBinding, and you have to send a packet. There's a LOT that goes into making this work, which is why I caution in the tutorial that it is not for beginners.
There is information on all of the things that you will need, both in this tutorial, the one for a Custom Player Inventory, in my other tutorials, and in other people's tutorials throughout the web. You will need to do some searching and lots of reading.
Thanks a ton i did forget to register the two and it works now and Also if you would like to use my Github code as an example for other people it works perfectly now I will also make the KeyHandler class
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAhem. It's mentioned some of my other tutorials as well as my profile, but looks like this one got left out xD
Okay I hope this will be the last thing
Anything in Backpack is deleted when opened again
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSorry again, the tutorial on the main page truly is outdated, now that I am looking through the code. If it weren't such a gamble editing it, I would fix it, but for now you can see on the demo I linked earlier - I redid the entire code surrounding how the inventory is saved.
You can see the Item class is much simpler now, and the part now responsible for making sure the data is saved is in the IInventory implementation. Those are links to the 1.7.10 version, but there is a 1.8 branch as well.