码迷,mamicode.com
首页 > 其他好文 > 详细

Minecraft Fabric Client 教程 #2 修改文件和目录名添加run和stop

时间:2020-02-22 12:05:13      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:mod   png   lin   pow   author   require   port   abr   name   

首发于Enaium的个人博客


修改 包名、json文件、添加run stop

技术图片

首先先修改包名

技术图片

ExampleMod.java改为ExcelInitializer.java

修改json文件modid.mixins.jsonfabric.mod.json

modid.mixins.json改为excel.mixins.json

excel.mixins.json内容:


{
  "required": true,
  "package": "cn.enaium.excel.mixin",
  "compatibilityLevel": "JAVA_8",
  "mixins": [
  ],
  "client": [
    "ExampleMixin",
    "MinecraftClientMixin"
  ],
  "injectors": {
    "defaultRequire": 1
  }
}

packagemixin的包名

client mixin的类名

compatibilityLevel java版本

fabric.mod.json内容:

{
  "schemaVersion": 1,
  "id": "excel",
  "version": "1.0",

  "name": "Excel",
  "description": "!",
  "authors": [
    "Enaium!"
  ],
  "contact": {
    "homepage": "https://fabricmc.net/",
    "sources": "https://github.com/FabricMC/fabric-example-mod"
  },

  "license": "CC0-1.0",
  "icon": "assets/excel/icon.png",

  "environment": "*",
  "entrypoints": {
    "main": [
      "cn.enaium.excel.ExcelInitializer"
    ]
  },
  "mixins": [
    "excel.mixins.json"
  ],

  "depends": {
    "fabricloader": ">=0.7.2",
    "fabric": "*",
    "minecraft": "1.15.x"
  },
  "suggests": {
    "flamingo": "*"
  }
}

id就是modid
namemod名字
description说明
authors作者
mixinsmixinjson的文件名
license如果有开源开源协议
mainModInitializer的文件名

然后在cn.enaium.excel新建一个枚举Excel.java

内容

package cn.enaium.excel;

/**
 * @Author Enaium
 * @Date 2020/1/4 20:23
 */
public enum Excel {

    INSTANCE;

    public final String NMAE = "Excel";

    public final String VERSION = "1";

    public final String MINECRAFT_VERSION = "1.15.1";

    public void onEnable() {

    }

    public void onDisable() {

    }

}

注入run和stop

再mixin这个包里面新建一个MinecraftClientMixin

内容

package cn.enaium.excel.mixin;

import cn.enaium.excel.Excel;
import net.minecraft.client.MinecraftClient;
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;

/**
 * @Author Enaium
 * @Date 2020/1/4 20:25
 */
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
    @Inject(at = @At("HEAD"), method = "run()V")
    private void onEnable(CallbackInfo info) {
        Excel.INSTANCE.onEnable();
    }

    @Inject(at = @At("HEAD"), method = "stop()V")
    private void onDisable(CallbackInfo info) {
        Excel.INSTANCE.onDisable();
    }
}

然后再mixin json 里面添加这个mixin

{
  "required": true,
  "package": "cn.enaium.excel.mixin",
  "compatibilityLevel": "JAVA_8",
  "mixins": [
  ],
  "client": [
    "ExampleMixin",
    "MinecraftClientMixin"
  ],
  "injectors": {
    "defaultRequire": 1
  }
}

完成

Minecraft Fabric Client 教程 #2 修改文件和目录名添加run和stop

标签:mod   png   lin   pow   author   require   port   abr   name   

原文地址:https://www.cnblogs.com/Enaium/p/12344569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!