Topic category: Help with MCreator software
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?
They just renamed it, check CompoundNBT for the starting point. You can use MCreator's class search function in the project browser sidebar.
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).
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.
Thank you. I am only down to 1 error. I am using...
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???
You can't convert Map<Integer, String> to Map<String, INBT>
I fied it...
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.
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...
... so it shouldn't be impossible to create vanilla written books now (using CompoundNBT).
Why not look in the CompoundNBT class 🤷♂️.
I did Google "CompoundNBT class", and only got information on something like NBTTagCompound, which is not the class I am trying to use.
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!
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.
Here, give me a second. I will copy the entire class to you.
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.
I couldn't tell you. I will do some research on my own to help
so far,
is not working.