Minecraft Fabric Client tutorial 2 modifying file and directory names to add run and stop

Keywords: Programming Excel JSON Java github

First appeared in Enaium's personal blog

Modify package name, json file, add run stop

First, modify the package name

Change ExampleMod.java to ExcelInitializer.java

Modify the JSON files modid.mixins.json and fabric.mod.json

Change modid.mixins.json to excel.mixins.json

Contents of excel.mixins.json:


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

Package name of packagemixin

Class name of client mixin

compatibilityLevel java version

fabric.mod.json content:

{
  "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 is modid namemod name description Description authors Filename of mixinsmixinjson license if there is an open source agreement Filename of mainModInitializer

Then create an enumeration Excel.java in cn.enium.excel

content

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() {

    }

}

Inject run and stop

In this package, create a new minetraftclient mixin class

content

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();
    }
}

Then add this mixin to mixin json

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

complete

Posted by stone.cold.steve.austin on Sat, 22 Feb 2020 07:53:24 -0800