MaiTheLord Posted July 7, 2022 Share Posted July 7, 2022 I want to store a constant integer in a json file under "resources/data/modid", so that it could be manipulated by datapacks. how do I achieve that? Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 What do you mean by manipulated by datapacks? To answer your question directly: To include any file in your mod, just put it in your src/main/resources 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. Link to comment Share on other sites More sharing options...
MaiTheLord Posted July 7, 2022 Author Share Posted July 7, 2022 I meant that a datapack whould be able to override it, similarly to how it can override a recipe Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 Why wouldn't you do this with a config option? Datapacks are normally used to load registries and then let users override the individual entries. 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. Link to comment Share on other sites More sharing options...
Luis_ST Posted July 7, 2022 Share Posted July 7, 2022 (edited) 40 minutes ago, warjort said: Why wouldn't you do this with a config option? Datapacks are normally used to load registries and then let users override the individual entries. A config file is only editable for the user (it's hard to edit the config file of a Mod from another), if a other Mod want to override a value a Datapack would be the best option And in general Datapacks are underrated, I think they have a lot of potential because of Mojnag's Codecs 1 hour ago, MaiTheLord said: I want to store a constant integer in a json file under "resources/data/modid", so that it could be manipulated by datapacks. how do I achieve that? unfortunately i'm not familiar with this json Datapack stuff, but as far as i know did you need a SimpleJsonResourceReloadListener which you need to register in AddReloadListenerEvent Edited July 7, 2022 by Luis_ST Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 I am just wondering if all the extra effort is appropriate? To do it, you need a PreparableReloadListener implementation. Then you register it using an AddReloadListenerEvent. The listener works in 2 stages prepare - which is run in parallel with other listeners apply - where the listeners are done one-by-one but only if all other listeners don't error in the prepare - this is where you modify your state You can only look at data loaded by other listeners in the apply, and then only if it runs before yours If you look at the vanilla ones, you can find some helpers that do common tasks - these will remove some of the complications. I don't think you will find one that does exactly what you are doing? 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. Link to comment Share on other sites More sharing options...
MaiTheLord Posted July 7, 2022 Author Share Posted July 7, 2022 I'll try using a config for now. I am not sure if it should be a common or a server config. the value affects entity spawning. Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted July 7, 2022 Share Posted July 7, 2022 if your value is server side and should be synced to the client you need use a server config (server and client value need to match), if the server value must not match with the client value you can use a common config Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 It depends where you need to access the config and who should control it. Usually common is used, even if the client never references it. https://forge.gemwire.uk/wiki/Configs 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. Link to comment Share on other sites More sharing options...
MaiTheLord Posted July 7, 2022 Author Share Posted July 7, 2022 As it affects entity spawning, I am not sure the user would want the same value in all of their worlds. should I use a server config then? Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 Could be? If this is the case, it would be another reason not to use datapacks. Only the worldgen is stored per world using the datapack values when you create 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. Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 Quote As it affects entity spawning, I am not sure the user would want the same value in all of their worlds. Another option would be a game rule. These are stored per world. 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. Link to comment Share on other sites More sharing options...
MaiTheLord Posted July 7, 2022 Author Share Posted July 7, 2022 gamerules sound better actually. I have no idea how to register one though, and I don't really find anything on google regarding that Quote Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 (edited) I have never done this either, but it looks pretty simple. Look at net.minecraft.world.level.GameRules which has vanilla examples. You just register() to set the default game rule, which will give you a GameRule.Key Then use Level.getGameRules().getRule(Key) at runtime. Edited July 7, 2022 by warjort 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. Link to comment Share on other sites More sharing options...
warjort Posted July 7, 2022 Share Posted July 7, 2022 (edited) Or there are helper methods on GamesRules that lets you do getBoolean(Key) instead of getRule(Key).get(). Edited July 7, 2022 by warjort 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. Link to comment Share on other sites More sharing options...
MaiTheLord Posted July 7, 2022 Author Share Posted July 7, 2022 (edited) vanilla gamerules use GameRules.IntegerValue.create(int value) which is package-private, I'll need to use reflection / AT Edited July 7, 2022 by MaiTheLord 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.