The setTagInfo() function.

Started by EnsurdFrndship on

Topic category: Help with MCreator software

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The setTagInfo() function.
Thu, 06/04/2020 - 13:44 (edited)

Hello,

     I just found the function... 

void net.minecraft.item.ItemStack.setTagInfo ( String  par1Str,
    NBTBase  par2NBTBase 
  )  

 

 

    for setting tags on items (such as 'written books'). I also found code examples on the lines needed to altar a 'written book'...

 

ItemStack tomeStack = new ItemStack(Item.writableBook);

NBTTagList bookPages = new NBTTagList("pages");

bookPages.appendTag(new NBTTagString("1", "Insert text here."));

bookPages.appendTag(new NBTTagString("2", "Insert moar text here."));

tomeStack.setTagInfo("pages", bookPages);

tomeStack.setTagInfo("author", new NBTTagString("author", "Author name here"));

tomeStack.setTagInfo("title", new NBTTagString("title", "Title here"));

tomeStack.itemID = Item.writtenBook.itemID;

 

   The only 'setback' now is that the NBTTagString subclass of NBTBase is not a recognized class. Somebody told me it had to do with the versions of Minecraft, but how would I find the 'newest version' of being able to assign the title, author and pages to 'written books'?... and why should newer versions of Minecraft allow developers less power for access to accomplish whatever they want to accomplish for their mods?

Edited by EnsurdFrndship on Thu, 06/04/2020 - 13:44
and why should newer…
Thu, 06/04/2020 - 14:06

and why should newer versions of Minecraft allow developers less power for access to accomplish whatever they want to accomplish for their mods?

They just renamed it, check CompoundNBT for the starting point. You can use MCreator's class search function in the project browser sidebar.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
  The only 'setback' now is…
Thu, 06/04/2020 - 14:11

  The only 'setback' now is that the NBTTagString subclass of NBTBase is not a recognized class. Somebody told me it had to do with the versions of Minecraft, but how would I find the 'newest version' of being able to assign the title, author and pages to 'written books'

You are going to need to do research to find the newer functions for these newer versions, if I knew these classes/sub-classes I would tell you (I don't). 

 and why should newer versions of Minecraft allow developers less power for access to accomplish whatever they want to accomplish for their mods?

That is not true lol, the developers don't go out of their way to make another person (us) life hell. If they do totally remove a file, it is to optimize the game. That being said, I don't think they removed this class. So my best advice for you is to research updated forums and maneuver in the Minecraft base files.

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you. I am only down to…
Thu, 06/04/2020 - 14:58

Thank you. I am only down to 1 error. I am using... 

 

				Map<Integer, String> wordsByKey = new HashMap<>();
				wordsByKey.put(1, "one");
				wordsByKey.put(2, "two");
				wordsByKey.put(3, "three");
				wordsByKey.put(4, "four");
				(new Object() {
					public ItemStack getItemStack(BlockPos pos, int sltid) {
						AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
						TileEntity _ent = world.getTileEntity(pos);
						if (_ent != null) {
							_ent.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> {
								_retval.set(capability.getStackInSlot(sltid).copy());
							});
						}
						return _retval.get();
					}
				}.getItemStack(new BlockPos((int) (x + (xval)), (int) (y + (yval)), (int) (z + (zval))), (int) (0))).setTagInfo(
						"pages",
						new CompoundNBT(wordsByKey));

and I am getting the error... 

        incompatible types: Map cannot be converted to Map new CompoundNBT(wordsByKey));

I am sending a variable of 'Map' as an argument to CompoundNBT(), but it can't seem to convert, even though they are of the same types???

 

 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can't convert Map…
Thu, 06/04/2020 - 15:06

You can't convert Map<Integer, String> to Map<String, INBT>

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I fied it...  CompoundNBT…
Thu, 06/04/2020 - 15:17

I fied it... 

