Jump to content

FluidTank NBT not saving


chbachman

Recommended Posts

I have read so many of the posts where people just stick the two lines of code that they think are causing the problem, and tell others to fix it. I am sorry if this comes off as one of those posts, but i am using code borrowed from build craft for saving the nbt of my tank and it is not working, and i cannot figure out why, because it traces back to code from KingLemming.

 

 

This is my nbt saving code:

 

the class extends the FluidTank class

 

@Override

public final NBTTagCompound writeToNBT(NBTTagCompound nbt) {

NBTTagCompound tankData = new NBTTagCompound();

super.writeToNBT(tankData);

this.writeTankToNBT(tankData);

nbt.setCompoundTag(this.name, tankData);

return nbt;

}

 

@Override

public final FluidTank readFromNBT(NBTTagCompound nbt) {

if (nbt.hasKey(this.name)) {

NBTTagCompound tankData = nbt.getCompoundTag(this.name);

super.readFromNBT(tankData);

this.readTankFromNBT(tankData);

}

return this;

}

 

 

public void writeTankToNBT(NBTTagCompound nbt) {

 

}

 

public void readTankFromNBT(NBTTagCompound nbt) {

 

}

 

Thank you for your time.

 

Link to comment
Share on other sites

@Override

  public final NBTTagCompound writeToNBT(NBTTagCompound nbt) {

      NBTTagCompound tankData = new NBTTagCompound();

      super.writeToNBT(tankData);

      this.writeTankToNBT(tankData);

      nbt.setCompoundTag(this.name, tankData);

      return nbt;

  }

 

Woah.  Slow down.

 

First, you've unneccessarily duplicated your functions.  You shouldn't need the

 this.writeTankToNBT(tankData);

part at all (not to mention that that function is empty and does nothing).

Second, you've marked that function as final.  You don't need that.  In fact, probably shouldn't have it.

 

I have half a mind saying that because you marked it as final, the function signature changed and it's no longer overriding.  Though my other half says not.  Either way, you don't need it.

 

Third, don't use

this.name

as a key...you can't be sure that that name won't change between a save and a load...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

ok i fixed up the method, but the nbt is still not saving. I am sorry for asking, but i have been trying to figure this out for a week.

 

Here is the total source code:

https://github.com/chbachman/ModularStorage

with the relevant code here (i think):

https://github.com/chbachman/ModularStorage/blob/master/common/io/github/chbachman/fluid/Tank.java

and here:

https://github.com/chbachman/ModularStorage/blob/master/common/io/github/chbachman/blocks/modulartank/TileModularTank.java

 

Thank you for your help

 

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.