Skip to main content
Version: Minecraft 26.2

Join check

Crystal Garden must be on both the server and the client. The game matches block states by number, so a client without the mod cannot show the sprout correctly even if it joins.

With a join preparation phase exchange, the server asks the client before the player enters the world. Depending on the answer, it lets the player in or turns them away with a clear message.

Server: ask and check​

Declare both sides in the common entrypoint.

CrystalGardenMod.java
/** Before a player joins, the server checks that their client has Crystal Garden too. */
static ConfigurationExchange<String> handshake;

// inside onInitializeCommon
handshake = mod.network()
.configurationExchange("handshake", PayloadCodec.string())
.serverRequest((id, name) -> Optional.of("crystal_garden version?"))
.serverCheck((id, name, reply) -> {
LOGGER.info("[{}] Handshake with {}: {}", MOD_ID, name, reply.orElse("no answer"));
return reply.filter(answer -> answer.startsWith(MOD_ID + " "))
.isPresent()
? Optional.empty()
: Optional.of("Install Crystal Garden on your client to join this server.");
});
  1. serverRequest decides the question to send to each joining player.
  2. The client answers (see below).
  3. serverCheck looks at the answer. If it returns an empty value, the player is let in. If it returns a message, the connection is closed with that message. A client without the mod does not answer, so after 5 seconds the server gets an empty answer (reply is empty).

Client: answer​

Decide the answer in the client entrypoint. It is the first line of the CrystalGardenClient you create on the next page.

CrystalGardenClient.java (onInitializeClient)
CrystalGardenMod.handshake.clientAnswer(request -> CrystalGardenMod.MOD_ID + " " + mod.modVersion());

Check​

In single player, the integrated server makes the same exchange. When you enter a world, the log shows this.

[Poly Mod Loader] Answered configuration exchange crystal_garden:handshake
[crystal_garden] Handshake with PolyDev: crystal_garden 0.1.0
[Poly Mod Loader] Configuration exchange crystal_garden:handshake with PolyDev: answered, accepted

To check that the versions match too, compare the version in the answer inside serverCheck. Payload channels (exchanging messages after joining) are in Networking and sync.

Next step​

Add the client code.

Buy me a coffee