Procházet zdrojové kódy

Add Tooltip and German translation

d4rkm0nkey před 4 roky
rodič
revize
9bd3ea16e1

+ 9 - 1
build.gradle

@@ -10,6 +10,13 @@ archivesBaseName = project.archives_base_name
 version = project.mod_version
 group = project.maven_group
 
+repositories {
+    maven {
+        name = "CottonMC"
+        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}"
@@ -19,6 +26,7 @@ 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"
+	modImplementation "io.github.cottonmc:LibGui:3.0.0-beta.1+1.16.2-rc2"
 	modApi("me.shedaniel.cloth:config-2:4.8.1") {
         exclude(group: "net.fabricmc.fabric-api")
     }
@@ -27,7 +35,7 @@ dependencies {
     }
 	include "me.shedaniel.cloth:config-2:4.8.1"
 	include "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
-
+	include "io.github.cottonmc:LibGui:3.0.0-beta.1+1.16.2-rc2"
 	// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
 	// You may need to force-disable transitiveness on them.
 }

+ 1 - 1
gradle.properties

@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
 	loader_version=0.9.2+build.206
 
 # Mod Properties
-	mod_version = 4.0.0
+	mod_version = 4.1.0
 	maven_group = monkey.lumpy
 	archives_base_name = horse-stats-vanilla
 

+ 8 - 2
src/main/java/monkey/lumpy/horse/stats/vanilla/config/ModConfig.java

