Squidsword Posted January 6, 2023 Posted January 6, 2023 (edited) Hey, I have a mod that adds a couple of new ores. For 1.19.3, I had to move over the logic to JSON files. I want the user to be able to change values such as rarity and vein size and have the JSON file change. Right now, though, all of the JSON files are stuck with the default config values and don't change. The simplest approach I came up with was updating all the JSON files with the configured values right after startup. I tried look at the docs, but I am still not sure how to access and modify the configured and placed feature JSON data on runtime. Do I need to use codecs? I'd appreciate any tips or alternative approaches. Thanks! Edited January 6, 2023 by Squidsword clarification about what I'm asking for Quote
Naamah Posted January 6, 2023 Posted January 6, 2023 (edited) Are you trying to have the values changed on startup or when the game/server is already started? Couldn't you just change the values and then restart the game/server to have them updated? Edited January 6, 2023 by Naamah Quote Not even gonna lie, I think I have autism
Squidsword Posted January 7, 2023 Author Posted January 7, 2023 (edited) I want to, but I'm not sure how to change the values. Right now, the JSON data is a static copy of the default values and it's not linked to the config in any way. I want to be able to programmatically adjust the JSON files containing the world generation data based on what people set their config to. So, the static copies of the default values are here: configured and placed features There are values like: "discard_chance_on_air_exposure": 0.5, Let's say the user wants the discard chance to be 0.8, so in my mods config file they set it to 0.8. I need to grab that value from the config and relay it over to change it to "discard_chance_on_air_exposure": 0.8, Edited January 7, 2023 by Squidsword link Quote
warjort Posted January 7, 2023 Posted January 7, 2023 Those json files are configuration files. If the user wants to modify them they can use a datapack. If you really want to continue to do this, just search this forum. This pointless "anti-pattern" has been discussed many times before in various forms. Configuration files for configuration files? 🙂 Quote 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.
Squidsword Posted January 7, 2023 Author Posted January 7, 2023 Quote If you really want to continue to do this, just search this forum. I've searched "Editing JSON file during runtime" and "Editing datapack" and I don't seem to get any relevant results. I don't have much experience with terminology, so I'm not exactly sure what keywords to look up. Do you have a link to the relevant threads? Quote Configuration files for configuration files? 🙂 I get what you are saying, but I don't want to put the burden on the user. Especially for my mod, since it's not as simple as just plugging in the values they want into a datapack. Right now, my code will take the rarity that the user sets and generate 3 different placed features that, when summed up, will approximate the rarity they picked. I have the conversion logic in my java code. Before 1.19.3, all the users had to do was set my ore to be say 5x rarer than diamonds, and I could handle the rest of the logic programmatically. I don't want them to have to make 3 different data files and manually compute what values each json file needs to have just to do the same thing. I feel like programmatically setting the JSON values is the only approach to avoid this. Unless you have another approach? Quote
warjort Posted January 7, 2023 Posted January 7, 2023 I assume you are talking about the "count" placement modifier? Typically placed features are configured with multiple placement modifiers one of which is some form "count". You can write your own PlacementModifier (and register it) that takes its value(s) from your configuration file instead of the numbers in the json file. In 1.19.3 Registries.PLACEMENT_MODIFER_TYPE is the registry key. This approach does at least mean if the end user/mod pack developer doesn't like your way of configuring the ore generation they can create a datapack and replace your placement modifier with their own. Which is Mojang's intended way to do it. Quote 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.
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.