Jump to content

Recommended Posts

Posted (edited)

I am trying to add conditions to my recipes based on values from my config file. I have gotten it to work for a single config value. I set the value to false, and the condition disables the recipe. I have a lot of recipes I'd like to handle this way, so I'd like to make my ICondition implementation more generic now, so I could pass in something that would tell it which config option to check. But I can't figure out how. Something roughly like this, I think:

  Reveal hidden contents

Each config option is a ForgeConfigSpec, and I found a function to look up the config options path, but I haven't found a way to do the reverse - given a path, get the value or maybe grab the corresponding ForgeConfigSpec so I can do ForgeConfigSpec#get.

Another idea I found is to create a manual Map or maybe an enum to associate a String with each relevant config option. Then I could pass in the String to look up the appropriate config option. But that just feels like a lot of extra work and manual maintenance

Edited by Daeruin
Fill out title
  • Daeruin changed the title to [1.18.2] ICondition to look up config values
Posted

Well, I think it's easier for users to type "false" into a config file than create a datapack. But also my mod is modular. If the user doesn't want to use a certain part of my mod, they can disable it, and it affects multiple things. I need to stop certain items from dropping when blocks are broken in addition to disabling various recipes. It doesn't make sense to me to make the user create a datapack to fully disable this part of my mod.

Posted

You may need to (re)read my original post to see more about what I'm trying to do. I have the process working for a single "module" but would like to make it more generic so I don't have to create a whole bunch of IConditions for all the modules. With how conditions work in data generation, I'm not sure how to achieve that.

Posted

Don't you have your config as a singleton in your mod for use at runtime?

You could just make your ICondition implementation reference a map like you say, except it would be a map of strings to "getters" for your config.

Something like:

public class MyMod {
    public static YourConfig configSingleton;
    public static final Map<String, BooleanSupplier> conditions = new HashMap<>();
    static {
       conditions.put("option1", configSingleton::isOption1);
       conditions.put("option2", () -> somethingMoreComplicated());
    }
}

Maybe I am misunderstanding the problem?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
  On 6/30/2022 at 7:14 PM, warjort said:

Don't you have your config as a singleton in your mod for use at runtime?

Maybe I am misunderstanding the problem?

Expand  

Yeah, something like you suggested would work. I just thought that maybe I could use some existing methods from Forge's existing config code instead of making a manual map. I poked around for a while, couldn't figure out anything elegant, and finally figured I'd ask for ideas.

Eventually I figured it out. My ICondition class takes a ForgeConfigSpec.Boolean parameter, so I can pass in a config option and save it as a field in ICondition. I can then reference it directly in the ICondition#test method.

  Reveal hidden contents

In my Serializer, I write that to JSON by using ConfigValue#getPath and turning the resulting list into a period separated string. I deserialize the period separated string using ForgeConfigSpec#getValues#get which returns the same ForgeConfigSpec.Boolean.

  Reveal hidden contents

The thing I like about this solution is that I can now use data generation to make any recipe conditional on my config without manually updating some map. So my instinct was right, I just got frustrated too early and posted here hoping someone had already solved this kind of issue. I guess with datapacks people aren't doing as much of this kind of thing anymore.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Recovering stolen Bitcoin can feel like an insurmountable challenge, especially after falling victim to scams that promise high returns with little investment. My journey began with excitement when I first learned about Bitcoin mining pools. The idea of earning substantial profits from a modest investment was enticing. I was encouraged to invest $5,200, and soon found myself caught in a web of endless demands for more money to access my funds. As time went on, I paid out hundreds of thousands of dollars, believing that each payment would finally unlock my investments. However, the requests never ceased, and I soon realized I was trapped in a scam. The weight of losing $826,000 worth of Bitcoin was unbearable, and I felt utterly helpless. I reached out to authorities, but their responses were disheartening, leaving me feeling even more isolated in my struggle. In my desperation, I even went to pray, seeking guidance and hope in what felt like a hopeless situation. I poured my heart out, asking for a sign or a way to recover my lost funds. It was during this time of reflection that I began searching for solutions online, hoping to find a way to recover my investments. That’s when I stumbled upon RAPID DIGITAL RECOVERY. At first, I was cynical after all, I had already been deceived so many times. However, I decided to reach out and share my story. The team at RAPID DIGITAL RECOVERY was understanding and compassionate, assuring me they had the expertise to help me recover my stolen Bitcoin. Within hours of providing them with the necessary information, I began to see progress. They guided me through the recovery process, keeping me informed every step of the way. It was surreal to watch as they worked diligently to trace my funds and navigate the complexities of the blockchain. To my astonishment, I received confirmation that my Bitcoin had been successfully recovered. The relief and joy I felt were indescribable. I had almost given up hope, but RAPID DIGITAL RECOVERY proved to be the lifeline I desperately needed. If you find yourself in a similar situation, I urge you to seek help from Reputable team at RAPID DIGITAL RECOVERY.  
    • https://mclo.gs/9Byd16j Hi, I've had my BetterMC world for a couple days now (1.19.2 vers & Fabric loader) but recently whenever I try to open the profile the minecraft launcher crashes and provides this error code. I've checked both this forum and google and haven't found any similar problems or solution to my problem. I'm not the best at reading crash logs but I gathered that there's an issue with fabric possibly, so I re-downloaded the same one on the modpack, then the latest version for 1.19.2 fabric and the issue still occurred. What can I do now?
    • it works now but idk why lmao. i removed terrablender and it didnt work. i then left it for a couple of days and, when i came back, updated the mods that needed updating because "what's the worst that could happen". i then tried launching it and now it works. i genuenly have no clue what i did to make it work, othen than updating the mods. so, thanks for your help
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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