CompoundNBT nbtTag = new CompoundNBT();
				nbtTag.putString("author", "Michael S. Lowe");
				nbtTag.putString("title", "Scripture");
				nbtTag.putString("pages", "This is page 1.");
				(new Object() {
					public ItemStack getItemStack(BlockPos pos, int sltid) {
						AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
						TileEntity _ent = world.getTileEntity(pos);
						if (_ent != null) {
							_ent.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> {
								_retval.set(capability.getStackInSlot(sltid).copy());
							});
						}
						return _retval.get();
					}
				}.getItemStack(new BlockPos((int) (x + (xval)), (int) (y + (yval)), (int) (z + (zval))), (int) (0))).setTagInfo(
						"pages",
						nbtTag);

I get no errors, but my books still say, "*Invalid book tag*" in them. I don't know if it is because I am not modifying my CompoundNBT (nbtTag) variable correctly.

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
    All I need to do now (to…
Thu, 06/04/2020 - 23:26

    All I need to do now (to finish my mod) is figure out how to set the CompoundNBT variable (value) properly and pass it on to the ItemStack.setTagInfo(java.lang.String key, NBTBase value)  function, to hopefully put the correct data into the 'written books' of my mod, and not have them all say, "*Invalid Book Tag*" when I open them in my game. 

      I Googled "CompoundNBT" for documentation, and Google thinks I am searching 2 words, "Compound NBT" even though I put it in quotes. Does anyone know how to use the CompoundNBT class variable for 'written books' in Minecraft? Thank you. I  saw an outdated code from 7 years ago...

ItemStack tomeStack = new ItemStack(Item.writableBook);
NBTTagList bookPages = new NBTTagList("pages");
bookPages.appendTag(new NBTTagString("1", "Insert text here."));
bookPages.appendTag(new NBTTagString("2", "Insert moar text here."));
tomeStack.setTagInfo("pages", bookPages);
tomeStack.setTagInfo("author", new NBTTagString("author", "Author name here"));
tomeStack.setTagInfo("title", new NBTTagString("title", "Title here"));
tomeStack.itemID = Item.writtenBook.itemID;

    ... so it shouldn't be impossible to create vanilla written books now (using CompoundNBT). 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Why not look in the…
Thu, 06/04/2020 - 23:32

Why not look in the CompoundNBT class 🤷‍♂️.

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did Google "CompoundNBT…
Thu, 06/04/2020 - 23:37

I did Google "CompoundNBT class", and only got information on something like NBTTagCompound, which is not the class I am trying to use.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What I meant was, find the…
Thu, 06/04/2020 - 23:40

What I meant was, find the declaration of the class (in Intellij it is ctrl+click). It wouldn't hurt to learn the methods and such. Good luck!

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
   Thank you. It is my first…
Fri, 06/05/2020 - 00:21

   Thank you. It is my first time working with Intellij. I downloaded it. It gives me a 30 day trial, and all I know it to do is 'create projects'. Ctrl+click seems to select multiple items I assume are in a newly created project (like it would do in File Explorer), but I am really not interested in creating new projects. I am just trying to find any kind of documentation I can find on the CompoundNBT class for assigning data to a written book. 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here, give me a second. I…
Fri, 06/05/2020 - 00:24

Here, give me a second. I will copy the entire class to you.

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
     In my code above, I am…
Fri, 06/05/2020 - 00:48

     In my code above, I am already using a variable of the CompactNBT class, but it seems like I am not using the variable's properties correctly because my books still say, "*Invalid Book Tag*" in them. I would just only need to know which tag(s) to set, and how.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I couldn't tell you. I will…
Fri, 06/05/2020 - 00:49

I couldn't tell you. I will do some research on my own to help

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so far, CompoundNBT nbtTag …
Fri, 06/05/2020 - 00:50

so far,

CompoundNBT nbtTag = new CompoundNBT();
nbtTag.putString("author", "Michael S. Lowe");
nbtTag.putString("title", "Scripture");
nbtTag.putString("pages", "This is page 1.");

is not working.