Bektor Posted August 10, 2017 Posted August 10, 2017 (edited) Hi, if it is possible using Forge to change values server side only, for example to allow a server owner to change how much energy a machine produces or consumes without the need of a update of the mod itself on the client side. Basically the server owner should be able to change specific values and the client uses the values from the server instead of it's own values. My problem there is: I don't know if this is possible with the current available systems in Forge/Minecraft. I don't know how to do it, except for that at some point the server has to send all the data to the client. Thx in advance. Bektor Edited August 14, 2017 by Bektor Quote Developer of Primeval Forest.
Bektor Posted August 11, 2017 Author Posted August 11, 2017 Anyone? Quote Developer of Primeval Forest.
OreCruncher Posted August 11, 2017 Posted August 11, 2017 Uh, this isn't related to writing mods. I suggest you read the documentation for the various mods you use in your pack. A lot of them provide configuration settings to do specifically what you want, or provide integration with systems such as Minetweaker/Crafttweaker. Quote
Bektor Posted August 11, 2017 Author Posted August 11, 2017 On 8/11/2017 at 9:23 PM, OreCruncher said: Uh, this isn't related to writing mods. I suggest you read the documentation for the various mods you use in your pack. A lot of them provide configuration settings to do specifically what you want, or provide integration with systems such as Minetweaker/Crafttweaker. Expand This is related to writing mods as I want my mod to have this feature, as I want for balancing and thus stuff my mod to sync data between the server and the client so that when I have for example a config file or a json file or whatever file I might want to use, I can change on the server just this file and everyone will be able to play with the new balanced variables instead of the old ones and the old ones are only used on the client when the client is not conntected to my server. Quote Developer of Primeval Forest.
OreCruncher Posted August 11, 2017 Posted August 11, 2017 Then your mod would have to send packets to clients when a player logs in. Up to your mod to do that, assuming the client really needs your updated server side values. Quote
Bektor Posted August 11, 2017 Author Posted August 11, 2017 On 8/11/2017 at 9:36 PM, OreCruncher said: Then your mod would have to send packets to clients when a player logs in. Up to your mod to do that, assuming the client really needs your updated server side values. Expand And here we've got a few problems: How to send the data to the client in a way the performance doesn't drop when it's a lot of data? How should the client or the server know if the data is different? How should I stop the client from using the data that already comes with the mod instead of using the new server data? Where to save the data on the client side? I mean the data is server specific like a resource pack can be server specific. Quote Developer of Primeval Forest.
Socratic_Phoenix Posted August 14, 2017 Posted August 14, 2017 On 8/11/2017 at 9:54 PM, Bektor said: How to send the data to the client in a way the performance doesn't drop when it's a lot of data? Expand How much data do you plan on sending? I doubt the amount of data you'll need to send will show any drop in performance, especially since you'll only be sending the config packet once, on join. On 8/11/2017 at 9:54 PM, Bektor said: How should the client or the server know if the data is different? Expand The easiest way to fix this would be to just always send the configuration packet... In fact, that's probably the best way to do it. The only way to know if the values were different would be to send all the values either from client->server or from server->client, so you may as well just send them from server->client anyway... On 8/11/2017 at 9:54 PM, Bektor said: How should I stop the client from using the data that already comes with the mod instead of using the new server data? Expand Abstract away the config into an object or into static fields. When the client joins the server, the server should send the configuration values, and the client should set all the fields to the received values. On 8/11/2017 at 9:54 PM, Bektor said: Where to save the data on the client side? I mean the data is server specific like a resource pack can be server specific. Expand Don't save it. Unless you're storing large amounts of data, caching will likely be more trouble than it's worth.. -------------------------------- How much data do you plan on sending? If it really is just a config file of integer settings for machines, it shouldn't be too much... 1 Quote Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes). I know Java pretty well... So yeah... Quote This is where I'd put an inspirational and/or clever quote, but I can't think of one right now... Expand This is the output of the totally, 100% working compiler for my programming language, Planet9: Beginning Compilation... Failed compilation! planet9.compiler.error.CompilationException: Compiler not yet implemented at planet9.compiler.Compiler.compile(Compiler.java:39) at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)
Bektor Posted August 14, 2017 Author Posted August 14, 2017 (edited) On 8/14/2017 at 1:53 PM, Socratic_Phoenix said: Don't save it. Unless you're storing large amounts of data, caching will likely be more trouble than it's worth.. Expand Why would caching be more trouble than it's worth? On 8/14/2017 at 1:53 PM, Socratic_Phoenix said: How much data do you plan on sending? Expand Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long. Edited August 14, 2017 by Bektor Quote Developer of Primeval Forest.
Socratic_Phoenix Posted August 14, 2017 Posted August 14, 2017 On 8/14/2017 at 8:56 PM, Bektor said: Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long. Expand Well, assuming the worst case, that they're all longs, you'd have about 300*8 bytes, or 3.2 kilobytes. I wouldn't consider that a lot of data, especially since you'd only be sending it on login. Furthermore, 3.2 kilobytes is worst case - I don't know how many longs vs. ints and booleans you plan on sending, it could easily cut my estimate in half, or more. Also note that Forge tests network transmissions of 2 MB, which is quite a lot larger than your packet. You could also compress the data... Quote Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes). I know Java pretty well... So yeah... Quote This is where I'd put an inspirational and/or clever quote, but I can't think of one right now... Expand This is the output of the totally, 100% working compiler for my programming language, Planet9: Beginning Compilation... Failed compilation! planet9.compiler.error.CompilationException: Compiler not yet implemented at planet9.compiler.Compiler.compile(Compiler.java:39) at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)
mysticalherobine Posted August 14, 2017 Posted August 14, 2017 (edited) On 8/14/2017 at 8:56 PM, Bektor said: Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long. Expand First off, do you have a class that loads, saves, and stores all your config data? If not I would highly recommend you have one, it would be the place to store all your variables. Since you want to send data, try to create a PacketConfig class that handles sending data from Server->Client. In the packet, just define the variables inside of the packet that you want the server to be able to edit and send to the client side of things, e.g. MachineEnergyPerTick or MachineProgressSpeed. Then, just send the packet to the client, have them read the packet and change the values specified in the Config class to match. It wouldn't change the config file and would sync up the server to client. Edited August 14, 2017 by mysticalherobine Quote
DougLazy Posted August 15, 2017 Posted August 15, 2017 Sounds like you're already close to a solution, but I found SimpleNetworkWrapper nice to use. create a SimpleNetworkWrapper, something like: SimpleNetworkWrapper simpleNetworkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("myChannel"); You will need to use that to register a message class, I did this in postinit like: simpleNetworkWrapper.registerMessage(MyMessageHandler.class, MyMessage.class, 0, Side.CLIENT); Declarations such as: MyMessage implements IMessage MyMessageHandler implements IMessageHandler<MyMessage, IMessage> For an example see the comment =~ line 62 of net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.java Finally you send the message from the server like this: simpleNetworkWrapper.sendToDimension(new MyMessage(myConfigurationSettings), 0); Which will fire the MyMessageHandler.onMessage on any client attached to that server that is in the Overworld (That's the 0). You would have to repeat this for the Nether (-1) and The End (1) if that was important. IMessage defines a dead simple ByteBuf serialization pattern which is where you'd convert your settings to something transportable. toBytes(ByteBuf buf) fromBytes(ByteBuf buf) 0d 1 Quote
Socratic_Phoenix Posted August 15, 2017 Posted August 15, 2017 On 8/15/2017 at 6:12 AM, DougLazy said: Finally you send the message from the server like this: Expand You can also invoke sendTo with an IMessage & Player, to send to a specific player when they log in. Quote Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes). I know Java pretty well... So yeah... Quote This is where I'd put an inspirational and/or clever quote, but I can't think of one right now... Expand This is the output of the totally, 100% working compiler for my programming language, Planet9: Beginning Compilation... Failed compilation! planet9.compiler.error.CompilationException: Compiler not yet implemented at planet9.compiler.Compiler.compile(Compiler.java:39) at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)
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.