Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

Ooookayyy then... so putting a System.out.println() at the top of the read and write to NBT functions has fixed the issue. I will not question it, I will just go with it and assume major-league B.S. Did I facedesk? You bet I did!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.