ArchitecturyTarget
ArchitecturyTarget
利用ArchitecturyTarget类的getCurrentTarget方法, 可以直接获取当前运行的模组加载器平台.
下面我们来用ArchitecturyTarget修改我们上一章节编写的Storyteller代码.
修改StoryTeller类, 去掉ExpectPlatform注解, 直接基于当前运行的加载器环境进行判断
public class Storyteller {
public static final String FORGE_STORY = "I'm forge, your old friend.";
public static final String FABRIC_STORY = "I'm fabric, your new friend.";
public static void tellStory() {
final String platform = ArchitecturyTarget.getCurrentTarget();
System.out.println(platform.equals("forge") ? FORGE_STORY : FABRIC_STORY);
}
}
现在应该能得到与之前相同的效果. 读者可以根据需要取舍使用ExpectPlatform和ArchitecturyTarget
最后更新于