Jump to content

[1.14.3] [Solved] Replacement for NBTTagCompound#setTag?


Recommended Posts

In previous versions of Minecraft (1.13-), I was able to create an NBTTagCompound and then run .setTag on the EntityData to set my compound to the entity. However, in 1.14, it appears this is different. How do I set a compound tag to the entity data via NBT?

Old code:
 

public void saveToPlayer(EntityPlayer player) {
  NBTTagCompound tag = new NBTTagCompound();
  tag.setByte("minHealth", this.defHealth);
  tag.setDouble("modifier", this.modifier);
  tag.setByte("heartContainers", this.heartContainers);
  tag.setShort("levelRampPosition", this.levelRampPosition);
  player.getEntityData().setTag(LevelHearts.NBT_ID, tag);
}

 

New (attempt) code:
 

public void saveToPlayer(PlayerEntity player) {
  CompoundNBT tag = new CompoundNBT();
  tag.putByte("minHealth", this.defHealth);
  tag.putDouble("modifier", this.modifier);
  tag.putByte("heartContainers", this.heartContainers);
  tag.putShort("levelRampPosition", this.levelRampPosition);
  player.getEntityData().setTag(LevelHearts.NBT_ID, tag); // There is no "setTag" option here, what do I do?
}

 

I am on my journey of making a remake of matmos, as explained here.

Link to comment
Share on other sites

  • FireController1847 changed the title to [1.14.3] Replacement for NBTTagCompound#setTag?
Just now, diesieben07 said:

For a start, do not use getEntityData. Use capabilities.

 

The method you want has been replaced by put. You could have easily found this out yourself by looking at the code for 2 seconds.

My apologies, I was looking within the code but somehow happened to miss this entirely. So sorry, thanks!

I am on my journey of making a remake of matmos, as explained here.

Link to comment
Share on other sites

  • FireController1847 changed the title to [1.14.3] [Solved] Replacement for NBTTagCompound#setTag?

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.