第一个Mod开发
大约 1 分钟约 363 字
第一个Mod
创建项目
使用IDEA创建一个Minecraft项目:
解决gradle构建慢的问题
在gradle.properties
中:
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.http.nonProxyHosts=10.*|localhost
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
systemProp.https.nonProxyHosts=10.*|localhost
切换fabric以及mavencenter源,settings.gradle
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://repository.hanbings.io/proxy'
}
gradlePluginPortal()
}
}
build.gradle
repositories {
maven {
url 'https://maven.aliyun.com/nexus/content/groups/public'
}
maven {
url 'https://repository.hanbings.io/proxy'
}
}
开始编写代码
我们的DemoMod1需要实现ModInitializer接口
DemoMod1Client需要实现ClientModInitializer接口
public class DemoMod1 implements ModInitializer {
@Override
public void onInitialize() {
}
}
public class DemoMod1Client implements ClientModInitializer {
@Override
public void onInitializeClient() {
}
}
同时在resources目录下的fabric.mod.json
文件中,需要设置这两个类的位置:
"entrypoints": {
"client": [
"com.cxk.demo_mod1.client.DemoMod1Client"
],
"main": [
"com.cxk.demo_mod1.DemoMod1"
]
},
简单些一点代码:
public class DemoMod1 implements ModInitializer {
public static final String MOD_ID = "demo_mod1";
public static final Logger LOGGER = Logger.getLogger(MOD_ID);
@Override
public void onInitialize() {
LOGGER.info("Hello Fabric world!");
}
}
运行代码
可以看到控制台打印信息了,游戏也正常启动,说明mod生效了
有时候可能会因为版本冲突原因启动不了,这里给一个不冲突的版本:
gradle.propertities
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
loader_version=0.15.11
# Mod Properties
mod_version = 1.0
maven_group = com.cxk
archives_base_name = demo_mod1
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.99.0+1.20.6
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.http.nonProxyHosts=10.*|localhost
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
systemProp.https.nonProxyHosts=10.*|localhost