{"id":18157479,"url":"https://github.com/caellian/loaderenv","last_synced_at":"2025-10-08T19:28:11.731Z","repository":{"id":252707007,"uuid":"841203545","full_name":"Caellian/LoaderEnv","owner":"Caellian","description":"Compiler plugin that allows conditional compilation based on active mod loader.","archived":false,"fork":false,"pushed_at":"2024-08-17T08:29:37.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-06-08T01:04:39.870Z","etag":null,"topics":["annotation","annotation-processor","compiler-plugin","gradle-plugin","javac","minecraft"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Caellian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE-2.0","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-11T23:01:10.000Z","updated_at":"2024-08-17T08:29:41.000Z","dependencies_parsed_at":"2024-08-17T09:37:38.835Z","dependency_job_id":"c07f1c78-cedc-42c4-8f6a-2c0a0d316ced","html_url":"https://github.com/Caellian/LoaderEnv","commit_stats":null,"previous_names":["caellian/modenv","caellian/loaderenv"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Caellian/LoaderEnv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caellian%2FLoaderEnv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caellian%2FLoaderEnv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caellian%2FLoaderEnv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caellian%2FLoaderEnv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Caellian","download_url":"https://codeload.github.com/Caellian/LoaderEnv/tar.gz/refs/heads/trunk","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caellian%2FLoaderEnv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000711,"owners_count":26082805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation","annotation-processor","compiler-plugin","gradle-plugin","javac","minecraft"],"created_at":"2024-11-02T06:06:23.850Z","updated_at":"2025-10-08T19:28:11.713Z","avatar_url":"https://github.com/Caellian.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LoaderEnv\n\nThis is a very simple Java compiler plugin that (optionally) integrates into Gradle build environment to allow\nconditional inclusion and exclusion of classes/methods/fields based on the mod loaders that are present while compiling\na project. See [Usage](#Usage) section below for examples.\n\n## Usage\n\nLoaderEnv library adds two annotations:\n- [`@NotForLoader`](https://github.com/Caellian/LoaderEnv/blob/trunk/modules/lib/src/main/java/net/tinsvagelj/mc/loaderenv/NotForLoader.java)\n- [`@OnlyForLoader`](https://github.com/Caellian/LoaderEnv/blob/trunk/modules/lib/src/main/java/net/tinsvagelj/mc/loaderenv/OnlyForLoader.java)\n\nYou can annotate classes and methods with either to hide them if specified mod loader is(n't) present:\n```java\n@OnlyForLoader(Loader.FORGE)\npublic void useFluid(net.minecraftforge.fluids.FluidStack fluid) {\n    useFluid(fluid.getFluid(), fluid.getAmount());\n}\npublic void useFluid(Fluid fluid, float buckets) {\n    // ... implementation details ...\n}\n```\n\nIf the code is compiled without Forge in classpath (e.g. for Fabric), the first method definition will not be present.\n\nThis means you can also add your own polyfill to bridge functionality you need to rely on (if not already available).\n```java\npackage must.be.in.your.own.pkg;\n\n// ... imports ...\n\n// Cause compiler errors if wrong class is used in Forge:\n@NotForLoader(Loader.FORGE)\nclass FluidStack {\n    // ... implementation details ...\n}\n```\n\nLast important bit of information is that you can specify multiple mod loaders. This allows fine-grained control over\nmod functionality at compile time:\n```java\n@OnlyForLoader({Loader.FORGE, Loader.NEO_FORGE})\npublic void initClientsideModLogic() {\n    // ... forge/neoforge client init ...\n}\n@NotForLoader({Loader.FORGE, Loader.NEO_FORGE})\npublic void initClientsideModLogic() {\n    // ... non-forge client init ...\n}\n```\n\n## Important Notes\n\n**IDEs _will_ (by default) show errors even though element conditions are mutually exclusive.**\nCode itself will however properly compile with `gradle`/`javac` - this is because Java IDEs have their own error\ninspection code and don't use java compiler for error reporting (such as missing types).\nWhile this is a much faster approach, the tradeoff is inaccurate highlighting.\n\nProperly supporting all mainstream IDEs is a lot of work and adds more maintenance burden than I'm willing to put into\nthis project at the moment.\nThere's a [minimal implementation](./modules/jetbrains) available for Jetbrains IntelliJ platform (IDEA).\nContributions are welcome.\n\nThis plugin runs before any other annotations have been processed, which means it should (hopefully) work as expected\nalongside other annotation processors such as [Lombok](https://github.com/projectlombok/lombok).\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch1\u003eQuestions And Answers\u003c/h1\u003e\u003c/summary\u003e\n\u003cdl\u003e\n\u003cdt\u003eHow likely is the plugin to break?\u003c/dt\u003e\n\u003cdd\u003eThis compiler plugin relies on abstractions provided by java compiler to avoid touching too much of compiler internals.\nIt's more stable than rest of the code you'll write, so don't worry about it.\u003c/dd\u003e\n\u003cdt\u003eI want another/my mod loader supported.\u003c/dt\u003e\n\u003cdd\u003eMake a PR. You need to only add an entry to \u003ccode\u003eLoaderEnv\u003c/code\u003e enum in the \u003cem\u003eloaderenv-lib\u003c/em\u003e module.\u003c/dd\u003e\n\u003cdt\u003eWhy add ancient/discontinued mod loaders?\u003c/dt\u003e\n\u003cdd\u003e\u003cul\u003e\n\u003cli\u003eThey serve as examples.\u003c/li\u003e\n\u003cli\u003eIt's very cheap to add \u003ccode\u003eLoaderEnv\u003c/code\u003e entries so there's no reason not to support old stuff.\u003c/li\u003e\n\u003cli\u003eArchival purposes.\u003c/li\u003e\n\u003c/ul\u003e\u003c/dd\u003e\n\u003cdt\u003eWhat's the purpose of this?\u003c/dt\u003e\n\u003cdd\u003eIt's supposed to make writing \u003ca href=\"https://github.com/TheCBProject/CodeChickenLib\"\u003ebase libraries\u003c/a\u003e that work\nfor different mod loaders easier. It should also work for mods, but that's a lot more involved and I believe it's better\nto separate implementations into different submodules and then use this processor in the \u003cem\u003ecommon\u003c/em\u003e code instead.\u003c/dd\u003e\n\u003cdt\u003eWhy not just use reflection?\u003c/dt\u003e\n\u003cdd\u003eWhile reflection is much simpler, it's too costly when it runs in a game loop. This plugin bridges the gap between\ndevelopment ergonomics and build system complexity.\u003c/dd\u003e\n\u003cdt\u003eWhat's your motivation for writing this?\u003c/dt\u003e\n\u003cdd\u003eI wanted to try writing a Java compiler plugin that does something similar to C/C++ preprocessor and Rust cfg.\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/details\u003e\n\n## License\n\nThis project is licensed under ternary [MIT](./LICENSE-MIT)/[Apache-2.0](./LICENSE-APACHE-2.0)/[Zlib](./LICENSE-ZLIB) license.\nAdhere to whichever fits your use case the best.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaellian%2Floaderenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaellian%2Floaderenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaellian%2Floaderenv/lists"}