Platform proxies are a way of abstracting platform-specific code away through a common interface from your common code.
With platform proxies, you can:
// Define implementations for each platform
MyInterface instance = Balm.platformProxy()
.withFabric("com.example.mymod.fabric.FabricImplementation")
.withForge("com.example.mymod.forge.ForgeImplementation")
.withNeoForge("com.example.mymod.neoforge.NeoForgeImplementation")
.build();
Implementation classes loaded through the platform proxy system must:
For the rare case where you need to handle some mod logic differently on one platform without needing to access loader-specific code, Balm also provides the current platform through Balm.platform().name() and its supported platforms in the LoaderPlatforms class.
if (Balm.platform().name().equals(LoaderPlatforms.FABRIC)) {
// Do something that only happens on Fabric (but obviously, without having access to Fabric APIs since you're in common code)
}
Balm also provides other proxy types: