Kinniken Posted May 13, 2018 Share Posted May 13, 2018 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 Quote http://www.millenaire.org/img/dynamicsig.png[/img] Link to comment Share on other sites More sharing options...
jabelar Posted May 13, 2018 Share Posted May 13, 2018 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. 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Laike_Endaril Posted February 6, 2019 Share Posted February 6, 2019 (edited) I actually just started looking into this as well. I'll keep this open in a tab and go check the vanilla classes first as suggested. Egad, somehow I misread the last post date on this thread; sorry about that. Edited February 6, 2019 by Laike_Endaril Quote Link to comment Share on other sites More sharing options...
Kinniken Posted February 7, 2019 Author Share Posted February 7, 2019 I never properly looked into this, I had other priorities that took over. If you find a good way to do it I'd be glad to have some feedback! Thanks Quote http://www.millenaire.org/img/dynamicsig.png[/img] Link to comment Share on other sites More sharing options...
Cadiboo Posted February 7, 2019 Share Posted February 7, 2019 I don’t think there’s any way to decide what parts of the NBT are “important” and which parts arent Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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 More sharing options...
Kinniken Posted February 7, 2019 Author Share Posted February 7, 2019 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. Quote http://www.millenaire.org/img/dynamicsig.png[/img] Link to comment Share on other sites More sharing options...
Laike_Endaril Posted February 8, 2019 Share Posted February 8, 2019 (edited) 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 February 8, 2019 by Laike_Endaril Quote Link to comment Share on other sites More sharing options...
Cadiboo Posted February 8, 2019 Share Posted February 8, 2019 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 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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 More sharing options...
Laike_Endaril Posted February 8, 2019 Share Posted February 8, 2019 Nice, I may end up going with this approach, though it will probably take me some time to hammer out the system Quote Link to comment Share on other sites More sharing options...
Laike_Endaril Posted February 8, 2019 Share Posted February 8, 2019 (edited) 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 February 8, 2019 by Laike_Endaril Formatting Quote Link to comment Share on other sites More sharing options...
JaredBGreat Posted February 8, 2019 Share Posted February 8, 2019 It never occurred to me to do this, so I ended up writing an elaborate (and fragile) system for loading NBT. Then someone called Hubry came along and added in this simpler system. It seems the meat of this system is in one line: out = new NBTFromJsonWrapper(tokens.getToken(0), s[2]); Quote Developer of Doomlike Dungeons. Link to comment Share on other sites More sharing options...
Laike_Endaril Posted February 8, 2019 Share Posted February 8, 2019 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. Quote Link to comment Share on other sites More sharing options...
Kinniken Posted February 8, 2019 Author Share Posted February 8, 2019 My case is a little different, it's not for user config but for setting up my mod's data. So indeed config files are perfectly viable. Quote http://www.millenaire.org/img/dynamicsig.png[/img] Link to comment Share on other sites More sharing options...
Laike_Endaril Posted February 9, 2019 Share Posted February 9, 2019 (edited) 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 February 9, 2019 by Laike_Endaril Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.