Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Configuration sync with server
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
SirWindfield

Configuration sync with server

By SirWindfield, January 13, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

SirWindfield    0

SirWindfield

SirWindfield    0

  • Tree Puncher
  • SirWindfield
  • Members
  • 0
  • 10 posts
Posted January 13, 2018 (edited)

I craeted a configuration file using the new 1.12 annotations offered by forge (@Config). Now I wanted to implement config syncing between client and server. Searching for some time lead to to the following posts here on this forum:

1) 

2) 

As /u/diesieben07 (@diesieben07) mentioned in the second link, the best way is to store the configs both on client side and use the server side config if it is available. But since I am using the forge annotations I do not even have two separate classes with those values (since the fields are static). Do I just set the static fields to the new values received from the server? And if so, how can I tell forge to write my new values to the client config file?

It know how to achieve this using the "old" way with configuration files but I have no idea how to do it with the annotations.

 

Any help is appreciated. Here is the config file if it is needed:

package morethanhidden.restrictedportals.config;

import net.minecraftforge.common.config.Config;

@Config(modid = "restrictedportals")
public class RPConfiguration {

    @Config.Comment("The list of dimension ids.")
    @Config.LangKey("config.name.dimension_ids")
    public static int[] dimensionIds = {-1, 1};

    @Config.Comment("The list of item ids that need to be in the player's inventory while entering a dimension.")
    @Config.LangKey("config.name.item_ids")
    public static String[] itemIds = {"minecraft:flint_and_steel", "minecraft:ender_eye"};

    @Config.Comment({"Specifies the dimensions that require a new key each time a player visits them.", "The used key " +
            "will get removed from the inventory after entering the dimension."})
    @Config.LangKey("config.name.teleport_player_on_fail")
    public static int[] oneTimeUseOnlyKeyDimensionIds = {};

    @Config.Comment({"If set to true, the player will get teleported to his spawn if he fails to enter a dimension",
        "Useful when trying to visit the end, as you would fall into the lava otherwise."})
    @Config.LangKey("config.name.onetimeuse")
    public static boolean teleportPlayerOnFail = true;

    @Config.Comment("The message displayed when a player has not the required items on him")
    @Config.LangKey("config.name.missing_item_message")
    public static String itemMissingMessage = "Please craft the following item to enter %dim%: %item%";

    @Config.Comment("The message displayed when unlocking a new dimension.")
    @Config.LangKey("config.name.dimension_unlocked_message")
    public static String dimensionUnlockedMessage = "You unlocked %dim%!";
}

Edit: It seems that ConfigManager#sync only lets you sync to the fields when you modify the content through the GUI. Is there some way to do it the other way, writing the static fields to the file?

Edited January 13, 2018 by SirWindfield
  • Quote

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted January 13, 2018

How to implement it is just a matter of choice.

You can make a new instance of the RPConfiguration class on client and manually sync the fields. Forge won't do any server-client syncing for you.

 

Or, you could just wait till 1.13 like me, it introduces synchronized data packs.

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
Share on other sites

SirWindfield    0

SirWindfield

SirWindfield    0

  • Tree Puncher
  • SirWindfield
  • Members
  • 0
  • 10 posts
Posted January 13, 2018

Making a new instance of RPConfiguration is not possible if you use the @Config annotations since your fields have to be static. 

At least for me, the annotation system has no way to actually set the fields manually since you have not access to the underlying Configuration instance.

@diesieben07 did post solutions, but those did not involve the new annotation system introduced in 1.12.

  • Quote

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted January 14, 2018
13 hours ago, SirWindfield said:

Making a new instance of RPConfiguration is not possible if you use the @Config annotations since your fields have to be static. 

At least for me, the annotation system has no way to actually set the fields manually since you have not access to the underlying Configuration instance.

@diesieben07 did post solutions, but those did not involve the new annotation system introduced in 1.12.

Well, why can't you get and set the fields when it's not final?

Also you can create instance of RPConfiguration since it's not final. You need separate instance than the static one anyway, considering the combined client. Just send sync packet based on the static configuration and setup separate client config with the packet. 

Anyway, forge does not have any tool for this. You have to do it yourself.

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
Share on other sites

SirWindfield    0

SirWindfield

