Jump to content

Recommended Posts

Posted

I'm building a mod that relies on external XML files that define the content of the mod. I've managed to figure out how to load the files when the mod is being run on a dedicated server. Here's an example of how I'm loading files:

 

File file = FMLCommonHandler.instance().getMinecraftServerInstance().getFile("mods/empathymod/settings.xml");
// parse loaded file

 

However the game crashes when loading (before the title screen is reached) when running the mod on the CombinedClient because FMLCommonHandler.instance().getMinecraftServerInstance() returns null. What is the best way load these files that works for the Combined Client and Dedicated Server? Also, I'd ideally only want the server to be managing this content. In other words, the client shouldn't load any of the externals files but instead receive what the server has loaded from its external files. Is this possible? Are there any tutorials on the matter?

 

 

Posted
  Quote
You will have to write a dynamic registry then that can change (since of the course the client can connect to multiple servers in a row). Then when the server starts you read the data there and send it to every player that logs in (PlayerLoggedInEvent).

I have worded my question poorly. I already have the XML data being loaded and parsed, I'm just unsure of how to determine if the mod is running as the client vs the server. Then if the mod is running as the client, it needs to ask the server for the data it needs.

 

  Quote
Also... why XML?

We have a team of designers writing the content and XML is the markup language that they are most familiar with.

Posted

Right, but once the server has started and loaded the data, how would a client ask the server for the data?

 

Better yet, are there any mods that are doing something similar? I'm aware of what needs to be done, but I'm confused how to accomplish it within the Forge API.

Posted

One of approaches:

 

In common code (main file / common proxy) make MyRegistry field.

In client code (client proxy) make additional MyRegistry field.

 

Use common MyRegistry as a place to load and hold stuff from XML, no matter what side.

Use client MyRegistry as holder for what client should use on current server.

 

More detailed:

1. Use init events to read XML files and place stuff loaded from them in common registry.

* For dedic it will be dedicated server data.

* For client it will be fallback single-player data (which can be used when you play SP).

 

2. Use PlayerLoggedInEvent (which is fired only on server thread) to gather common registry data and send it to client - which will save it to client registry.

* As you now see - no matter if you are on SP (integrated) or MP (dedicated/LAN) common registry is always present and no matter what you play - SP or MP - common one will be used on server thread (dedicated or integrated), and the other one (client's) will be use as display registry.

* What you choose to sync is entirely up to you.

 

3. Just to stress things out:

Your mod will have 2 registries - one for data holding, one for display, where display one will only exist on Client.jar.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

Okay this is starting to make sense! Just have some follow up questions:

 

As I mentioned above, I found that I was able to load the external files when via:

File file = FMLCommonHandler.instance().getMinecraftServerInstance().getFile("mods/empathymod/settings.xml");

While this works on the dedicated server it fails on the combined client because the MinecraftServerInstance is null. What is the proper method to load the data for the combined client (single player)?

 

How much data can I send over packets? Are there any problems with send large amounts of data? There's going to be quite a few large XML files, but I'd only need to send it to clients when either they first logged in or when the server reloaded the external files.

Posted

Setup @SidedProxy, design choice:

 

abstract Common
{
    abstract File getDir();
}

Client extends Common
{
    File getDir() { return Minecraft.getMinecraft().mcDataDir; }
}

Server extends Common
{
    File getDir() { return FMLCommonHandler.instance().getMinecraftServerInstance(); }
}

 

Packet client->server are limited and if you need big data - you need to split them manually.

Packets server->client on the other hand are handled internally, so basically there is no limit as to what can written to buffer - it will be split into parts if too big. As to how much can be sent? Well - you can always throttle connection, but if operation happens per-login you are safe to send data in MB.

Big note - you should NOT send xml files!!! Waste of memory and requires client-side decoding. Once you decoded them on server you can encode data directly to buffer and read it back.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello , when I try to launch the forge installer it just crash with a message for 0,5 secondes. I'm using java 17 to launch it. Here's the link of the error :https://cdn.corenexis.com/view/?img=d/ma24/qs7u4U.jpg  
    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
  • Topics

×
×
  • Create New...

Important Information

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