Jump to content

[1.12.2] TileEntity NBT refusing to load


Sataniq

Recommended Posts

Well, the title says it all, really. I have a TileEntity which is saving its NBT data (supposedly), but it won't load anything. Here's the code (only the parts you need to see):

private static final String NBTTAG_INVENTORY = "inventory";

private ItemStackHandler inventory = new ItemStackHandler(4)
{
  @Override
  protected void onContentsChanged (int slot)
  {
  	TileEntityCrusher.this.markDirty();
  }
};

@Override
public NBTTagCompound writeToNBT (NBTTagCompound compound)
{
  super.writeToNBT(compound);

  compound.setTag(NBTTAG_INVENTORY, this.inventory.serializeNBT());
  System.out.println("Saved crusher inventory");

  return compound;
}
    
@Override
public void readFromNBT (NBTTagCompound compound)
{
  if (compound.hasKey(NBTTAG_INVENTORY))
  {
    this.inventory.deserializeNBT(compound.getCompoundTag(NBTTAG_INVENTORY));
    System.out.println("Loaded crusher inventory");
  }
  else
  {
  	System.err.println("ERROR: Could not load crusher inventory");
  }

super.readFromNBT(compound);
}

 

As you can see, I'm using the output stream to log when the inventory is saved/loaded. All I see in the console is that it has saved, so the writeToNBT() is working. But then if I leave and re-join the world, I see NOTHING about loading, not a message saying it's loaded the inventory OR an error message saying it couldn't... nothing. The TileEntity loses its inventory every time. This is very frustrating, and I'm using the same code as my test project, where this worked just fine. What could be causing this mysterious and stupid behaviour? And yes, the TileEntity is registered... and no, I see no errors in the console.

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



×
×
  • Create New...

Important Information

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