@@ -7,9 +7,11 @@ import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
 @Config(name = "horsestatsvanilla")
 public class ModConfig implements ConfigData {
     @ConfigEntry.Gui.Tooltip
-    boolean useColors = true;
+    private boolean useColors = true;
     @ConfigEntry.Gui.Tooltip
-    boolean showMaxMin = true;
+    private boolean showMaxMin = true;
+    @ConfigEntry.Gui.Tooltip
+    private boolean enableTooltip = true;
 
     public boolean useColors() {
         return useColors;
@@ -18,5 +20,9 @@ public class ModConfig implements ConfigData {
     public boolean showMaxMin() {
         return showMaxMin;
     }
+
+    public boolean isTooltipEnabled() {
+        return enableTooltip;
+    }
     
 }

+ 28 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/gui/ToolTipGui.java

@@ -0,0 +1,28 @@
+package monkey.lumpy.horse.stats.vanilla.gui;
+
+import io.github.cottonmc.cotton.gui.GuiDescription;
+import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
+
+public class ToolTipGui extends CottonClientScreen {
+
+    public ToolTipGui(GuiDescription description) {
+        super(description);
+    }
+
+    @Override
+    public boolean keyPressed(int ch, int keyCode, int modifiers) {
+        if(keyCode == 26) {
+            onClose();
+        }
+        return super.keyPressed(ch, keyCode, modifiers);
+    }
+
+    @Override
+    public boolean keyReleased(int ch, int keyCode, int modifiers) {
+        if(keyCode == 50) {
+            onClose();
+        }
+        return super.keyReleased(ch, keyCode, modifiers);
+    }
+    
+}

+ 97 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/gui/Tooltip.java

@@ -0,0 +1,97 @@
+package monkey.lumpy.horse.stats.vanilla.gui;
+
+import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
+import io.github.cottonmc.cotton.gui.widget.WBox;
+import io.github.cottonmc.cotton.gui.widget.WLabel;
+import io.github.cottonmc.cotton.gui.widget.data.Axis;
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+import net.minecraft.text.LiteralText;
+
+public class Tooltip extends LightweightGuiDescription {
+    private final int normalColor = 4210752;
+    private final int badColor = 16733525;
+    private final int goodColor = 43520;
+    private ModConfig config;
+
+    public Tooltip(double speed, double jump, int health, Integer strength) {
+        config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
+        WBox root = new WBox(Axis.VERTICAL);
+        setRootPanel(root);
+        root.setSpacing(-8);
+        
+        // Coloring
+        int jumpColor = normalColor;
+        int speedColor = normalColor;
+        int hearthColor = normalColor;
+        if(config == null || config.useColors()) {
+            if(jump > 4) {jumpColor = goodColor;}
+            else if (jump < 2.5) {jumpColor = badColor;};
+    
+            if(speed > 11) {speedColor = goodColor;} 
+            else if (speed < 7) {speedColor = badColor;};
+    
+            if(health> 25) {hearthColor = goodColor;} 
+            else if (health < 20) {hearthColor = badColor;};
+        }
+
+        WBox speedBox = new WBox(Axis.HORIZONTAL);
+        
+        WLabel speedSymbol = new WLabel(new LiteralText("➟"), speedColor);
+        WLabel speedLabel = new WLabel(new LiteralText("" + speed), speedColor);
+        // WLabel speedRange = new WLabel(new LiteralText("(4.8-14.5)"), normalColor);
+        
+        // speedSymbol.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        speedBox.add(speedSymbol);
+        speedBox.add(speedLabel);
+        // speedBox.add(speedRange);
+
+        WBox jumpBox = new WBox(Axis.HORIZONTAL);
+        
+        WLabel jumpSymbol = new WLabel(new LiteralText("⇮"), jumpColor);
+        WLabel jumpLabel = new WLabel(new LiteralText("" + jump), jumpColor);
+        // WLabel jumpRange = new WLabel(new LiteralText("(1-5.1)"), normalColor);
+        
+        // jumpSymbol.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        jumpBox.add(jumpSymbol);
+        jumpBox.add(jumpLabel);
+        // jumpBox.add(jumpRange);
+
+        WBox healthBox = new WBox(Axis.HORIZONTAL);
+        
+        WLabel healthSymbol = new WLabel(new LiteralText("♥"), hearthColor);
+        WLabel healthLabel = new WLabel(new LiteralText("" + health), hearthColor);
+        // WLabel healthRange = new WLabel(new LiteralText("(15-30)"), normalColor);
+        
+        // healthSymbol.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        healthBox.add(healthSymbol);
+        healthBox.add(healthLabel);
+        // healthBox.add(healthRange);
+
+        root.add(speedBox);
+        root.add(jumpBox);
+        root.add(healthBox);
+
+        if(strength != null) {
+            int strengthColor = normalColor;
+            if(config == null || config.useColors()) {
+                if(strength > 9) {strengthColor = goodColor;} 
+                else if (strength < 6) {strengthColor = badColor;};
+            }
+
+            WBox strengthBox = new WBox(Axis.HORIZONTAL);
+            WLabel strengthSymbol = new WLabel(new LiteralText("▦"), strengthColor);
+            WLabel strengthLabel = new WLabel(new LiteralText("" + strength), strengthColor);
+            strengthBox.add(strengthSymbol);
+            strengthBox.add(strengthLabel);
+
+            root.add(strengthBox);
+        }
+
+        root.validate(this);
+
+    }
+}

+ 68 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/mixin/AbstractDonkeyEntityMixin.java

@@ -0,0 +1,68 @@
+package monkey.lumpy.horse.stats.vanilla.mixin;
+
+import com.ibm.icu.math.BigDecimal;
+import com.ibm.icu.text.DecimalFormat;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+import monkey.lumpy.horse.stats.vanilla.gui.ToolTipGui;
+import monkey.lumpy.horse.stats.vanilla.gui.Tooltip;
+
+import org.spongepowered.asm.mixin.injection.At;
+
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.entity.EntityType;
+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.PlayerEntity;
+import net.minecraft.util.ActionResult;
+import net.minecraft.util.Hand;
+import net.minecraft.world.World;
+
+@Mixin(AbstractDonkeyEntity.class)
+public class AbstractDonkeyEntityMixin extends HorseBaseEntity {
+
+    private ModConfig config;
+
+    protected AbstractDonkeyEntityMixin(EntityType<? extends HorseBaseEntity> entityType, World world) {
+        super(entityType, world);
+    }
+
+    @Inject(at = @At("HEAD"), method = "interactMob")
+    public ActionResult interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> ret) {
+        if(config == null) {
+            config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
+        }
+        
+        if (this.world.isClient && !this.isTame() && player.shouldCancelInteraction() && (config == null || config.isTooltipEnabled())) {
+            // Show tooltip
+            DecimalFormat df = new DecimalFormat("#.#");
+            String jumpstrength = df.format( 0.695 * (this.getJumpStrength() * 10) - 1.736);
+            String maxHealth = df.format(this.getMaxHealth());
+            String speed = df.format( 0.42466 * (this.getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) * 100) + 0.112665);            
+            
+            double jumpValue = new BigDecimal(jumpstrength.replace(',', '.')).doubleValue();
+            double speedValue = new BigDecimal(speed.replace(',', '.')).doubleValue();
+            int healthValue = new BigDecimal(maxHealth).intValue();
+            
+            Integer strength = null;
+            if (LlamaEntity.class.isAssignableFrom(this.getClass())) {
+                strength = 3 * this.getStrength();
+            }
+            MinecraftClient.getInstance().openScreen(
+                new ToolTipGui(new Tooltip(speedValue, jumpValue, healthValue, strength))
+            );
+        }
+        return ret.getReturnValue();
+    }
+
+    public int getStrength() {
+        return 0;
+    }
+}

+ 60 - 0
src/main/java/monkey/lumpy/horse/stats/vanilla/mixin/HorseEntityMixin.java

