Просмотр исходного кода

Updated project to a more modern flow; New version 1.1.3;

umollu 5 лет назад
Родитель
Сommit
f048d5e1e1

+ 8 - 9
build.gradle

@@ -1,5 +1,5 @@
 plugins {
-	id 'fabric-loom' version '0.2.2-SNAPSHOT'
+	id 'fabric-loom' version '0.2.6-SNAPSHOT'
 	id 'maven-publish'
 }
 
@@ -16,24 +16,23 @@ minecraft {
 repositories {
     maven {
         name "CottonMC"
-        url "http://server.bbkr.space:8081/artifactory/libs-snapshot"
+        url "https://server.bbkr.space/artifactory/libs-release"
     }
 }
 
 dependencies {
 	//to change the versions see the gradle.properties file
 	minecraft "com.mojang:minecraft:${project.minecraft_version}"
-	mappings "net.fabricmc:yarn:${project.yarn_mappings}"
-	modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
+	mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
+	modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
 
 	// Fabric API. This is technically optional, but you probably want it anyway.
-	modCompile "net.fabricmc:fabric:${project.fabric_version}"
+	modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
 
-    // Used for commands
-    modCompile "io.github.cottonmc:client-commands:${clientcommands_version}"
-    include "io.github.cottonmc:client-commands:${clientcommands_version}"
+	modImplementation "io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2"
+	include "io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2"
 
-	implementation 'com.google.code.gson:gson:2.8.5'
+	implementation 'com.google.code.gson:gson:2.8.6'
 }
 
 processResources {

+ 5 - 5
gradle.properties

@@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G
 
 # Fabric Properties
 	# check these on https://fabricmc.net/use
-	minecraft_version=1.14
-	yarn_mappings=1.14+build.3
-	loader_version=0.4.3+build.134
+	minecraft_version=1.15.2
+	yarn_mappings=1.15.2+build.14
+	loader_version=0.7.8+build.189
 
 # Mod Properties
-	mod_version = 1.1.2
+	mod_version = 1.1.3
 	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
+	fabric_version=0.5.1+build.294-1.15
 	clientcommands_version=0.2.1+1.14-pre5-SNAPSHOT

+ 2 - 3
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,5 @@
-#Sat Mar 09 18:58:18 GMT 2019
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
+zipStorePath=wrapper/dists

+ 120 - 0
src/main/java/com/umollu/ash/AshCommands.java

@@ -0,0 +1,120 @@
+package com.umollu.ash;
+
+import com.google.gson.Gson;
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
+import io.github.cottonmc.clientcommands.ArgumentBuilders;
+import io.github.cottonmc.clientcommands.ClientCommandPlugin;
+import io.github.cottonmc.clientcommands.CottonClientCommandSource;
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+
+import static com.umollu.ash.AshMod.MOD_ID;
+
+public class AshCommands implements ClientCommandPlugin {
+
+    public static AshConfig config;
+
+    @Override
+    public void registerCommands(CommandDispatcher<CottonClientCommandSource> commandDispatcher) {
+
+        String configPath = FabricLoader.getInstance().getConfigDirectory() + "/" + MOD_ID + ".json";
+
+        Gson gson = new Gson();
+
+        File configFile = new File(configPath);
+
+        if(!configFile.exists()) {
+            config = new AshConfig();
+            String result = gson.toJson(config);
+            try {
+                FileOutputStream out = new FileOutputStream(configFile, false);
+
+                out.write(result.getBytes());
+                out.flush();
+                out.close();
+
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        else {
+
+            try {
+                config = gson.fromJson( new FileReader(configFile), AshConfig.class);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            finally {
+                config = (config == null? new AshConfig() : config);
+            }
+        }
+
+
+        commandDispatcher.register(ArgumentBuilders.literal("toggleash")
+            .executes(context -> {
+                config.showHud = !config.showHud;
+                config.saveConfig();
+                return 1;
+            }));
+
+        commandDispatcher.register(ArgumentBuilders.literal("togglecoords")
+            .executes(context -> {
+                config.showCoords = !config.showCoords;
+                config.saveConfig();
+                return 1;
+            }));
+
+        commandDispatcher.register(ArgumentBuilders.literal("toggledirection")
+            .executes(context -> {
+                config.showDirection = !config.showDirection;
+                config.saveConfig();
+                return 1;
+            }));
+
+        commandDispatcher.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");
+                                        int b = IntegerArgumentType.getInteger(context,"b");
+
+                                        config.hudColor = b + (g << 8) + (r << 16);
+                                        config.saveConfig();
+                                        return 1;
+                                    })))));
+
+        commandDispatcher.register(ArgumentBuilders.literal("resetash")
+            .executes(context -> {
+                config = new AshConfig();
+                config.saveConfig();
+                return 1;
+            }));
+
+        commandDispatcher.register(ArgumentBuilders.literal("alignash")
+            .then(ArgumentBuilders.literal("left")
+                    .executes(context -> {
+                        config.align = 0;
+                        config.saveConfig();
+                        return 1;
+                    }))
+            .then(ArgumentBuilders.literal("center")
+                    .executes(context -> {
+                        config.align = 1;
+                        config.saveConfig();
+                        return 1;
+                    }))
+            .then(ArgumentBuilders.literal("right")
+                    .executes(context -> {
+                        config.align = 2;
+                        config.saveConfig();
+                        return 1;
+                    })));
+    }
+}

