Jump to content

NBT help


vtsman

Recommended Posts

I'm not very good with nbt tags, so can someone tell me what I'm doing wrong. I'm trying to make my tile entity to store some values a liquid stack and an ItemStack. For testing reasons, I've omitted the liquidstack and itemstack.

Here's the nbt stuff

 

@Override

public void readFromNBT(NBTTagCompound data)

    {

        super.readFromNBT(data);

        this.setType(data.getString("Type"), data.getInteger("Radius"), data.getInteger("Capacity"));

    }

 

@Override

public void writeToNBT(NBTTagCompound data) {

super.writeToNBT(data);

data.setDouble("energy", this.energy);

 

 

data.setString("Type", this.type.getType());

data.setInteger("Radius", this.type.getRange());

data.setInteger("Capacity", this.type.getCapacity());

}

 

Link to comment
Share on other sites

It's just not saving or loading, no error.

 

It's because of a client-server disparity.

 

You need to send a datapacket to all players with the information.

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

Try adding something like this in your write to NBT data and wherever else you try to set NBT.

if (stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());

//insert NBT set thingies here
}

 

I know I had trouble whenever the stackTagCompound equaled null and I tried to read it the game would crash. I'm not sure if that's your problem, but it's worth a shot.

Link to comment
Share on other sites

game would crash

 

He is not having that problem and I know it is an unhelpful suggestion as the problem he is actually having I've dealt with before.  The client can't load the data values from the save (because it's a client) but the server isn't sending the info because he hasn't told it to.

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

it's even simpler than that, in my code i just do this:

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
	NBTTagCompound tag = pkt.customParam1;
	this.readFromNBT(tag);
}

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound tag = new NBTTagCompound();
	this.writeToNBT(tag);
	return new Packet132TileEntityData(xCoord, yCoord, zCoord, 0, tag);
}

 

just put that into your TileEntity class, this gets called every time the block is marked for an update and automatically passes it from the server to the client.

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.