withMinecraftClient¶
inline fun withMinecraftClient(crossinline block: Minecraft.() -> Unit)
Runs block against the running Minecraft, on the physical client and only once there is a game to run it against - see withMinecraftServer for the server-side counterpart.
The distinction onClient does not draw: that one answers "is this the client distribution", and a data run is exactly that distribution with no game behind it - it loads mods to collect their providers and never constructs a Minecraft. So an onClient block does execute in a data run, and anything in it reaching for minecraftClient, or for a registry that resolves through one, finds null and throws straight out of mod construction - killing the run before a single provider executes, for every mod in the load.
Handing the instance over as a receiver is what makes that impossible to get wrong: there is no way to write the body without having gone through the check first.
The two guards answer different questions and both are load-bearing. onClient is about the distribution: Minecraft is not in a dedicated server jar, so naming it there fails to link at all. The null check is about the instance, and is what matters everywhere the class does load - which includes a data run, and includes server-side code in single player, where the integrated server runs inside the client's own JVM and can reach this perfectly well.