瀏覽代碼

Merge pull request #2 from geniiii/master

register commands client-side, fully update to loader 0.4
umollu 6 年之前
父節點
當前提交
2f6928e97c

+ 11 - 0
build.gradle

@@ -13,6 +13,13 @@ group = project.maven_group
 minecraft {
 }
 
+repositories {
+    maven {
+        name "CottonMC"
+        url "http://server.bbkr.space:8081/artifactory/libs-snapshot"
+    }
+}
+
 dependencies {
 	//to change the versions see the gradle.properties file
 	minecraft "com.mojang:minecraft:${project.minecraft_version}"
@@ -22,6 +29,10 @@ dependencies {
 	// Fabric API. This is technically optional, but you probably want it anyway.
 	modCompile "net.fabricmc:fabric:${project.fabric_version}"
 
+    // Used for commands
+    modCompile "io.github.cottonmc:client-commands:${clientcommands_version}"
+    include "io.github.cottonmc:client-commands:${clientcommands_version}"
+
 	implementation 'com.google.code.gson:gson:2.8.5'
 }
 

+ 3 - 2
gradle.properties

@@ -5,13 +5,14 @@ org.gradle.jvmargs=-Xmx1G
 	# check these on https://fabricmc.net/use
 	minecraft_version=1.14
 	yarn_mappings=1.14+build.3
-	loader_version=0.4.2+build.132
+	loader_version=0.4.3+build.134
 
 # Mod Properties
-	mod_version = 1.1.1
+	mod_version = 1.1.2
 	maven_group = com.umollu
 	archives_base_name = ash
 
 # Dependencies
 	# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
 	fabric_version=0.2.7+build.127
+	clientcommands_version=0.2.1+1.14-pre5-SNAPSHOT

+ 30 - 31
src/main/java/com/umollu/ash/AshMod.java

@@ -2,23 +2,23 @@ package com.umollu.ash;
 
 import com.google.gson.Gson;
 import com.mojang.brigadier.arguments.IntegerArgumentType;
-import net.fabricmc.api.ModInitializer;
-import net.fabricmc.fabric.api.registry.CommandRegistry;
+import io.github.cottonmc.clientcommands.ArgumentBuilders;
+import io.github.cottonmc.clientcommands.ClientCommands;
+import net.fabricmc.api.ClientModInitializer;
 import net.fabricmc.loader.api.FabricLoader;
-import net.minecraft.server.command.CommandManager;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 
-public class AshMod implements ModInitializer {
+public class AshMod implements ClientModInitializer {
 
     public static final String MOD_ID = "umollu_ash";
     public static AshConfig config;
 
     @Override
-    public void onInitialize() {
+    public void onInitializeClient() {
         String configPath = FabricLoader.getInstance().getConfigDirectory() + "/" + MOD_ID + ".json";
 
         Gson gson = new Gson();
@@ -51,18 +51,17 @@ public class AshMod implements ModInitializer {
             }
         }
 
-
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("toggleash")
-                        .executes(context -> {
-                            config.showHud = !config.showHud;
-                            config.saveConfig();
-                            return 1;
-                        })
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+            ArgumentBuilders.literal("toggleash")
+                    .executes(context -> {
+                        config.showHud = !config.showHud;
+                        config.saveConfig();
+                        return 1;
+                    })
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("togglefps")
+       ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("togglefps")
                         .executes(context -> {
                             config.showFps = !config.showFps;
                             config.saveConfig();
@@ -70,8 +69,8 @@ public class AshMod implements ModInitializer {
                         })
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("togglecoords")
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("togglecoords")
                         .executes(context -> {
                             config.showCoords = !config.showCoords;
                             config.saveConfig();
@@ -79,8 +78,8 @@ public class AshMod implements ModInitializer {
                         })
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("toggledirection")
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("toggledirection")
                         .executes(context -> {
                             config.showDirection = !config.showDirection;
                             config.saveConfig();
@@ -88,11 +87,11 @@ public class AshMod implements ModInitializer {
                         })
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("ashcolor")
-                        .then(CommandManager.argument("r", IntegerArgumentType.integer())
-                                .then(CommandManager.argument("g", IntegerArgumentType.integer())
-                                        .then(CommandManager.argument("b", IntegerArgumentType.integer())
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("ashcolor")
+                        .then(ArgumentBuilders.argument("r", IntegerArgumentType.integer())
+                                .then(ArgumentBuilders.argument("g", IntegerArgumentType.integer())
+                                        .then(ArgumentBuilders.argument("b", IntegerArgumentType.integer())
                                             .executes(context -> {
                                                 int r = IntegerArgumentType.getInteger(context,"r");
                                                 int g = IntegerArgumentType.getInteger(context,"g");
@@ -104,8 +103,8 @@ public class AshMod implements ModInitializer {
                                 }))))
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("resetash")
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("resetash")
                         .executes(context -> {
                             config = new AshConfig();
                             config.saveConfig();
@@ -113,21 +112,21 @@ public class AshMod implements ModInitializer {
                         })
         ));
 
-        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                CommandManager.literal("alignash")
-                        .then(CommandManager.literal("left")
+        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ArgumentBuilders.literal("alignash")
+                        .then(ArgumentBuilders.literal("left")
                         .executes(context -> {
                             config.align = 0;
                             config.saveConfig();
                             return 1;
                         }))
-                        .then(CommandManager.literal("center")
+                        .then(ArgumentBuilders.literal("center")
                         .executes(context -> {
                             config.align = 1;
                             config.saveConfig();
                             return 1;
                         }))
-                        .then(CommandManager.literal("right")
+                        .then(ArgumentBuilders.literal("right")
                         .executes(context -> {
                             config.align = 2;
                             config.saveConfig();

+ 10 - 7
src/main/resources/fabric.mod.json

@@ -1,16 +1,19 @@
 {
+  "schemaVersion": 1,
   "id": "umollu_ash",
   "name": "ASH - Another Simple HUD",
   "description": "ASH - Another Simple HUD with FPS count and coordinates.",
   "version": "${version}",
-  "side": "universal",
-  "initializers": [
-    "com.umollu.ash.AshMod"
-  ],
+  "environment": "*",
+  "entrypoints": {
+    "client": [
+      "com.umollu.ash.AshMod"
+    ]
+  },
   "requires": {
     "fabric": "*"
   },
-  "mixins": {
-    "client": "umollu_ash.client.json"
-  }
+  "mixins": [
+    "umollu_ash.mixins.json"
+  ]
 }

+ 2 - 1
src/main/resources/umollu_ash.client.json → src/main/resources/umollu_ash.mixins.json

@@ -2,7 +2,8 @@
   "required": true,
   "package": "com.umollu.ash.mixin",
   "compatibilityLevel": "JAVA_8",
-  "mixins": [
+  "minVersion": "0.7.11",
+  "client": [
     "GameRendererMixin"
   ],
   "injectors": {