Jump to content

Storing constant data in a json file


MaiTheLord

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Luis_ST
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 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.

Link to comment
Share on other sites

Or there are helper methods on GamesRules that lets you do getBoolean(Key) instead of getRule(Key).get().

Edited 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.

Link to comment
Share on other sites

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.