Prechádzať zdrojové kódy

Refactoring, Modmenu integration, coloring

d4rkm0nkey 4 rokov pred
rodič
commit
8b5c6726d4

+ 10 - 0
build.gradle

@@ -18,6 +18,15 @@ dependencies {
 
 	// Fabric API. This is technically optional, but you probably want it anyway.
 	modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
+	modImplementation "io.github.prospector:modmenu:1.14.6+build.31"
+	modApi("me.shedaniel.cloth:config-2:4.8.1") {
+        exclude(group: "net.fabricmc.fabric-api")
+    }
+	modApi("me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable") {
+        exclude(group: "net.fabricmc.fabric-api")
+    }
+	include "me.shedaniel.cloth:config-2:4.8.1"
+	include "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
 
 	// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
 	// You may need to force-disable transitiveness on them.
@@ -73,5 +82,6 @@ publishing {
 	repositories {
 		// uncomment to publish to the local maven
 		// mavenLocal()
+		jcenter()
 	}
 }

+ 12 - 9
gradle.properties

@@ -1,14 +1,17 @@
 # Done to increase the memory available to gradle.
 org.gradle.jvmargs=-Xmx1G
+
 # Fabric Properties
-# check these on https://fabricmc.net/use
-minecraft_version=1.16.1
-yarn_mappings=1.16.1+build.19
-loader_version=0.8.9+build.203
+	# check these on https://fabricmc.net/use
+	minecraft_version=1.16.2
+	yarn_mappings=1.16.2+build.31
+	loader_version=0.9.2+build.206
+
 # Mod Properties
-mod_version=3.0.0
-maven_group=net.fabricmc
-archives_base_name=horse-stats-vanilla
+	mod_version = 4.0.0
+	maven_group = monkey.lumpy
+	archives_base_name = horse-stats-vanilla
+
 # Dependencies
-# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
-fabric_version=0.14.2+build.373-1.16
+	# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
+	fabric_version=0.19.0+build.398-1.16

+ 13 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/HorseStatsVanilla.java

@@ -0,0 +1,13 @@
+package monkey.lumpy.horse.stats.vanilla;
+
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
+import net.fabricmc.api.ModInitializer;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+
+public class HorseStatsVanilla implements ModInitializer {
+    @Override
+    public void onInitialize() {
+        AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
+    }
+}

+ 22 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/ModMenuApiImpl.java

@@ -0,0 +1,22 @@
+package monkey.lumpy.horse.stats.vanilla;
+
+import io.github.prospector.modmenu.api.ConfigScreenFactory;
+import io.github.prospector.modmenu.api.ModMenuApi;
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+import net.fabricmc.api.Environment;
+import net.fabricmc.api.EnvType;
+
+@Environment(EnvType.CLIENT)
+public class ModMenuApiImpl implements ModMenuApi {
+
+    @Override
+    public String getModId() {
+        return "horsestatsvanilla";
+    }
+
+    @Override
+    public ConfigScreenFactory<?> getModConfigScreenFactory() {
+        return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get();
+    }
+}

+ 22 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/config/ModConfig.java

@@ -0,0 +1,22 @@
+package monkey.lumpy.horse.stats.vanilla.config;
+
+import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
+import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
+import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
+
+@Config(name = "horsestatsvanilla")
+public class ModConfig implements ConfigData {
+    @ConfigEntry.Gui.Tooltip
+    boolean useColors = true;
+    @ConfigEntry.Gui.Tooltip
+    boolean showMaxMin = true;
+
+    public boolean useColors() {
+        return useColors;
+    }
+
+    public boolean showMaxMin() {
+        return showMaxMin;
+    }
+    
+}

+ 110 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/mixin/HorseScreenMixin.java

@@ -0,0 +1,110 @@
+package monkey.lumpy.horse.stats.vanilla.mixin;
+
+import net.minecraft.client.gui.screen.ingame.HandledScreen;
+import net.minecraft.client.gui.screen.ingame.HorseScreen;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.entity.attribute.EntityAttributes;
+import net.minecraft.entity.passive.AbstractDonkeyEntity;
+import net.minecraft.entity.passive.HorseBaseEntity;
+import net.minecraft.entity.passive.LlamaEntity;
+import net.minecraft.entity.player.PlayerInventory;
+import net.minecraft.screen.HorseScreenHandler;
+import net.minecraft.text.Text;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+@Mixin(HorseScreen.class)
+public abstract class HorseScreenMixin extends HandledScreen<HorseScreenHandler> {
+    @Shadow
+    @Final
+    private HorseBaseEntity entity;
+    private final int normalColor = 4210752;
+    private final int badColor = 16733525;
+    private final int goodColor = 43520;
+    private ModConfig config;
+
+    public HorseScreenMixin(HorseScreenHandler handler, PlayerInventory inventory, Text title) {
+        super(handler, inventory, title);
+    }
+
+    protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) {
+        super.drawForeground(matrices, mouseX, mouseY);
+        if(config == null) {
+            config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
+            System.out.println(config == null);
+        }
+        boolean hasChest = false;
+        if (AbstractDonkeyEntity.class.isAssignableFrom(this.entity.getClass()) && ((AbstractDonkeyEntity) this.entity).hasChest()) {
+            hasChest = true;
+        }
+        DecimalFormat df = new DecimalFormat("#.#");
+        String jumpstrength = df.format( 0.695 * (this.entity.getJumpStrength() * 10) - 1.736);
+        String maxHealth = df.format(this.entity.getMaxHealth());
+        String speed = df.format( 0.42466 * (this.entity.getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) * 100) + 0.112665);
+
+        // Coloring
+        int jumpColor = normalColor;
+        int speedColor = normalColor;
+        int hearthColor = normalColor;
+        if(config.useColors()) {
+            double jumpValue = new BigDecimal(jumpstrength.replace(',', '.')).doubleValue();
+            double speedValue = new BigDecimal(speed.replace(',', '.')).doubleValue();
+            int healthValue = new BigDecimal(maxHealth).intValue();
+    
+            if(jumpValue > 4) {jumpColor = goodColor;}
+            else if (jumpValue < 2.5) {jumpColor = badColor;};
+    
+            if(speedValue > 11) {speedColor = goodColor;} 
+            else if (speedValue < 7) {speedColor = badColor;};
+    
+            if(healthValue > 25) {hearthColor = goodColor;} 
+            else if (healthValue < 20) {hearthColor = badColor;};
+        }
+
+
+        if (!hasChest) {
+            float spacer = 1.0F;
+            if(config.showMaxMin()) {
+                this.textRenderer.draw(matrices, "(4.8-14.5)", 119.0F, 26.0F, normalColor);
+                this.textRenderer.draw(matrices, "(1-5.1)", 119.0F, 36.0F, normalColor);
+                this.textRenderer.draw(matrices, "(15-30)", 119.0F, 46.0F, normalColor);
+            } else {
+                spacer = 10.0F;
+            }
+            this.textRenderer.draw(matrices, "➟", 82.0F + spacer, 26.0F, speedColor);
+            this.textRenderer.draw(matrices, "" + speed, 93.0F + spacer, 26.0F, speedColor);
+            
+            this.textRenderer.draw(matrices, "⇮", 84.0F + spacer, 36.0F, jumpColor);
+            this.textRenderer.draw(matrices, "" + jumpstrength, 93.0F + spacer, 36.0F, jumpColor);
+            this.textRenderer.draw(matrices, "♥", 83.0F + spacer, 46.0F, hearthColor);
+            this.textRenderer.draw(matrices, "" + maxHealth, 93.0F + spacer, 46.0F, hearthColor);
+
+        } else {
+            this.textRenderer.draw(matrices, "➟ " + speed, 80.0F, 6.0F, speedColor);
+            this.textRenderer.draw(matrices, "⇮ " + jumpstrength, 115.0F, 6.0F, jumpColor);
+            this.textRenderer.draw(matrices, "♥️ " + maxHealth, 140.0F, 6.0F, hearthColor);
+        }
+
+        int strengthColor = normalColor;
+
+        if (LlamaEntity.class.isAssignableFrom(this.entity.getClass())) {
+            int strength = 3 * ((LlamaEntity) this.entity).getStrength();
+
+            if(config.useColors()) {
+                if(new BigDecimal(strength).doubleValue() > 9) {strengthColor = goodColor;} 
+                else if (new BigDecimal(strength).doubleValue() < 6) {strengthColor = badColor;};
+            }
+            if (!hasChest) {
+                this.textRenderer.draw(matrices, "▦", 91.0F, 56.0F, strengthColor);
+                this.textRenderer.draw(matrices, "" + strength, 100.0F, 56.0F, strengthColor);
+            }
+        }
+    }
+}

