diff --git a/common/src/main/java/com/github/khanshoaib3/minecraft_access/features/inventory_controls/InventoryControls.java b/common/src/main/java/com/github/khanshoaib3/minecraft_access/features/inventory_controls/InventoryControls.java
index 540fc0a2..30229078 100644
--- a/common/src/main/java/com/github/khanshoaib3/minecraft_access/features/inventory_controls/InventoryControls.java
+++ b/common/src/main/java/com/github/khanshoaib3/minecraft_access/features/inventory_controls/InventoryControls.java
@@ -9,7 +9,9 @@
import com.github.khanshoaib3.minecraft_access.utils.TimeUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.*;
+import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
+import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.ToggleButtonWidget;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
@@ -110,10 +112,15 @@ public void update() {
if (previousScreen != currentScreen) {
previousScreen = currentScreen;
if (currentScreen instanceof AnvilScreen anvilScreen) {
- ((AnvilScreenAccessor) anvilScreen).getNameField().setFocused(false);
+ // since 1.20.x
+ setSearchBoxFocus(((AnvilScreenAccessor) anvilScreen).getNameField(), false);
}
- if (currentScreen instanceof CreativeInventoryScreen creativeInventoryScreen && ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox().isActive()) {
- ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox().setFocused(false);
+ if (currentScreen instanceof CreativeInventoryScreen creativeInventoryScreen) {
+ // since 1.20.x
+ TextFieldWidget searchBox = ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox();
+ if (searchBox.isActive()) {
+ setSearchBoxFocus(searchBox, false);
+ }
}
//
@@ -125,8 +132,9 @@ public void update() {
}
if (autoOpenRecipeBook && recipeBookWidget != null) {
+ // since 1.20.x
if (!recipeBookWidget.isOpen()) recipeBookWidget.toggleOpen();
- ((RecipeBookWidgetAccessor) recipeBookWidget).getSearchField().setFocused(false);
+ setSearchBoxFocus(((RecipeBookWidgetAccessor) recipeBookWidget).getSearchField(), false);
}
//
@@ -178,41 +186,53 @@ private boolean keyListener() {
boolean disableInputForSearchBox = false;
//
- if (currentScreen instanceof CreativeInventoryScreen creativeInventoryScreen && ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox().isActive()) {
- disableInputForSearchBox = true;
- if (isEnterPressed) {
- MainClass.infoLog("Enter key pressed, deselecting the search box.");
- ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox().setFocused(false);
- refreshGroupListAndSelectFirstGroup(true);
- return true;
+ if (currentScreen instanceof CreativeInventoryScreen creativeInventoryScreen) {
+ // since 1.20.x
+ TextFieldWidget searchBox = ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox();
+ if (searchBox.isActive()) {
+ disableInputForSearchBox = true;
+ if (isEnterPressed) {
+ setSearchBoxFocus(searchBox, false);
+ refreshGroupListAndSelectFirstGroup(true);
+ return true;
+ }
}
}
- if (currentScreen instanceof AnvilScreen anvilScreen && ((AnvilScreenAccessor) anvilScreen).getNameField().isActive()) {
- disableInputForSearchBox = true;
- if (isEnterPressed) {
- MainClass.infoLog("Enter key pressed, deselecting the search box.");
- ((AnvilScreenAccessor) anvilScreen).getNameField().setFocused(false);
- previousSlotText = "";
- return true;
+ if (currentScreen instanceof AnvilScreen anvilScreen) {
+ // since 1.20.x
+ TextFieldWidget searchBox = ((AnvilScreenAccessor) anvilScreen).getNameField();
+ if (searchBox.isActive()) {
+ disableInputForSearchBox = true;
+ if (isEnterPressed) {
+ setSearchBoxFocus(searchBox, false);
+ previousSlotText = "";
+ return true;
+ }
}
}
- if (currentScreen instanceof InventoryScreen inventoryScreen && inventoryScreen.getRecipeBookWidget().isOpen() && ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getSearchField().isActive()) {
- disableInputForSearchBox = true;
- if (isEnterPressed) {
- MainClass.infoLog("Enter key pressed, deselecting the search box.");
- ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getSearchField().setFocused(false);
- previousSlotText = "";
- return true;
+ if (currentScreen instanceof InventoryScreen inventoryScreen && inventoryScreen.getRecipeBookWidget().isOpen()) {
+ // since 1.20.x
+ TextFieldWidget searchBox = ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getSearchField();
+ if (searchBox.isActive()) {
+ disableInputForSearchBox = true;
+ if (isEnterPressed) {
+ setSearchBoxFocus(searchBox, false);
+ previousSlotText = "";
+ return true;
+ }
}
}
- if (currentScreen instanceof CraftingScreen craftingScreen && craftingScreen.getRecipeBookWidget().isOpen() && ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getSearchField().isActive()) {
- disableInputForSearchBox = true;
- if (isEnterPressed) {
- MainClass.infoLog("Enter key pressed, deselecting the search box.");
- ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getSearchField().setFocused(false);
- previousSlotText = "";
- return true;
+ if (currentScreen instanceof CraftingScreen craftingScreen && craftingScreen.getRecipeBookWidget().isOpen()) {
+ // since 1.20.x
+ TextFieldWidget searchBox = ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getSearchField();
+ if (searchBox.isActive()) {
+ disableInputForSearchBox = true;
+ if (isEnterPressed) {
+ setSearchBoxFocus(searchBox, false);
+ previousSlotText = "";
+ return true;
+ }
}
}
//
@@ -247,25 +267,9 @@ else if (currentScreen instanceof CreativeInventoryScreen)
MainClass.infoLog("Up key pressed");
if (isLeftShiftPressed && currentGroup.isScrollable) {
if (currentScreen instanceof InventoryScreen inventoryScreen && inventoryScreen.getRecipeBookWidget().isOpen()) {
-// int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().x + 3; // Pre 1.19.3
-// int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().y + 3; // Pre 1.19.3
- int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getX() + 3; // From 1.19.3
- int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getY() + 3; // From 1.19.3
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
- moveToSlotItem(currentSlotItem, 100);
+ clickPreviousRecipeBookPage(inventoryScreen);
} else if (currentScreen instanceof CraftingScreen craftingScreen && craftingScreen.getRecipeBookWidget().isOpen()) {
-// int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().x + 3; // Pre 1.19.3
-// int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().y + 3; // Pre 1.19.3
- int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getX() + 3; // From 1.19.3
- int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getY() + 3; // From 1.19.3
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
- moveToSlotItem(currentSlotItem, 100);
+ clickPreviousRecipeBookPage(craftingScreen);
} else {
MouseUtils.scrollUp();
}
@@ -283,25 +287,9 @@ else if (currentScreen instanceof CreativeInventoryScreen)
MainClass.infoLog("Down key pressed");
if (isLeftShiftPressed && currentGroup.isScrollable) {
if (currentScreen instanceof InventoryScreen inventoryScreen && inventoryScreen.getRecipeBookWidget().isOpen()) {
-// int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().x + 3; // Pre 1.19.3
-// int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().y + 3; // Pre 1.19.3
- int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getX() + 3; // From 1.19.3
- int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getY() + 3; // From 1.19.3
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
- moveToSlotItem(currentSlotItem, 100);
+ clickNextRecipeBookPage(inventoryScreen);
} else if (currentScreen instanceof CraftingScreen craftingScreen && craftingScreen.getRecipeBookWidget().isOpen()) {
-// int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().x + 3; // Pre 1.19.3
-// int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().y + 3; // Pre 1.19.3
- int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getX() + 3; // From 1.19.3
- int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().getY() + 3; // From 1.19.3
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
- moveToSlotItem(currentSlotItem, 100);
+ clickNextRecipeBookPage(craftingScreen);
} else {
MouseUtils.scrollDown();
}
@@ -317,17 +305,23 @@ else if (currentScreen instanceof CreativeInventoryScreen)
}
if (isTPressed) {
if (CreativeInventoryScreenAccessor.getSelectedTab().getType() == ItemGroup.Type.SEARCH && currentScreen instanceof CreativeInventoryScreen creativeInventoryScreen) {
- ((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox().setFocused(true);
- MainClass.infoLog("T key pressed, selecting the search box.");
+ // since 1.20.x
+ setSearchBoxFocus(((CreativeInventoryScreenAccessor) creativeInventoryScreen).getSearchBox(), true);
} else if (currentScreen instanceof AnvilScreen anvilScreen) {
- ((AnvilScreenAccessor) anvilScreen).getNameField().setFocused(true);
- MainClass.infoLog("T key pressed, selecting the search box.");
+ // since 1.20.x
+ setSearchBoxFocus(((AnvilScreenAccessor) anvilScreen).getNameField(), true);
} else if (currentScreen instanceof InventoryScreen inventoryScreen && inventoryScreen.getRecipeBookWidget().isOpen()) {
- ((RecipeBookWidgetAccessor) inventoryScreen.getRecipeBookWidget()).getSearchField().setFocused(true);
- MainClass.infoLog("T key pressed, selecting the search box.");
+ // since 1.20.x
+ RecipeBookWidget recipeBookWidget = inventoryScreen.getRecipeBookWidget();
+ // resolve can-not-enter-characters-issue https://github.com/khanshoaib3/minecraft-access/issues/67
+ inventoryScreen.setFocused(recipeBookWidget);
+ setSearchBoxFocus(((RecipeBookWidgetAccessor) recipeBookWidget).getSearchField(), true);
} else if (currentScreen instanceof CraftingScreen craftingScreen && craftingScreen.getRecipeBookWidget().isOpen()) {
- ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getSearchField().setFocused(true);
- MainClass.infoLog("T key pressed, selecting the search box.");
+ // since 1.20.x
+ RecipeBookWidget recipeBookWidget = craftingScreen.getRecipeBookWidget();
+ // resolve can-not-enter-characters-issue https://github.com/khanshoaib3/minecraft-access/issues/67
+ craftingScreen.setFocused(recipeBookWidget);
+ setSearchBoxFocus(((RecipeBookWidgetAccessor) recipeBookWidget).getSearchField(), true);
}
return true;
}
@@ -349,10 +343,8 @@ else if (currentScreen instanceof CreativeInventoryScreen)
int x = toggleCraftableButton.getX() + 8;
int y = toggleCraftableButton.getY() + 4;
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(x, y);
+ MouseUtils.moveAndLeftClick(p.x(), p.y());
moveToSlotItem(currentSlotItem, 100);
MainClass.infoLog("Recipe toggle key pressed, Showing %s".formatted(toggleCraftableButton.isToggled() ? "all" : "craftable only"));
@@ -364,6 +356,28 @@ else if (currentScreen instanceof CreativeInventoryScreen)
return false;
}
+ private void clickPreviousRecipeBookPage(RecipeBookProvider screen) {
+ // int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().x + 3; // Pre 1.19.3
+ // int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getPrevPageButton().y + 3; // Pre 1.19.3
+ RecipeBookResultsAccessor area = (RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) screen.getRecipeBookWidget()).getRecipesArea();
+ int x = area.getPrevPageButton().getX() + 3; // From 1.19.3
+ int y = area.getPrevPageButton().getY() + 3; // From 1.19.3
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(x, y);
+ MouseUtils.moveAndLeftClick(p.x(), p.y());
+ moveToSlotItem(currentSlotItem, 100);
+ }
+
+ private void clickNextRecipeBookPage(RecipeBookProvider screen) {
+ // int x = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getNextPageButton().x + 3; // Pre 1.19.3
+ // int y = ((RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) craftingScreen.getRecipeBookWidget()).getRecipesArea()).getNextPageButton().y + 3; // Pre 1.19.3
+ RecipeBookResultsAccessor area = (RecipeBookResultsAccessor) ((RecipeBookWidgetAccessor) screen.getRecipeBookWidget()).getRecipesArea();
+ int x = area.getNextPageButton().getX() + 3; // From 1.19.3
+ int y = area.getNextPageButton().getY() + 3; // From 1.19.3
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(x, y);
+ MouseUtils.moveAndLeftClick(p.x(), p.y());
+ moveToSlotItem(currentSlotItem, 100);
+ }
+
/**
* Focuses a slot item in the specified direction if available.
*
@@ -474,10 +488,8 @@ private void moveToSlotItem(SlotItem slotItem) {
int x = slotItem.x;
int y = slotItem.y;
- int targetX = (int) (minecraftClient.getWindow().getX() + ((currentScreen.getX() + x) * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + ((currentScreen.getY() + y) * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.move(targetX, targetY);
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(currentScreen.getX() + x, currentScreen.getY() + y);
+ MouseUtils.move(p.x(), p.y());
}
/**
@@ -493,10 +505,8 @@ private void moveToSlotItem(SlotItem slotItem, int delay) {
int x = slotItem.x;
int y = slotItem.y;
- int targetX = (int) (minecraftClient.getWindow().getX() + ((currentScreen.getX() + x) * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + ((currentScreen.getY() + y) * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAfterDelay(targetX, targetY, delay);
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(currentScreen.getX() + x, currentScreen.getY() + y);
+ MouseUtils.moveAfterDelay(p.x(), p.y(), delay);
}
/**
@@ -505,6 +515,8 @@ private void moveToSlotItem(SlotItem slotItem, int delay) {
* @return The details of the current slot item.
*/
private String getCurrentSlotNarrationText() {
+ if (currentSlotItem == null) return "";
+
if (currentSlotItem.slot == null) {
return Objects.requireNonNullElse(currentSlotItem.getNarratableText(), I18n.translate("minecraft_access.inventory_controls.Unknown"));
}
@@ -617,12 +629,28 @@ private void changeRecipeTab(boolean goForward) {
int x = recipeBookWidgetAccessor.getTabButtons().get(nextTabIndex).getX() + 9;
int y = recipeBookWidgetAccessor.getTabButtons().get(nextTabIndex).getY() + 9;
- int targetX = (int) (minecraftClient.getWindow().getX() + (x * minecraftClient.getWindow().getScaleFactor()));
- int targetY = (int) (minecraftClient.getWindow().getY() + (y * minecraftClient.getWindow().getScaleFactor()));
-
- MouseUtils.moveAndLeftClick(targetX, targetY);
+ MouseUtils.Coordinates p = MouseUtils.calcRealPositionOfWidget(x, y);
+ MouseUtils.moveAndLeftClick(p.x(), p.y());
moveToSlotItem(currentSlotItem, 100);
MainClass.infoLog("Change tab to %s".formatted(recipeBookWidgetAccessor.getCurrentTab().getCategory().name()));
}
+
+ /**
+ * Encapsulate the changes against the vanilla code here.
+ * Correspond to the vanilla code after 1.20.x
+ */
+ private void setSearchBoxFocus(TextFieldWidget w, boolean focus) {
+ if (focus) {
+ MainClass.infoLog("T key pressed, selecting the search box.");
+ w.setFocused(true);
+ } else {
+ MainClass.infoLog("Enter key pressed, deselecting the search box.");
+ boolean origin = ((TextFieldWidgetAccessor) w).getFocusUnlocked();
+ w.setFocusUnlocked(true);
+ w.setFocused(false);
+ // set origin value back since we don't know what it is and don't want to screw up the inner state.
+ w.setFocusUnlocked(origin);
+ }
+ }
}
diff --git a/common/src/main/java/com/github/khanshoaib3/minecraft_access/mixin/TextFieldWidgetAccessor.java b/common/src/main/java/com/github/khanshoaib3/minecraft_access/mixin/TextFieldWidgetAccessor.java
new file mode 100644
index 00000000..3fe8e1fe
--- /dev/null
+++ b/common/src/main/java/com/github/khanshoaib3/minecraft_access/mixin/TextFieldWidgetAccessor.java
@@ -0,0 +1,12 @@
+package com.github.khanshoaib3.minecraft_access.mixin;
+
+import net.minecraft.client.gui.widget.TextFieldWidget;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(TextFieldWidget.class)
+public interface TextFieldWidgetAccessor {
+ @Accessor
+ boolean getFocusUnlocked();
+
+}
diff --git a/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/MouseUtils.java b/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/MouseUtils.java
index 4b1764cc..ef648f77 100644
--- a/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/MouseUtils.java
+++ b/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/MouseUtils.java
@@ -4,9 +4,11 @@
import com.sun.jna.Library;
import com.sun.jna.Native;
import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.util.Window;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
/**
* Contains functions to simulate mouse events.
@@ -21,6 +23,15 @@ public class MouseUtils {
*/
public static void moveAndLeftClick(int x, int y) {
move(x, y);
+ // fix the https://github.com/khanshoaib3/minecraft-access/issues/65
+ if (OsUtils.isWindows()) {
+ try {
+ // with a little bit of waiting, everything is ok now.
+ // I've tried to set the value to 10, and it doesn't always work, 20 is fine.
+ TimeUnit.MILLISECONDS.sleep(20);
+ } catch (Exception ignored) {
+ }
+ }
leftClick();
}
@@ -31,6 +42,15 @@ public static void moveAndLeftClick(int x, int y) {
*/
public static void moveAndRightClick(int x, int y) {
move(x, y);
+ // fix the https://github.com/khanshoaib3/minecraft-access/issues/65
+ if (OsUtils.isWindows()) {
+ try {
+ // with a little bit of waiting, everything is ok now.
+ // I've tried to set the value to 10, and it doesn't always work, 20 is fine.
+ TimeUnit.MILLISECONDS.sleep(20);
+ } catch (Exception ignored) {
+ }
+ }
rightClick();
}
@@ -190,6 +210,20 @@ public static void scrollDown(){
}
}
+ public record Coordinates(int x, int y) {
+ }
+
+ public static Coordinates calcRealPositionOfWidget(int x, int y) {
+ MinecraftClient client = MinecraftClient.getInstance();
+ if (client == null) return new Coordinates(x, y);
+ Window window = client.getWindow();
+ if (window == null) return new Coordinates(x, y);
+
+ int realX = (int) (window.getX() + (x * window.getScaleFactor()));
+ int realY = (int) (window.getY() + (y * window.getScaleFactor()));
+ return new Coordinates(realX, realY);
+ }
+
/**
* Initializes the User32.dll for windows
*/
diff --git a/common/src/main/resources/minecraft_access-common.mixins.json b/common/src/main/resources/minecraft_access-common.mixins.json
index 0fa2a582..320ec785 100644
--- a/common/src/main/resources/minecraft_access-common.mixins.json
+++ b/common/src/main/resources/minecraft_access-common.mixins.json
@@ -29,6 +29,7 @@
"ScreenMixin",
"SlotAccessor",
"StonecutterScreenAccessor",
+ "TextFieldWidgetAccessor",
"TextFieldWidgetMixin"
],
"injectors": {
diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml
index 4f2f1946..4d52fc1f 100644
--- a/forge/src/main/resources/META-INF/mods.toml
+++ b/forge/src/main/resources/META-INF/mods.toml
@@ -23,7 +23,7 @@ side = "BOTH"
[[dependencies.minecraft_access]]
modId = "minecraft"
mandatory = true
-versionRange = "[1.20.1)"
+versionRange = "[1.20.1,)"
ordering = "NONE"
side = "BOTH"