@@ -0,0 +1,60 @@
+package monkey.lumpy.horse.stats.vanilla.mixin;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+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.CallbackInfoReturnable;
+
+import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
+import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
+import monkey.lumpy.horse.stats.vanilla.gui.ToolTipGui;
+import monkey.lumpy.horse.stats.vanilla.gui.Tooltip;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.entity.EntityType;
+import net.minecraft.entity.attribute.EntityAttributes;
+import net.minecraft.entity.passive.HorseBaseEntity;
+import net.minecraft.entity.passive.HorseEntity;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.util.ActionResult;
+import net.minecraft.util.Hand;
+import net.minecraft.world.World;
+
+@Mixin(HorseEntity.class)
+public abstract class HorseEntityMixin extends HorseBaseEntity {
+
+    private ModConfig config;
+
+    protected HorseEntityMixin(EntityType<? extends HorseBaseEntity> entityType, World world) {
+        super(entityType, world);
+    }
+
+
+    @Inject(at = @At("HEAD"), method = "interactMob")
+    public ActionResult interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> ret) {
+        if(config == null) {
+            config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
+        }
+        
+        if (this.world.isClient && !this.isTame() && player.shouldCancelInteraction() && (config == null || config.isTooltipEnabled())) {
+            // Show tooltip
+            DecimalFormat df = new DecimalFormat("#.#");
+            String jumpstrength = df.format( 0.695 * (this.getJumpStrength() * 10) - 1.736);
+            String maxHealth = df.format(this.getMaxHealth());
+            String speed = df.format( 0.42466 * (this.getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) * 100) + 0.112665);            
+            
+            double jumpValue = new BigDecimal(jumpstrength.replace(',', '.')).doubleValue();
+            double speedValue = new BigDecimal(speed.replace(',', '.')).doubleValue();
+            int healthValue = new BigDecimal(maxHealth.replace(',', '.')).intValue();
+            // while (player.isSneaking()) showTooltip
+
+
+            MinecraftClient.getInstance().openScreen(
+                new ToolTipGui(new Tooltip(speedValue, jumpValue, healthValue, null))
+            );
+        }
+        return ret.getReturnValue();
+    }
+}

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

@@ -25,6 +25,7 @@ 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;
@@ -38,7 +39,6 @@ public abstract class HorseScreenMixin extends HandledScreen<HorseScreenHandler>
         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()) {
@@ -56,7 +56,7 @@ public abstract class HorseScreenMixin extends HandledScreen<HorseScreenHandler>
         if(config.useColors()) {
             double jumpValue = new BigDecimal(jumpstrength.replace(',', '.')).doubleValue();
             double speedValue = new BigDecimal(speed.replace(',', '.')).doubleValue();
-            int healthValue = new BigDecimal(maxHealth).intValue();
+            int healthValue = new BigDecimal(maxHealth.replace(',', '.')).intValue();
     
             if(jumpValue > 4) {jumpColor = goodColor;}
             else if (jumpValue < 2.5) {jumpColor = badColor;};
@@ -98,8 +98,8 @@ public abstract class HorseScreenMixin extends HandledScreen<HorseScreenHandler>
             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(strength > 9) {strengthColor = goodColor;} 
+                else if (strength < 6) {strengthColor = badColor;};
             }
             if (!hasChest) {
                 this.textRenderer.draw(matrices, "▦", 91.0F, 56.0F, strengthColor);

+ 9 - 0
src/main/resources/assets/horsestatsvanilla/lang/de_de.json

@@ -0,0 +1,9 @@
+{
+    "text.autoconfig.horsestatsvanilla.title": "HorseStatsVanilla Einstellungen", 
+    "text.autoconfig.horsestatsvanilla.option.useColors": "Farben benutzen",
+    "text.autoconfig.horsestatsvanilla.option.showMaxMin": "Maximal- und Minimalwerte anzeigen",
+    "text.autoconfig.horsestatsvanilla.option.enableTooltip": "Tooltip aktivieren",
+    "text.autoconfig.horsestatsvanilla.option.useColors.@Tooltip": "Schlechte Werte werden rot und gute Werte grün dargestellt.",
+    "text.autoconfig.horsestatsvanilla.option.showMaxMin.@Tooltip": "Maximal- und Minimalwerte anzeigen.",
+    "text.autoconfig.horsestatsvanilla.option.enableTooltip.@Tooltip": "Tooltip anzeigen bei Shift + Rechtsklick auf ein Pferd."
+}

+ 3 - 1
src/main/resources/assets/horsestatsvanilla/lang/en_us.json

@@ -2,6 +2,8 @@
     "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.enableTooltip": "Enable Tooltip",
     "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."
+    "text.autoconfig.horsestatsvanilla.option.showMaxMin.@Tooltip": "Display max and min values.",
+    "text.autoconfig.horsestatsvanilla.option.enableTooltip.@Tooltip": "Show a tooltip when right-clicking on a horse while sneaking"
 }

+ 3 - 1
src/main/resources/horsestatsvanilla.mixins.json

@@ -4,7 +4,9 @@
   "compatibilityLevel": "JAVA_8",
   "mixins": [],
   "client": [
-    "HorseScreenMixin"
+    "HorseScreenMixin",
+    "HorseEntityMixin",
+    "AbstractDonkeyEntityMixin"
   ],
   "injectors": {
     "defaultRequire": 1