盘古是一个基于内容开发的 Minecraft Forge Mod 快速开发框架。盘古并不实现任何游戏内容,只提供了一系列便于开发的工具类或者框架。
主要功能
UI 框架:一个基于 GuiScreen 的 UI 框架,拥有更加完善的组件系统
Bridge 通讯:允许开发者直接调用方法即可完成服务端、客户端之间的相互通信,不需要再手动发包。
Loader 系统:盘古提供了不少了注解,可以用于快速注入
Registering System 内容注册器:可以通过注解快速注册物品、方块等
Custom Font Renderer 字体:允许开发者加载自定义的字体
Utils 工具类:盘古提供了不少的工具类,覆盖数据、渲染等方面
创建基于 Pangu 的新项目
你可以直接下载我们的 示例项目(Zip下载链接),下载好后,修改相关配置。使用终端执行以下命令:gradle setupDecompWorkspace idea gIR。然后直接使用 IDEA 打开该文件夹即可。
在已有项目中引入 Pangu
你只需要在 build.gradle 文件中,加入以下内容即可,注意更换为最新的版本号!
1repositories {
2 maven { url 'https://www.jitpack.io' }
3}
4
5dependencies {
6 implementation "com.github.MinecraftPangu:Pangu:1.13.7:dev"
7}
8
9// IDE Runner Settings from https://blog.ustc-zzzz.net/add-jvm-arguments-to-ide-in-forge-mod-projects/
10// 以下部分代码是为了在开发环境中引入 Pangu 的 CoreMod
11ext.jvmArguments = [
12 '-Dfml.coreMods.load=cn.mccraft.pangu.core.asm.PanguPlugin'
13]
14
15idea.workspace.iws.withXml {
16 def runManager = it.asNode().component.find({ it.@name == 'RunManager' })
17 runManager.configuration.findAll({ it.@type == 'Application' }).each {
18 def mainClass = it.option.find({ it.@name == 'MAIN_CLASS_NAME' }).@value
19 if (mainClass == 'GradleStart' || mainClass == 'GradleStartServer') {
20 def jvmArg = String.join(' ', jvmArguments)
21 it.option.find({ it.@name == 'VM_PARAMETERS' }).@value = jvmArg
22 }
23 }
24}Copy
@Load 加载器
在使用了盘古后,我们不在需要通过 CommonProxy 的方法来执行初始化操作:
1public interface ExampleMessage {
2 @Load
3 static void init() {
4 PanguExample.getLogger().info("Pangu-Example initialization");
5 }
6}Copy
我们可以在任意可见静态方法上加上 @Load 注解,当游戏在进行预初始化(Pre-Initialization)时,该方法则会被执行。
如果你的初始化操作,仅在客户端执行,则可以通过修改 @Load 注解中的属性控制。(在服务端启动时,将会删除该方法,将同时有 @SideOnly 的效果)
1@Load(side = Side.CLIENT)
2static void init() {
3 PanguExample.getLogger().info("Pangu-Example initialization (client-side)");
4}Copy
当然还有其他的属性,请自行查询。
@BindKeyPress 按钮绑定
该注解提供了快速绑定按钮到按键的功能。
1@BindKeyPress(Keyboard.KEY_O)
2static void keyDown() {
3 PanguExample.getLogger().info("YOU PRESSED O!");
4}Copy
你可以将该功能用于调试(建议添加 devOnly = true,表示仅在开发环境中生效),也可以用作你 Mod 中某功能的触发按键(建议加入 description = "key.xxxx",则该案件将会对应注册按键绑定,用户可以在设置界面中修改)
@Reg 注册器
盘古 cn.mccraft.pangu.core.loader.annotation 包下提供了一些游戏相关内容的注册注解,只需要将对应内容注解即可自动完成注册。
1public class Items {
2 // 自动注册为 modid:simple_item
3 @RegItem
4 public static Item simpleItem = new Item();
5}Copy
@Bridge 服务器通讯
Bridge 是一个快速通信框架,允许开发者“远程调用方法”,自动完成客户端与服务端之间的通信。使用下述代码,在游戏中按下 O 键时,将会在服务端中输出 Message From client: I'm Chen
1@BindKeyPress(value = Keyboard.KEY_O, devOnly = true)
2static void keyDown() {
3 say("I'm Chen");
4}
5
6@Bridge
7static void say(String message) {
8 PanguExample.getLogger().info("Message From client: " + message);
9}Copy
当我们在客户端调用 say 方法时,将会被重定向服务端中执行该方法。特殊的你可以在方法中添加EntityPlayer参数,将会自动设置为发送者。
1@BindKeyPress(value = Keyboard.KEY_O, devOnly = true)
2static void keyDown() {
3 say(null, "I'm Chen");
4}
5
6@Bridge
7static void say(EntityPlayer player, String message) {
8 PanguExample.getLogger().info("Message From " + player.getName() + ": " + message);
9}CopyCopyrightAll content on this website is protected by copyright law and other relevant laws and regulations. Without explicit authorization from the author of this website, no individual or organization may copy, reproduce, quote, excerpt, modify, publish, perform, derive from, or otherwise use the content of this website in any way.Third-party works mentioned on this website (such as quotations, images, etc.) are copyrighted by their respective authors.Individuals or organizations that violate the above provisions will be held legally responsible. If you need to reproduce the content of this website, please obtain written authorization from the author and include the source and author information.