Jump to content

[1.15.2] Changing ForgeConfigSpec values in game.


Squidsword

Recommended Posts

Hey guys, I am trying to send a packet to the client when he enters the server to update his config files. In 1.12.2 it was rather easy with the @Config annotation, however I am having difficulty finding ways to change ForgeConfigSpec values in the packet handler I just made. I am a new programmer and I am not really sure of the most efficient way to do so. 

    final ForgeConfigSpec.BooleanValue overworld_ores;
    final ForgeConfigSpec.BooleanValue nether_ores;
    final ForgeConfigSpec.BooleanValue end_ores;
    
    ServerConfig(final ForgeConfigSpec.Builder builder) {
        
        builder.comment("Note that almost all config changes require a server restart. Dimensional Ore Configuration").push("dimensional_ore");
        
        overworld_ores = builder
                .comment("Spawn ores in the overworld? Default = true")
                .define("overworld_ores", true);
        
        nether_ores = builder
                .comment("Spawn ores in the nether? Default = false")
                .define("nether_ores", false);
        
        end_ores = builder
                .comment("Spawn ores in the end? Default = false")
                .define("end_ores", false);



        builder.pop();

}

 

Here's a snippet of the way I created the values. It writes the default value in the config value, but how do I set the value to something other than the default without manually going to the .toml file and rewriting new ones? Is there any way to do it within the code? Thanks for any help.

 

Link to comment
Share on other sites

I do want the user to be able to customize their own config values as normal. For more details, when the player joins a minecraft server with the mod enabled, I want the client config to change to the servers values so the player can see the changes the server has made. I have config values that can change the damage and armor values of the items in my mod (which a minecraft restart to take effect or so I believe). I'm not sure if there is a simpler way to do this other than sending a packet and changing the values using the packet message. The problem I'm not sure how to change it from within the packet handler because I'm not sure how to set the values from within the code.

Quote

Just create a temporary variable for testing purposes and change it to the config version once you have finished.

I am not sure what you mean by change it to the config version, do you mean set the default value to the packet values from the server in the ForgeConfigSpec builder .define method?

Link to comment
Share on other sites

10 minutes ago, Squidsword said:

do you mean set the default value to the packet values from the server in the ForgeConfigSpec builder .define method?

I was saying that originally because I misunderstood your original intention. So, let's address it. If I understand this right, you want the dedicated server config to match the users own personal config file?

 

I'm not sure why you would need to send a packet from server to client to recognize the change. My understanding of the config file is based in logical sides. There are two kinds of servers: IntegratedServer and DedicatedServer. The server uses the config file adjusted for common and server based code ignoring client (for obvious reasons). The need for updating the specific user is irrelevant since data such as what you are describing would be handled on the server side. If there is something that needs to require Minecraft to restart, then you would need to restart minecraft again to change them. You would need some instance of reflection to override that. Moreover, code would be handled by the server itself leaving only rendering details to be handled by the client making the whole point of a packet update seem quite useless especially since they're final values.

 

I would recommend testing your mod using a server with a different configuration than the user and test it and see what results. If my understanding of config files is right, the server should reign over the user on a multiplayer world and only in a singleplayer world would the user's config be needed.

Link to comment
Share on other sites

You're absolutely right, the config file on the server side will still take effect on all the clients. The only problem is that the players can't see some of the changes in their HUD since their own config file is different. The packet is for a client-side only change that will update the HUDs of the items by registering the proper config values so they will render properly after the restart, as you already said. I am not familiar with how ForgeConfigSpec works or how to change the file values in an efficient way, so I'm having a problem actually changing the values within the code itself.

Link to comment
Share on other sites

1 hour ago, Squidsword said:

The only problem is that the players can't see some of the changes in their HUD since their own config file is different

Then yes, you would sync those values in a packet, except you're not changing the config variables. You're storing the result in wherever you are using the HUD. Basically, when turning on the hud, send a packet to the client from the server side containing the variables stored in the config. Then, store those values inside the HUD to be rendered. This way you are getting the variables from the server rather than the client. That's how I see it anyways.

  • Thanks 1
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.



×
×
  • Create New...

Important Information

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