Posted July 7, 20223 yr 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?
July 7, 20223 yr 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 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.
July 7, 20223 yr Author I meant that a datapack whould be able to override it, similarly to how it can override a recipe
July 7, 20223 yr 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. 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.
July 7, 20223 yr 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, 20223 yr by Luis_ST
July 7, 20223 yr 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? 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.
July 7, 20223 yr Author 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.
July 7, 20223 yr 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
July 7, 20223 yr 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 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.
July 7, 20223 yr Author 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?
July 7, 20223 yr 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. 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.
July 7, 20223 yr 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. 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.
July 7, 20223 yr Author gamerules sound better actually. I have no idea how to register one though, and I don't really find anything on google regarding that
July 7, 20223 yr 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, 20223 yr by warjort 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.
July 7, 20223 yr Or there are helper methods on GamesRules that lets you do getBoolean(Key) instead of getRule(Key).get(). Edited July 7, 20223 yr by warjort 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.
July 7, 20223 yr Author vanilla gamerules use GameRules.IntegerValue.create(int value) which is package-private, I'll need to use reflection / AT Edited July 7, 20223 yr by MaiTheLord
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.