> For the complete documentation index, see [llms.txt](https://turou.gitbook.io/arch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://turou.gitbook.io/arch/architectury-plugin/platformonly.md).

# PlatformOnly

### PlatformOnly

PlatformOnly是一个用于限定某一方法只能在某一平台执行的注解.

* @PlatformOnly("forge")修饰的方法**只能**在Forge模块调用(编译后不会出现在Fabric代码中)
* @PlatformOnly("fabric")修饰的方法**只能**在Fabric模块调用(编译后不会出现在Forge代码中)

被PlatformOnly修饰的方法如果在common包直接调用会产生警告 (需要安装插件)

![Warning](https://s2.loli.net/2022/04/02/Hp85GEtrSfOKueB.png)

如果我们尝试在Forge模块中调用被@PlatformOnly("fabric")修饰的方法, 游戏会抛出反射异常

![InvocationTargetException](https://s2.loli.net/2022/04/02/1DZfJ9xFXowS5mn.png)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://turou.gitbook.io/arch/architectury-plugin/platformonly.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
