1.19.2的离线开发包附文末
我们本次来进行Minecraft 1.19.2 Fabric模组开发教程的介绍,首先我们需要下载eclipse和openJDK
eclipse下载
eclipse官网下载最新版
openJDK下载
下载最新版JDK 17.02+8
1.19.2 mdk下载
下载1.19.2MDK
注:1.19.2需要使用Java17进行开发。eclipse中的Java 11+VM需要选择我们上面刚刚下载的hotspot地址
一般下载后的地址:
C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot
1.将下载后的MDK解压(打开eclipse -> 导入项目 -> 选择Gradlew -> 选择我们解压后的MDK的文件夹 -> 点击Finish,等待模组包构建
出现这样的画面说明构建成功了
2.修改fabric.mod.json
该文件路径一般在~\src\main\resources
下,是fabric项目的配置文件:
fabric.mod.json
{
"schemaVersion": 1,
//你的modid
"id": "joyggd",
"version": "${version}",
//你的模组名称
"name": "Joy's GGD Mod",
"description": "This is an example description! Tell everyone what your mod is about!",
//你的创作团队成员名称
"authors": [
"joy187"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
},
//协议为MIT
"license": "MIT License",
"icon": "assets/modid/icon.png",
"environment": "*",
"entrypoints": {
//这个是你的项目主类的路径
"main": [
"net.joy187.joyggd.Main"
],
//这个是你的客户端类的路径
"client":[
"net.joy187.joyggd.ModClient"
]
},
//这个是你的mixin文件路径
"mixins": [
"joyggd.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.10",
"fabric-api": "*",
"minecraft": "~1.19",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}
}
之后修改上面提到的mixin文件:
joyggd.mixins.json
{
"required": true,
"minVersion": "0.8",
//这里要指向你Java开发包中的mixin包的路径
"package": "net.joy187.joyggd.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
//客户端的mixin类
"client": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
}
}
3.找到我们java文件夹,然后建一个net
包,包内新建一个以作者名称命名的包joy187
,然后在里面建立一个以你的模组名称的文件夹(joyggd为例),里面建一个项目主类Main
Main.java
package net.joy187.joyggd;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main implements ModInitializer {
//定义你的modid
public static final String MOD_ID = "joyggd";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
}
}
同样路径下新建一个客户端类ModClient
用于注册:
ModClient.java
package net.joy187.joyggd;
import net.fabricmc.api.ClientModInitializer;
public class ModClient implements ClientModInitializer{
@Override
public void onInitializeClient() {
}
}
新建一个mixin包,mixin包中新建ExampleMixin
类:
ExampleMixin.java
package net.joy187.joyggd.mixin;
import net.joy187.joyggd.Main;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TitleScreen.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
Main.LOGGER.info("This line is printed by an example mod mixin!");
}
}