Jump to content

[1.10.2] Just another NBT read/write problem


Zootaxz

Recommended Posts

Hey,

 

some time ago ive started with modding in 1.7.

Now.. some months/years? later ill want to continue with 1.10.2.

 

Something changed .. but i want to use my existing "core"-classes,

which are written in 1.7.

With some changes everything works fine, but .. some of these changed are weird and confuse me.

 

I've started with a new tileentity and some gui stuff.

The problem is, if i code like i learned in 1.7, my gui does nothing (e.g. no progressbar).

 

---

 

readFromNBT gets called before writeToNBT:

The method call readFromNBT overrides the initial-values of my class attributes which are set in constructor.

I changed the readFromNBT: read only if the key exists in compound.

In 1.7 (i tried it) the writeFromNBT gets called before readFromNBT.

 

Now.. is it possible that my "base"-nbt methods in 1.10.2 are wrong?

@Override
public SPacketUpdateTileEntity getUpdatePacket () {
	// Sorry, ive added these in 1.10.2 .. do i need them?
                //NBTTagCompound nbtTag = new NBTTagCompound();
	//writeToNBT(nbtTag);
	return new SPacketUpdateTileEntity(this.pos, getBlockMetadata(), getUpdateTag());
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
	if(net.getDirection() == EnumPacketDirection.CLIENTBOUND){
		readFromNBT(pkt.getNbtCompound());
	}
}

 

Or in one of my base tileentities (TileEntityMachine) i need to comment some code out.. because it still not exists in 1.10:

@Override
public void update() {

	if (this.worldObj.isRemote)
		return;

	//if (this.hasWorldObj())
	//	this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

}

 

the "this.worldObj.isRemote .. return" only if there is no gui data in this class or?

 

If i should post my whole code.. ask.. buts its incomplete and wont confuse you with this :)

 

Thanks

 

 

 

Link to comment
Share on other sites

update method is added by the interface ITickable and your getUpdatePacket and onDataPacket looks fine.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Hi

 

TileEntities now need four methods to synchronise client<-->server

 

For example

 

	// When the world loads from disk, the server needs to send the TileEntity information to the client
//  it uses getUpdatePacket(), getUpdateTag(), onDataPacket(), and handleUpdateTag() to do this:
  //  getUpdatePacket() and onDataPacket() are used for one-at-a-time TileEntity updates
  //  getUpdateTag() and handleUpdateTag() are used by vanilla to collate together into a single chunk update packet
//  Not really required for this example since we only use the timer on the client, but included anyway for illustration
@Override
  @Nullable
  public SPacketUpdateTileEntity getUpdatePacket()
  {
	NBTTagCompound nbtTagCompound = new NBTTagCompound();
	writeToNBT(nbtTagCompound);
	int metadata = getBlockMetadata();
	return new SPacketUpdateTileEntity(this.pos, metadata, nbtTagCompound);
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	readFromNBT(pkt.getNbtCompound());
}

  /* Creates a tag containing the TileEntity information, used by vanilla to transmit from server to client
*/
  @Override
  public NBTTagCompound getUpdateTag()
  {
    NBTTagCompound nbtTagCompound = new NBTTagCompound();
    writeToNBT(nbtTagCompound);
    return nbtTagCompound;
  }

  /* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client
*/
  @Override
  public void handleUpdateTag(NBTTagCompound tag)
  {
    this.readFromNBT(tag);
  }

 

That might be contributing to your problem.

 

You can find a working example of TileEntities and GUI (Furnaces, chests) in this tutorial project

https://github.com/TheGreyGhost/MinecraftByExample/tree/master

see mbe20, mbe30, mbe31

 

-TGG

 

 

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.