Jump to content

[1.12.2] Easy way of storing NBT data in config files?


Kinniken

Recommended Posts

Hi all,

 

I need to define items in external config files for reference in my mod's content files. Until now I've done this simply enough in the following way:

 

wool_black;minecraft:wool;15
wool_blue;minecraft:wool;11
wool_brown;minecraft:wool;12
wool_cyan;minecraft:wool;9
wool_gray;minecraft:wool;7
wool_green;minecraft:wool;13

 

Where the first value is an internal name for my mod and the next values are the Minecraft item name and the meta value. Works very well except for items dependent on item-stack level NBT data. Is there any way of storing (simple) NBT data in single-line string format that I could use rather than code mine? Obviously not for really complicated data structure, but say to store the data needed to define a potion for example?

 

Thanks

Link to comment
Share on other sites

There are a number of classes such as the JsonToNBT, the CompressedStreamTools, and even methods in the NBTBase class that deal with various approaches to serialization of NBT. I haven't used them myself, but I assume they are close to what you're looking for. Just check out how they are used in vanilla.

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

  • 8 months later...

I don’t think there’s any way to decide what parts of the NBT are “important” and which parts arent

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

In my case I'm not planning that, I just meant that I was looking for a way to store "small" NBT data, like the data necessary to define a potion or en enchanted item, not "large" NBT data like the content of a chest etc. Something that could plausibly be put in a config file on a single line.

Link to comment
Share on other sites

Aye, my goal is the same (to allow users to specify items with nbt in a config String array input).

 

Alternatively, if there is a good way to do something similar with submenus (categories), that would be even better for my case, as I could allow them to add an entry, which would be a new config button, which they could then click on...and then inside the dynamically-created config menu it sends them to I would have a field for the base item name/meta, a string array input for multiple nbt tags, etc, etc.  I don't think this is really a thing or I'd think I would've seen it by now, but I could be wrong.

 

Back to the NBT, it's difficult to decide how to implement it in order to strike a balance between complexity and flexibility for the end-user.  I'm trying to avoid external JSON files because I feel many users would be put-off by them.  At the same time though, doing a full JSON-format NBT compound in a one-line string input field can get confusing without using an external text editor to write it out first.  I started writing my own syntax for a simplified input that just uses tiered string splitting, but even that got very complicated to put entries into...being able to split the entry into multiple different input fields would be ideal, but I need an unknown number of them, thus the want of a config array input.  Is that a thing?

 

Edit: I suppose I could accomplish this by writing my own GUI, but I would want to link access to my GUI to the normal forge mod config menu if I did, and I'm not sure how that would be done either.

Edited by Laike_Endaril
Link to comment
Share on other sites

1 hour ago, Laike_Endaril said:

but I would want to link access to my GUI to the normal forge mod config menu if I did, and I'm not sure how that would be done either.

Extend GuiConfig and pass the name of the class to guiClassName in @Mod

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

3 hours ago, Cadiboo said:

pass the name of the class to guiClassName in @Mod


I've unfortunately been unable to figure this out.  I had assumed it would be doable in the @Mod tag of the main mod class, but the only gui related thing in there seems to be guiFactory.

I tried messing with the guiFactory argument in the @Mod tag since I had stumbled upon it, and ended up with this so far:

 

@Mod(modid = DynamicStealth.MODID, name = DynamicStealth.NAME, version = DynamicStealth.VERSION, guiFactory = "com.fantasticsource.dynamicstealth.config.DynamicStealthConfigFactory")

 

...and...

 

package com.fantasticsource.dynamicstealth.config;

import com.fantasticsource.dynamicstealth.common.DynamicStealth;
import net.minecraftforge.fml.client.DefaultGuiFactory;

public class DynamicStealthConfigFactory extends DefaultGuiFactory
{
    public DynamicStealthConfigFactory()
    {
        super(DynamicStealth.MODID, DynamicStealth.NAME);
    }
}

 

Which does work...it loads the same config files as usual, and everything works as expected.  Next I'll try overriding createConfigGui and having it return an instance of a custom class extending GuiConfig and see where that gets me.

Side note: I tried making the above class in a general-use context at first, but even though DefaultGuiFactory uses a 2-argument constructor, it seems if you define your own guiFactory in the @Mod tag, it only searches for a 0-argument constructor.  Maybe there is some syntax that can be used in the @Mod reference to make it look for a constructor with arguments, bug I haven't the slightest idea how that would be structured if there is.


In any case, this possible solution is going to be far more...adventurous...than I would've hoped, if it ends up working, and certainly goes far beyond a "simple" solution for specifying items with NBT in your config in a reasonable manner.  Nonetheless I'll try to get it working in as general a way as possible and if I manage it, will post the code.

Edited by Laike_Endaril
Formatting
Link to comment
Share on other sites

In my case, I'm trying to avoid external files, though that may be viable for Kinniken?  I'm not sure.

 

In my particular case, I'm attempting to allow users to enter an item with many properties attached to it without the entry getting complex, so I basically need to split it into multiple inputs.  I also want the user to be able to enter any number of items this way, all without having to edit an external file, so for now I'll continue trying to manipulate the config menu itself with the goal of making what basically amounts to a category array.

Link to comment
Share on other sites

After a couple days messing with it, I've decided to cave in and use a normal String[] config with a token parse...so I'm currently writing code for that approach.

 

Edit: My code is working.  I've tried to make it a bit simpler than a normal NBT string so I did my own parsing, which means the code itself is much more complex than it would otherwise be, but hopefully it makes things a bit easier on the user...we'll see.

 

Will only post link to code if someone requests it; it is likely more complex than most would want to look at for what it does

Edited by Laike_Endaril
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.