diff --git a/README.md b/README.md index b3ae2a0..26f11c3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is a Minecraft mod that overlays a timer on the Vanilla status effect HUD icons. -This mod requires Minecraft 1.16.5-1.19 and the Fabric loader. +This mod requires Minecraft 1.16.5-1.20 and the Fabric loader. This mod overlays the number of seconds left of the status effect, or the number of minutes (followed by "m") if it is more than 60 seconds, on the vanilla status effect indicator. If the effect has an amplifier (as in "Haste II"), the amplifier is also overlaid. That's it. This is a very minimalistic mod. No settings are required nor provided. @@ -25,7 +25,7 @@ This is what it looks like when you are using the mod. The latest version is 1.1.1. -Direct download links for Minecraft 1.19: +Direct download links for Minecraft 1.20: * Download from GitHub: [statuseffecttimer-1.1.1+1.19.jar](https://github.com/magicus/statuseffecttimer/releases/download/v1.1.1%2B1.19/statuseffecttimer-1.1.1+1.19.jar) * Download from Modrinth: [statuseffecttimer-1.1.1+1.19.jar](https://cdn.modrinth.com/data/T9FDHbY5/versions/1.1.1+1.19/statuseffecttimer-1.1.1%2B1.19.jar) diff --git a/gradle.properties b/gradle.properties index f1a1cfa..b1a31d8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.19 -yarn_mappings=1.19+build.2 -loader_version=0.14.7 +minecraft_version=1.20 +yarn_mappings=1.20+build.1 +loader_version=0.15.6 # Mod Properties mod_version = 1.1.1+1.19 @@ -14,4 +14,4 @@ archives_base_name = statuseffecttimer # Dependencies # Fabric api -fabric_version=0.56.0+1.19 +fabric_version=0.83.0+1.20 diff --git a/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java b/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java index f7aa203..df13910 100644 --- a/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java +++ b/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java @@ -1,13 +1,13 @@ package se.icus.mag.statuseffecttimer.mixin; import com.google.common.collect.Ordering; +import java.util.Collection; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.util.math.MathHelper; @@ -19,17 +19,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Collection; - // Set priority to 500, to load before default at 1000. This is to better cooperate with HUDTweaks. @Environment(EnvType.CLIENT) @Mixin(value = InGameHud.class, priority = 500) -public abstract class StatusEffectTimerMixin extends DrawableHelper { +public abstract class StatusEffectTimerMixin { @Shadow @Final private MinecraftClient client; @Inject(method = "renderStatusEffectOverlay", at = @At("TAIL")) - private void renderDurationOverlay(MatrixStack matrices, CallbackInfo c) { + private void renderDurationOverlay(DrawContext context, CallbackInfo c) { Collection collection = this.client.player.getStatusEffects(); if (!collection.isEmpty()) { // Replicate vanilla placement algorithm to get the duration @@ -58,14 +56,14 @@ private void renderDurationOverlay(MatrixStack matrices, CallbackInfo c) { String duration = getDurationAsString(statusEffectInstance); int durationLength = client.textRenderer.getWidth(duration); - drawStringWithShadow(matrices, client.textRenderer, duration, x + 13 - (durationLength / 2), y + 14, 0x99FFFFFF); + context.drawTextWithShadow(client.textRenderer, duration, x + 13 - (durationLength / 2), y + 14, 0x99FFFFFF); int amplifier = statusEffectInstance.getAmplifier(); if (amplifier > 0) { - // Most langages has "translations" for amplifier 1-5, converting to roman numerals - String amplifierString = (amplifier < 6) ? I18n.translate("potion.potency." + amplifier) : "**"; + // Convert to roman numerals if possible + String amplifierString = (amplifier < 10) ? I18n.translate("enchantment.level." + (amplifier + 1)) : "**"; int amplifierLength = client.textRenderer.getWidth(amplifierString); - drawStringWithShadow(matrices, client.textRenderer, amplifierString, x + 22 - amplifierLength, y + 3, 0x99FFFFFF); + context.drawTextWithShadow(client.textRenderer, amplifierString, x + 22 - amplifierLength, y + 3, 0x99FFFFFF); } } } @@ -74,13 +72,16 @@ private void renderDurationOverlay(MatrixStack matrices, CallbackInfo c) { @NotNull private String getDurationAsString(StatusEffectInstance statusEffectInstance) { + if (statusEffectInstance.isInfinite()) { + return I18n.translate("effect.duration.infinite"); + } + int ticks = MathHelper.floor((float) statusEffectInstance.getDuration()); int seconds = ticks / 20; - if (ticks > 32147) { - // Vanilla considers everything above this to be infinite - return "**"; - } else if (seconds > 60) { + if (seconds >= 3600) { + return seconds / 3600 + "h"; + } else if (seconds >= 60) { return seconds / 60 + "m"; } else { return String.valueOf(seconds); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a9621a0..fb2429c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,6 +25,6 @@ "depends": { "fabricloader": ">=0.7.4", - "minecraft": "~1.19" + "minecraft": "~1.20" } }