SirWindfield    0

  • Tree Puncher
  • SirWindfield
  • Members
  • 0
  • 10 posts
Posted January 14, 2018

Ye but the only way to do the syncing is by making the fields non static so each instance has actually other values, am I right? But that would conflict with the configuration annotation api. Because that api actually expects values to be static. 

Quite upset that those two APIs can't work together. But creating a GUI for a simple Configuration is not hard at all. So I will probably just make the fields non static and use instances then. Thanks.

  • Quote

Share this post


Link to post
Share on other sites

Choonster    1651

Choonster

Choonster    1651

  • Reality Controller
  • Choonster
  • Forge Modder
  • 1651
  • 5100 posts
Posted January 14, 2018 (edited)

Only the fields of the top-level class need to be static, the fields of the other classes need to be non-static.

 

You could create your @Config class such that it has two static fields of the same type, one public (to store the server-side settings and be used by the config system) and one protected (to store the client-side copy of the server-side settings). You can then create the fields for all of your settings inside of the class you used for the fields.

 

Something like this:

@Config(modid = "<modid>")
public class ModConfig {
	
	public static final ConfigOptions serverOptions = new ConfigOptions();
	
	protected static final ConfigOptions clientOptions = new ConfigOptions();	
		
	public static class ConfigOptions {
		public int foo = 1;
		
		public float bar = 3.0f;
		
		public String baz = "baz";
	}
}

 

Edited January 14, 2018 by Choonster
  • Quote

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted January 14, 2018
5 hours ago, SirWindfield said:

Ye but the only way to do the syncing is by making the fields non static so each instance has actually other values, am I right? But that would conflict with the configuration annotation api. Because that api actually expects values to be static. 

Quite upset that those two APIs can't work together. But creating a GUI for a simple Configuration is not hard at all. So I will probably just make the fields non static and use instances then. Thanks.

Ah, I didn't read your code carefully. As Choonster said, you don't have to make every fields static. Just the field holding the whole configuration need to be static. You can create a new class containing all the configuration fields.

You can do as what Choonster said. You can store the client configuration fields in any class/instance you want if you use it properly. I prefer to put it in either the mod instance or the network instance which can be accessed from the mod instance.

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Nyko
      [1.16.5] overwriting the maximum build height

      By Nyko · Posted just now

      thanks for the info, since the whole thing sounds pretty complicated, I will probably not change it
    • ChocoCookies33
      Description: Exception in server tick loop

      By ChocoCookies33 · Posted 14 minutes ago

      local server set up not working, help is appreciated.  crash-2021-03-07_00.55.37-server.txt
    • LessyDoggy
      Forge 1.12.2 Installing Bug

      By LessyDoggy · Posted 1 hour ago

      So I used forge 1.16.5 but now I cant change it too 1.12.2 no mather what. I have tried Installing client, Installing server and extract but nothing works. I even removed forge 1.16.5 from my computer but I still have that verison on and idk how to change it.
    • Yourskillx2
      !!Keeps crashing during launch!!

      By Yourskillx2 · Posted 1 hour ago

      I have a decent sized mod pack with around 90 mods and every time I go to launch the game, it loads some stuff then crashes with exit code 0, I cannot figure out if its a mod in the pack doing it, like maybe not a release version or if it just doesn't work with Mc like its supposed to.
    • IMaironI
      server error

      By IMaironI · Posted 8 hours ago

      2021-03-06-8.log
  • Topics

    • Nyko
      4
      [1.16.5] overwriting the maximum build height

      By Nyko
      Started 14 hours ago

    • ChocoCookies33
      0
      Description: Exception in server tick loop

      By ChocoCookies33
      Started 14 minutes ago

    • LessyDoggy
      0
      Forge 1.12.2 Installing Bug

      By LessyDoggy
      Started 1 hour ago

    • Yourskillx2
      0
      !!Keeps crashing during launch!!

      By Yourskillx2
      Started 1 hour ago

    • IMaironI
      13
      server error

      By IMaironI
      Started 12 hours ago

  • Who's Online (See full list)

    • Nyko
    • loordgek
    • zlappedx3
    • Kreepydude
    • Helios885
    • ChocoCookies33
    • vemerion
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Configuration sync with server
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community