+ 7 - 0
src/main/resources/assets/horsestatsvanilla/lang/en_us.json

@@ -0,0 +1,7 @@
+{
+    "text.autoconfig.horsestatsvanilla.title": "HorseStatsVanilla Config", 
+    "text.autoconfig.horsestatsvanilla.option.useColors": "Use colors",
+    "text.autoconfig.horsestatsvanilla.option.showMaxMin": "Show max and min",
+    "text.autoconfig.horsestatsvanilla.option.useColors.@Tooltip": "Highlight weak values red and good values green.",
+    "text.autoconfig.horsestatsvanilla.option.showMaxMin.@Tooltip": "Display max and min values."
+}

+ 9 - 4
src/main/resources/fabric.mod.json

@@ -3,17 +3,22 @@
   "id": "horsestatsvanilla",
   "version": "${version}",
   "name": "Horse Stats Vanilla",
-  "description": "Shows horse stats in the horse inventory. The style is fiting the vanilla game.",
+  "description": "Shows horse stats in the horse inventory.",
   "authors": [
     "lumpyMonkey"
   ],
+  "contact": {
+    "homepage": "https://www.curseforge.com/minecraft/mc-mods/horsestatsvanilla",
+    "sources": "https://github.com/d4rkm0nkey/HorseStatsVanilla"
+  },
   "license": "CC0-1.0",
   "icon": "assets/horsestatsvanilla/icon.png",
   "environment": "*",
   "entrypoints": {
     "main": [
-      "net.horse.stats.vanilla.HorseStatsVanilla"
-    ]
+      "monkey.lumpy.horse.stats.vanilla.HorseStatsVanilla"
+    ],
+    "modmenu": [ "monkey.lumpy.horse.stats.vanilla.ModMenuApiImpl" ] 
   },
   "mixins": [
     "horsestatsvanilla.mixins.json"
@@ -27,4 +32,4 @@
     "flamingo": "*"
   },
   "custom": { "modmenu:clientsideOnly": true }
-}
+}

+ 2 - 2
src/main/resources/horsestatsvanilla.mixins.json

@@ -1,6 +1,6 @@
 {
   "required": true,
-  "package": "net.horse.stats.vanilla.mixin",
+  "package": "monkey.lumpy.horse.stats.vanilla.mixin",
   "compatibilityLevel": "JAVA_8",
   "mixins": [],
   "client": [
@@ -9,4 +9,4 @@
   "injectors": {
     "defaultRequire": 1
   }
-}
+}