+ 0 - 125
src/main/java/com/umollu/ash/AshMod.java

@@ -1,137 +1,12 @@
 package com.umollu.ash;
 
-import com.google.gson.Gson;
-import com.mojang.brigadier.arguments.IntegerArgumentType;
-import io.github.cottonmc.clientcommands.ArgumentBuilders;
-import io.github.cottonmc.clientcommands.ClientCommands;
 import net.fabricmc.api.ClientModInitializer;
-import net.fabricmc.loader.api.FabricLoader;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
 
 public class AshMod implements ClientModInitializer {
 
     public static final String MOD_ID = "umollu_ash";
-    public static AshConfig config;
 
     @Override
     public void onInitializeClient() {
-        String configPath = FabricLoader.getInstance().getConfigDirectory() + "/" + MOD_ID + ".json";
-
-        Gson gson = new Gson();
-
-        File configFile = new File(configPath);
-
-        if(!configFile.exists()) {
-            config = new AshConfig();
-            String result = gson.toJson(config);
-            try {
-                FileOutputStream out = new FileOutputStream(configFile, false);
-
-                out.write(result.getBytes());
-                out.flush();
-                out.close();
-
-            } catch (IOException ex) {
-                ex.printStackTrace();
-            }
-        }
-        else {
-
-            try {
-                config = gson.fromJson( new FileReader(configFile), AshConfig.class);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            finally {
-                config = (config == null? new AshConfig() : config);
-            }
-        }
-
-        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-            ArgumentBuilders.literal("toggleash")
-                    .executes(context -> {
-                        config.showHud = !config.showHud;
-                        config.saveConfig();
-                        return 1;
-                    })
-        ));
-
-       ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                ArgumentBuilders.literal("togglefps")
-                        .executes(context -> {
-                            config.showFps = !config.showFps;
-                            config.saveConfig();
-                            return 1;
-                        })
-        ));
-
-        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                ArgumentBuilders.literal("togglecoords")
-                        .executes(context -> {
-                            config.showCoords = !config.showCoords;
-                            config.saveConfig();
-                            return 1;
-                        })
-        ));
-
-        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                ArgumentBuilders.literal("toggledirection")
-                        .executes(context -> {
-                            config.showDirection = !config.showDirection;
-                            config.saveConfig();
-                            return 1;
-                        })
-        ));
-
-        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");
-                                                int b = IntegerArgumentType.getInteger(context,"b");
-
-                                                config.hudColor = b + (g << 8) + (r << 16);
-                                                config.saveConfig();
-                                                return 1;
-                                }))))
-        ));
-
-        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                ArgumentBuilders.literal("resetash")
-                        .executes(context -> {
-                            config = new AshConfig();
-                            config.saveConfig();
-                            return 1;
-                        })
-        ));
-
-        ClientCommands.registerCommand(serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
-                ArgumentBuilders.literal("alignash")
-                        .then(ArgumentBuilders.literal("left")
-                        .executes(context -> {
-                            config.align = 0;
-                            config.saveConfig();
-                            return 1;
-                        }))
-                        .then(ArgumentBuilders.literal("center")
-                        .executes(context -> {
-                            config.align = 1;
-                            config.saveConfig();
-                            return 1;
-                        }))
-                        .then(ArgumentBuilders.literal("right")
-                        .executes(context -> {
-                            config.align = 2;
-                            config.saveConfig();
-                            return 1;
-                        }))
-        ));
     }
 }

+ 16 - 20
src/main/java/com/umollu/ash/mixin/GameRendererMixin.java

@@ -1,13 +1,11 @@
 package com.umollu.ash.mixin;
 
-import com.umollu.ash.AshMod;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.umollu.ash.AshCommands;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.render.GameRenderer;
 import net.minecraft.entity.Entity;
 import net.minecraft.util.math.BlockPos;
