Jump to content

Recommended Posts

Posted (edited)

I've been stuck on this for a while now, so how do I obtain a String of a ForgeConfigSpec (and is that even the correct class to use?).

Now the issue is that the exact path of the String is not known at compile time and will be only known to the runtime after the config has been built via the ForgeConfigSpec.Builder, this also removes the possibility from using the builder to obtain the instances. Since the ForgeConfigSpec has getByte, getInt, getEnum, etc. methods I doubt that there is anything that would hinder me from obtaining a String of it, however a getString method is missing and using getRaw or getOrDefault throw a ClassCastException since the get, getRaw and getOrElse methods don't return T (so String in my case) but from some reason return ForgeConfigSpec.ValueSpec. However ValueSpec is pretty useless for me since that also doesn't have the needed methods to convert it's content to a String (#get(null) or #get("") could be one, but I won't attempt that since that would be super strange if it were to work).

 

So how do I actually obtain a String?

Edited by Geolykt
Posted

Have you looked at how Forge does its configs?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

Look for the ForgeConfig class

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

Unfortunately it appears to not be what I am looking for and just reinforces my opinion that I should use a non-forge library and even non-toml language instead.

Now of course I could use integer identifies instead, however it would still mean that I have somewhere around 360 references to unused variables, or make use of two configurations and some unsightly tricks.

I basically currently have a

bots:
  - host: localhost
    user: Username
    nick: Nickname
  - host: localhost
    user: botV2
    nick: AnotherBot

configuration in yaml (well, it's a bit bigger, around 40 variables per bot), porting it to TOML is kindof difficult since TOML doesn't have a notion of arrays. As such I have thought to just index these via the username, which is why I cannot make use of the builder to obtain an instance

Posted (edited)

Update to the issue (for future users) It appears that using ForgeConfigSpec#getValues(), which returns a UnmodifiableConfig, which can then be used instead of the ForgeConfigSpec.

Now, instead of using the returns as is, you'd need to cast the returns to ConfigValue<String> (although String can be replaced with every other Object you want to have) and then invoke the get method on it to get the actual values of the ForgeConfigSpec. It's honestly a bit of a strange way of accessing the values, but at least makes some sense.

Hopefully that will be clarified in the javadocs someday.

Edited by Geolykt
removed accidental emoji
Posted

Do you not see the public static fields in ForgeConfig that are holding the config instances, and the public fields in those config instances you can .get()?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

Yeah I see it clear as day, but these are exactly what I CANNOT use. I CANNOT make use of the builder to obtain these values as it would require the contents of the config to be known at build time (however it isn't and would throw an exception - I think (wouldn't make sense otherwise)) or that I guess the indexes (which can be done via numeric indexes - no biggie there), which would result in unused instances (that will not be automatically GC-ed - so you'd need to write code to remove it).

Basically, I CANNOT make use of the builder to obtain the values, but only make use of the ForgeConfigSpec.

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.