那么知周所众 minecraft是一款沙盒游戏 那么也是用java做的 就可以学点fabric mod教学

例如

import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.waterplus.registry.ModItemGroup;

public class text implements ModInitializer {
       public static final String MOD_ID = "text";
       public static final Logger LOGGER = LoggerFactory.getLogger("text-mod");
      
       @Override
        public void onInitialize() {
               Moditem.registerModItems();
               ModItemGroup.registerModItemGroup();
               LOGGER.info("text start");
}

这是一个示例代码 好了,废话不多说,开始第一步

配置环境

1.下载JDK 去Java 7, 8, 11, 13, 15, 17, 19, 21 Download for Linux, Windows and macOS (azul.com)下载JDK(要选 .msi 格式的),由于zulu下载慢的原因这里供大家一个jdk17下载:https://download.fgit.cf/dragonwell-project/dragonwell17/releases/download/dragonwell-standard-17.0.9.0.10%2B9_jdk-17.0.9-ga/Alibaba_Dragonwell_Standard_17.0.9.0.10.9_x64_windows.zip

2.下载IntelliJ IDEA 直接点链接就行了awa https://download.jetbrains.com/idea/ideaIC-2023.3.3.exe

3.下载示例fabric mod https://archive.fgit.cf/FabricMC/fabric-example-mod/archive/refs/heads/1.20.zip

安装

  1. 安装IntelliJ IDEA 一直点下一步 记得把安装位置换成除c盘外的盘符

  2. 把下载的jdk解压到任意一个文件夹里,如果是zulu 那点下一步就行了 同样记得把安装位置换成除c盘外的盘符,Zip的jdk需要配置环境变量 请看JDK的安装与环境变量配置详细教程-CSDN博客 安装jdk这一步直接跳过看正片就行了

  3. 把下载的示例fabric mod的zip解压到任意一个文件夹里 然后打开 按shift+右键 点在终端打开,win10用户选择PowerShell 然后输入.\gradlew build(记得使用管理员打开PowerShell) 如果在下载gradle时太慢 按Ctrl+C 输入y 回车 然后直接复制它下载的链接 我的是https://services.gradle.org/diCtrstributions/gradle-8.5-bin.zip 那就用浏览器下载例如edge(无耻推广)下载之后 打开C:\Users\你的用户名\ .gradle\wrapper\dists\gradle-8.5-bin\ 之后再往里打开 把下载的gradle-8.5-bin.zip解压出来 之后把文件扩展名打开 复制一份gradle-8.5-bin.zip.lck 然后改名字成gradle-8.5-bin.zip.ok gradle的安装就搞定了!

  4. 打开build.gradle文件 注:用记事本打开此文件 在

    repositories {
    	// Add repositories to retrieve artifacts from in here.
    	// You should only use this when depending on other mods because
    	// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
    	// See https://docs.gradle.org/current/userguide/declaring_repositories.html
    	// for more information about repositories.
    }
    

    这里替换成

    repositories {
    	maven {
    		url 'https://maven.aliyun.com/repository/central'
    	}
    	maven {
    		url 'https://repository.hanbings.io/proxy'
    	}
    }
    

    然后保存

  5. 打开settings.gradle,把url = 'https://maven.fabricmc.net/' 替换成 url ='https://repository.hanbings.io/proxy' 然后再加一条仓库

    maven {
         name = 'aliyun'
         url = 'https://maven.aliyun.com/repository/gradle-plugin'
    }
    

    然后保存 再输入.\gradlew build 就行了 (要等他弄完)

    打开

    1. 打开IDEA 同意协议 再点击打开项目 定位到刚刚解压的文件夹 也就是fabric-example-mod-1.20 然后点ok 再点Trust Project
    2. 把readme.md 关掉 idea在打开项目后 会在构建一次 让它构建完成 再等一下索引完成(总结:等等等,然后还是等)
    3. 点小齿轮打开项目配置 点一下SDK旁边的框 选择add jdk 定位到你解压的JDK 之后点ok 还是点ok

    运行

    1. 点击右边的大象,再展开fabric-example-mod-1.20 之后展开Tasks 再展开fabric 双击runClient 之后等游戏启动就ok了

好了,这环境配置就ok了 bye!😄