Skip to content

Merged environment

mineLdiver edited this page Jul 26, 2023 · 1 revision

Unlike MCP, Fabric, which StationAPI is developed for, provides merged environment.

It means that the code you write ends up usable on both client and server, without having to maintain two source sets and two mod jars.

It makes mod development a lot more streamlined and easier to get into.

You can refer to FabricMC Wiki for a more detailed documentation on this, but here's the summary:

Side annotations

Classes, fields and methods that are only supposed to exist on one side must be annotated with @Environment and an EnvType as value.

Example:

// textures are a client-side only feature, so this class cannot exist on server environment
@Environment(EnvType.CLIENT)
public class MyTextures {
    // texture code...
}

Side interfaces

It's also possible to implement an interface only on one side, for example:

@EnvironmentInterface(
    value = EnvType.CLIENT,
    itf = CustomAtlasProvider.class
)
public class MyItem extends TemplateItemBase implements CustomAtlasProvider {
    // item code...

    @Override
    @Environment(EnvType.CLIENT)
    public Atlas getAtlas() {
        return MyTextures.myAtlas;
    }
}