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

Fix animated button crush (in Inventory Screen recipe book speaking) #253

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.khanshoaib3.minecraft_access.mixin.StonecutterScreenAccessor;
import net.minecraft.block.entity.BannerPattern;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.LoomScreen;
import net.minecraft.client.gui.screen.ingame.MerchantScreen;
import net.minecraft.client.gui.screen.ingame.StonecutterScreen;
Expand Down Expand Up @@ -72,7 +73,7 @@ public SlotItem(int x, int y, String text) {
public String getNarratableText() {
if (MinecraftClient.getInstance().currentScreen instanceof LoomScreen loomScreen) {
List<RegistryEntry<BannerPattern>> list = loomScreen.getScreenHandler().getBannerPatterns();
if (list.size() == 0) return "";
if (list.isEmpty()) return "";

int p = row + ((LoomScreenAccessor) loomScreen).getVisibleTopRow();
int q = p * 4 + column;
Expand All @@ -82,11 +83,11 @@ public String getNarratableText() {

if (MinecraftClient.getInstance().currentScreen instanceof StonecutterScreen stonecutterScreen) {
List<RecipeEntry<StonecuttingRecipe>> list = stonecutterScreen.getScreenHandler().getAvailableRecipes();
if (list.size() == 0) return "";
if (list.isEmpty()) return "";

int scrollOffset = ((StonecutterScreenAccessor) stonecutterScreen).getScrollOffset();
ItemStack item = list.get(recipeOrTradeIndex + scrollOffset).value().getResult(DynamicRegistryManager.EMPTY);
List<Text> toolTip = MinecraftClient.getInstance().currentScreen.getTooltipFromItem(MinecraftClient.getInstance(),item);
List<Text> toolTip = Screen.getTooltipFromItem(MinecraftClient.getInstance(),item);
StringBuilder toolTipString = new StringBuilder();
for (Text text : toolTip) {
toolTipString.append(text.getString()).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.client.gui.screen.recipebook.AnimatedResultButton;
import net.minecraft.client.gui.screen.recipebook.RecipeResultCollection;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
Expand All @@ -11,8 +11,9 @@

@Mixin(AnimatedResultButton.class)
public interface AnimatedResultButtonAccessor {
// pre 1.20.4: List<Recipe<?>> callGetResults();
@Invoker
List<Recipe<?>> callGetResults();
List<RecipeEntry<?>> callGetResults();

@Accessor
RecipeResultCollection getResultCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import net.minecraft.client.gui.screen.recipebook.AnimatedResultButton;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.registry.DynamicRegistryManager;
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;

@Mixin(AnimatedResultButton.class)
public class AnimatedResultButtonMixin {
@Unique
Expand All @@ -28,7 +31,9 @@ public class AnimatedResultButtonMixin {
// @Inject(at = @At("HEAD"), method = "appendNarrations", cancellable = true) // Pre 1.19.3
@Inject(at = @At("HEAD"), method = "appendClickableNarrations", cancellable = true) // From 1.19.3
private void appendNarrations(NarrationMessageBuilder builder, CallbackInfo callbackInfo) {
ItemStack itemStack = ((AnimatedResultButtonAccessor) this).callGetResults().get(((AnimatedResultButtonAccessor) this).getCurrentResultIndex()).getResult(DynamicRegistryManager.EMPTY);
List<RecipeEntry<?>> recipes = ((AnimatedResultButtonAccessor) this).callGetResults();
RecipeEntry<?> recipe = recipes.get(((AnimatedResultButtonAccessor) this).getCurrentResultIndex());
ItemStack itemStack = recipe.value().getResult(DynamicRegistryManager.EMPTY);
String itemName = itemStack.getName().getString();

boolean sameItem = itemName.equalsIgnoreCase(minecraft_access$previousItemName);
Expand Down
14 changes: 9 additions & 5 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Release v1.5.1 (2024-01)
Release v1.5.2 (2024-01)
---------------------------

### Feature Changes

* Add a new config "Speak Focused Slot Changes" with default "true" value for "Inventory Controls" feature. Close this config if you hear the mod is continuously repeating changes of item name. [#242](https://github.com/khanshoaib3/minecraft_access/issues/242)

### Bug Fixes

* Fix the bug that locking on Entity will immediately unlock [#248](https://github.com/khanshoaib3/minecraft_access/issues/248)
* Fix the bug that mod's INFO log will be logged twice in console and log files [#247](https://github.com/khanshoaib3/minecraft_access/issues/247)
* Fix the bug that speaking recipes in Inventory Screen will cause the game crush. [#251](https://github.com/khanshoaib3/minecraft_access/issues/251)

Release v1.5.1 (2024-01)
---------------------------

### Feature Changes

* Add a new config "Speak Focused Slot Changes" with default "true" value for "Inventory Controls" feature. Close this config if you hear the mod is continuously repeating changes of item name. [#242](https://github.com/khanshoaib3/minecraft_access/issues/242)

Release v1.5.0 (2024-01)
---------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fabric_yarn_version=1.20.4+build.1:v2
enabled_platforms=fabric,forge

archives_base_name=minecraft-access
mod_version=1.5.1+1.20.4
mod_version=1.5.2+1.20.4
maven_group=com.github.khanshoaib3.minecraft_access

# https://maven.architectury.dev/dev/architectury/
Expand Down