Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New features #288

Merged
merged 10 commits into from
Jun 5, 2024
2 changes: 1 addition & 1 deletion .github/workflows/fast_forward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Commit the changes (if any)
if: ${{ env.MERGE_STATUS }}
run: |
if [[ "$( tail ./response.txt -n 1 )" = "No changes to write\!" ]] || [[ "$( tail ./response.txt -n 1 )" =~ "File \`(.*?)\` not found\!" ]]; then
if [[ "$( tail ./response.txt -n 1 )" == 'No changes to write!' ]] || [[ "$( tail ./response.txt -n 1 )" =~ "File \`(.*?)\` not found\!" ]]; then
echo "COMMENT=${{ env.COMMENT }}\nNo changelogs found..." >> $GITHUB_ENV
else
git add doc/changelogs/latest.md
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Currently, this mod [has enough features](doc/FAQ.md#is-the-mod-enough-to-play-t

This mod supports:

* Game version `1.19.3`, `1.20.1`, `1.20.4`, `1.20.5`
* Game version `1.19.3`, `1.20.1`, `1.20.4`, `1.20.6`
* On [Fabric](https://fabricmc.net/use/installer/) and [Forge](https://files.minecraftforge.net/net/minecraftforge/forge/) modding platform
* On Windows and Linux operating system ([Help us on macOS porting](https://github.com/khanshoaib3/minecraft-access/issues/22))
* Works despite the language setting of the game (but the mod specific narration will [fall back to English](/doc/FEATURES.md#i18n-fallback-mechanism) if the mod does not support the language yet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
public interface AnvilScreenAccessor {
@Accessor
TextFieldWidget getNameField();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.khanshoaib3.minecraft_access.mixin;

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.AnvilScreen;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AnvilScreen.class)
public class AnvilScreenMixin {

@Unique
private String minecraft_access$previousText;

/**
* The "drawForeground" method is continually triggered when enchant cost changes,
* so there is a repeat check before speaking.
* Let the original logic build the text, we don't want to repeat that.
*/
@Inject(method = "drawForeground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V"))
protected void speakCost(DrawContext context, int mouseX, int mouseY, CallbackInfo ci, @Local Text text) {
if (text instanceof Text text_) {
String textString = text_.getString();
if (!textString.equals(minecraft_access$previousText)) {
MainClass.speakWithNarrator(textString, true);
minecraft_access$previousText = textString;
}
}
}

@Inject(method = "drawForeground", at = @At("RETURN"))
protected void resetWhenCostDisappears(DrawContext context, int mouseX, int mouseY, CallbackInfo ci, @Local(ordinal = 2) int cost) {
if (cost <= 0) {
minecraft_access$previousText = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.github.khanshoaib3.minecraft_access.mixin;

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.config.config_maps.InventoryControlsConfigMap;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.item.TooltipData;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Optional;

/**
* Speak hovered tooltip when Inventory Controls is disabled.
* Need to get text before they turned into "OrderedText" or "TooltipComponent"
* (can't easily extract text from these types).
* So we intercept every "drawTooltip" invoke that in "drawHoverEvent" method.
*/
@Mixin(DrawContext.class)
public class DrawContextMixin {
@Unique
private static String minecraft_access$previousTooltipText = "";

@Inject(at = @At("HEAD"), method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;II)V")
private void speakHoveredTooltip(TextRenderer textRenderer, Text text, int x, int y, CallbackInfo ci) {
if (InventoryControlsConfigMap.getInstance().isEnabled()) return;
minecraft_access$checkAndSpeak(text.getString());
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Inject(at = @At("HEAD"), method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;II)V")
private void speakHoveredTooltip2(TextRenderer textRenderer, List<Text> text, Optional<TooltipData> data, int x, int y, CallbackInfo ci) {
if (InventoryControlsConfigMap.getInstance().isEnabled()) return;
minecraft_access$speakTextList(text);
}

@Inject(at = @At("HEAD"), method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;II)V")
private void speakHoveredTooltip3(TextRenderer textRenderer, List<Text> text, int x, int y, CallbackInfo ci) {
if (InventoryControlsConfigMap.getInstance().isEnabled()) return;
minecraft_access$speakTextList(text);
}

@Inject(method = "drawHoverEvent", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawOrderedTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;II)V"))
private void speakHoveredTooltip4(TextRenderer textRenderer, Style style, int x, int y, CallbackInfo ci, @Local Text text) {
if (InventoryControlsConfigMap.getInstance().isEnabled()) return;
minecraft_access$checkAndSpeak(text.getString());
}

@Unique
private static void minecraft_access$speakTextList(List<Text> text) {
if (InventoryControlsConfigMap.getInstance().isEnabled()) return;

StringBuilder toSpeak = new StringBuilder();
for (Text t : text) {
toSpeak.append(t.getString()).append("\n");
}

minecraft_access$checkAndSpeak(toSpeak.toString());
}

@Unique
private static void minecraft_access$checkAndSpeak(String toSpeak) {
if (minecraft_access$previousTooltipText.equals(toSpeak)) return;
if (toSpeak.isBlank()) return;

minecraft_access$previousTooltipText = toSpeak;
MainClass.speakWithNarrator(minecraft_access$previousTooltipText, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Arrays;
import java.util.IllegalFormatException;
import java.util.Map;
import java.util.Objects;

@Mixin(I18n.class)
public class I18nMixin {
Expand All @@ -26,13 +26,15 @@ public class I18nMixin {
@Inject(at = @At("HEAD"), method = "translate", cancellable = true)
private static void useNamedFormatter(String key, Object[] args, CallbackInfoReturnable<String> cir) {
if (args.length == 1 && args[0] instanceof Map) {
Map<String, Object> params = (Map<String, Object>) args[0];

String pattern = I18NAccessor.getLanguage().get(key);
Map<String, Object> values = (Map<String, Object>) args[0];
String result = NamedFormatter.format(pattern, values);
String result = NamedFormatter.format(pattern, params);

// fallback to english
// fallback to English
if (result.startsWith("minecraft_access")) {
result = minecraft_access$translateEn(key, args);
pattern = minecraft_access$getEnglishI18Nof(key);
result = NamedFormatter.format(pattern, params);
}

cir.setReturnValue(result);
Expand All @@ -45,31 +47,25 @@ private static void useNamedFormatter(String key, Object[] args, CallbackInfoRet
*/
@Inject(at = @At("RETURN"), method = "translate", cancellable = true)
private static void fallbackFailedI18NToEnglish(String key, Object[] args, CallbackInfoReturnable<String> cir) {
// if result still is config key, That's because I18n failed, fallback to english
// if result still is config key, That's because I18n failed, fallback to English
if (cir.getReturnValue().startsWith("minecraft_access")) {
cir.setReturnValue(minecraft_access$translateEn(key, args));
cir.cancel();
String pattern = minecraft_access$getEnglishI18Nof(key);
try {
String result = String.format(pattern, args);
cir.setReturnValue(result);
} catch (IllegalFormatException illegalFormatException) {
cir.setReturnValue("Format error: key:[" + key + "] args:[" + Arrays.toString(args) + "]");
}
}
}

/**
* Copied from original code
*/

@Unique
private static String minecraft_access$translateEn(String key, Object... args) {
private static String minecraft_access$getEnglishI18Nof(String key) {
if (minecraft_access$enLanguage == null) {
minecraft_access$loadEnLanguage();
}
String string = Objects.requireNonNull(minecraft_access$enLanguage).get(key);
try {
return String.format(string, args);
} catch (IllegalFormatException illegalFormatException) {
return "Format error: " + string;
minecraft_access$enLanguage = Language.getInstance();
}
return minecraft_access$enLanguage.get(key);
}

@Unique
private static void minecraft_access$loadEnLanguage() {
minecraft_access$enLanguage = Language.getInstance();
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/minecraft_access-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"AnimatedResultButtonAccessor",
"AnimatedResultButtonMixin",
"AnvilScreenAccessor",
"AnvilScreenMixin",
"BookEditScreenMixin",
"BookScreenMixin",
"ButtonWidgetMixin",
Expand All @@ -16,6 +17,7 @@
"ClickableWidgetAccessor",
"ClientPlayNetworkHandlerMixin",
"CreativeInventoryScreenAccessor",
"DrawContextMixin",
"DurabilityMixin",
"EntityAccessor",
"EyeOfEnderEntityMixin",
Expand Down
23 changes: 21 additions & 2 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
Release v1.6.0 (2024-xx)
Release v1.6.0 (2024-06)
---------------------------

### New Features

- Speak variant of dog, cat, axolotl
- Speak animals and monsters currently wearing equipment
- Speak enchant cost in anvil [#277](https://github.com/khanshoaib3/minecraft-access/pull/277)
- Speak hovered tooltip when `Inventory Control` feature is disabled [#281](https://github.com/khanshoaib3/minecraft-access/pull/281)

### Bug Fixes

- Fix broken logic after upgrading to 1.20.6

### Translation Changes

- Add Italian translation thanks to Discord user Vabax_YT.
- Add Italian translation thanks to Discord user Vabax_YT
- New field: entity wearing equipment format
- New field: animal variant format
- New field: variant of dog, cat, axolotl

### Others

- Remove `architectury-api` denpendence

### Development Chores

- Add Fast-forward workflow.
- New `NamedFormatter` class with modifications to `I18NMixin`, for easier I18N translation

Release v1.5.4 (2024-03)
---------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/SET_UP_ON_WINDOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ For this type of error, there is a simple, common, cumbersome, no-better-choice
### Quality of Life Mods

1. Client side, which you can use in both single-player and multiplayer game:
* Presence Footsteps ([Fabric](https://modrinth.com/mod/presence-footsteps), [Forge port](https://www.curseforge.com/minecraft/mc-mods/presence-footsteps-forge)): Footstep sound enhancement mod. If the mod has not supported your game version, you would consider to use this resource pack
* Presence Footsteps ([Fabric](https://modrinth.com/mod/presence-footsteps), [Forge port](https://www.curseforge.com/minecraft/mc-mods/presence-footsteps-forge)): Footstep sound enhancement mod. If the Fabric version of mod isn't work, select `Default sound pack` in the resource pack menu. If the mod has not supported your game version, you would consider to use this resource pack
instead: [Presence Footsteps: Remastered Sounds Pack](https://modrinth.com/resourcepack/presense-footsteps-sounds), put it under `%appdata%\.minecraft\resourcepacks` folder.
* Just Enough Items ([Fabric and Forge](https://modrinth.com/mod/jei)): Item and recipe viewing mod, far better than similar recipe book feature in original game (but this mod hasn't been 100% accessible by us, you need some vision to use it).
* Sound Physics Remastered ([Fabric and Forge](https://modrinth.com/mod/sound-physics-remastered)): Provides realistic sound attenuation, reverberation, and absorption through blocks. I'm sure this mod consumes resources, so install it only when you're confident in your PC hardware.
Expand Down
15 changes: 1 addition & 14 deletions doc/changelogs/latest.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
[//]: # (Manually copy the latest.md to CHANGELOG.md, then copy the default.md to the latest.md at every release time (when changing the version number of this mod).)
[//]: # (Manually copy the latest.md to CHANGELOG.md, then copy the default.md to the latest.md at every release time.)

### New Features

- Speak variant of dog, cat, axolotl
- Speak animals and monsters currently wearing equipment

### Feature Updates

### Bug Fixes

- Fix broken logic after upgrading to 1.20.6

### Translation Changes

- New field: entity wearing equipment format
- New field: animal variant format
- New field: variant of dog, cat, axolotl

### Others

- Remove `architectury-api` denpendence

### Development Chores

- New `NamedFormatter` class with modifications to `I18NMixin`, for easier I18N translation
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fabric_yarn_version=1.20.6+build.1:v2
enabled_platforms=fabric,forge

archives_base_name=minecraft-access
mod_version=1.5.3+1.20.4
mod_version=1.6.0+1.20.6
maven_group=com.github.khanshoaib3.minecraft_access

# Architectury API version
Expand Down