-
-import com.mojang.blaze3d.platform.GlStateManager;
-
 import net.minecraft.util.math.Direction;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.injection.At;
@@ -17,40 +15,38 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 @Mixin(GameRenderer.class)
 public class GameRendererMixin {
 
-	@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;alphaFunc(IF)V"), method = "render")
+	@Inject(at = @At(value = "INVOKE", target = "com/mojang/blaze3d/systems/RenderSystem.defaultAlphaFunc()V"), method = "render")
 	public void render(float float_1, long long_1, boolean boolean_1, CallbackInfo info) {
 
 		MinecraftClient client = MinecraftClient.getInstance();
 		Entity cameraEntity = client.getCameraEntity();
 
-		if(!client.options.debugEnabled && AshMod.config.showHud) {
-			double scaleFactor = client.window.getScaleFactor();
-			GlStateManager.pushMatrix();
-			GlStateManager.scaled(1 * scaleFactor, 1 * scaleFactor, 1 * scaleFactor);
+		if(!client.options.debugEnabled && AshCommands.config.showHud) {
+			RenderSystem.pushMatrix();
 			String ashString = "";
-			if(AshMod.config.showFps) {
-				ashString += String.format("%d fps ", MinecraftClient.getCurrentFps());
+			if(AshCommands.config.showFps) {
+				ashString += String.format("%d fps ", ((MinecraftClientMixin) MinecraftClient.getInstance()).getCurrentFps());
 			}
-			if(AshMod.config.showCoords) {
-				BlockPos blockPos = new BlockPos(cameraEntity.x, cameraEntity.getBoundingBox().minY, cameraEntity.z);
+			if(AshCommands.config.showCoords) {
+				BlockPos blockPos = new BlockPos(cameraEntity.getX(), cameraEntity.getBoundingBox().getMin(Direction.Axis.Y), cameraEntity.getZ());
 				ashString += String.format("%d %d %d ", blockPos.getX(), blockPos.getY(), blockPos.getZ());
 			}
-			if(AshMod.config.showDirection) {
+			if(AshCommands.config.showDirection) {
 				Direction direction = cameraEntity.getHorizontalFacing();
 				ashString += String.format("%5s ", direction);
 			}
 
 			float textPosX = 5;
 
-			if (AshMod.config.align == 1) {
-				textPosX = (client.window.getScaledWidth() - client.textRenderer.getStringWidth(ashString)) / 2f - textPosX;
+			if (AshCommands.config.align == 1) {
+				textPosX = (client.getWindow().getScaledWidth() - client.textRenderer.getStringWidth(ashString)) / 2f - textPosX;
 			}
-			if (AshMod.config.align == 2) {
-				textPosX = client.window.getScaledWidth() - client.textRenderer.getStringWidth(ashString) - textPosX;
+			if (AshCommands.config.align == 2) {
+				textPosX = client.getWindow().getScaledWidth() - client.textRenderer.getStringWidth(ashString) - textPosX;
 			}
 
-			client.textRenderer.drawWithShadow(ashString, textPosX, 5, AshMod.config.hudColor);
-			GlStateManager.popMatrix();
+			client.textRenderer.drawWithShadow(ashString, textPosX, 5, AshCommands.config.hudColor);
+			RenderSystem.popMatrix();
 		}
 	}
 }

+ 11 - 0
src/main/java/com/umollu/ash/mixin/MinecraftClientMixin.java

@@ -0,0 +1,11 @@
+package com.umollu.ash.mixin;
+
+import net.minecraft.client.MinecraftClient;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(MinecraftClient.class)
+public interface MinecraftClientMixin {
+	@Accessor("currentFps")
+	public abstract int getCurrentFps();
+}

+ 5 - 3
src/main/resources/fabric.mod.json

@@ -8,10 +8,12 @@
   "entrypoints": {
     "client": [
       "com.umollu.ash.AshMod"
-    ]
+    ],
+    "cotton-client-commands": ["com.umollu.ash.AshCommands"]
   },
-  "requires": {
-    "fabric": "*"
+  "depends": {
+    "fabric": "*",
+    "cotton-client-commands": "^1.0.0"
   },
   "mixins": [
     "umollu_ash.mixins.json"

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

@@ -4,7 +4,8 @@
   "compatibilityLevel": "JAVA_8",
   "minVersion": "0.7.11",
   "client": [
-    "GameRendererMixin"
+    "GameRendererMixin",
+    "MinecraftClientMixin"
   ],
   "injectors": {
     "defaultRequire": 1