From f1550f476ca9dd1619fa2feab4c427de29cd720a Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Mon, 20 Feb 2023 13:53:50 +0800 Subject: [PATCH 01/30] feature: Add grindstone as possible crafting screen --- src/main/java/fi/dy/masa/itemscroller/config/Configs.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index c41b24720..94c03c0fc 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -8,6 +8,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import net.minecraft.client.gui.screen.ingame.CraftingScreen; +import net.minecraft.client.gui.screen.ingame.GrindstoneScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.screen.slot.CraftingResultSlot; import fi.dy.masa.itemscroller.Reference; @@ -121,6 +122,8 @@ public static void loadFromFile() CraftingHandler.addCraftingGridDefinition(CraftingScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 9)); //"net.minecraft.client.gui.inventory.PlayerInventoryScreen,net.minecraft.inventory.SlotCrafting,0,1-4", // vanilla player inventory crafting grid CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4)); + + CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), CraftingResultSlot.class.getName(), 2, new SlotRange(0, 2)); } public static void saveToFile() From 33972ef3e8eca1fb86d13cf4f68974afcfe25dad Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Mon, 20 Feb 2023 20:46:57 +0800 Subject: [PATCH 02/30] Create devbuild.yml --- .github/workflow/devbuild.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflow/devbuild.yml diff --git a/.github/workflow/devbuild.yml b/.github/workflow/devbuild.yml new file mode 100644 index 000000000..cbc0631f3 --- /dev/null +++ b/.github/workflow/devbuild.yml @@ -0,0 +1,28 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Development Builds + +on: [push] + +jobs: + Build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + cache: 'gradle' + - name: Grant execute permission to gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - uses: actions/upload-artifact@v3 + with: + name: Compiled artifacts for ${{ github.sha }} + path: build/libs From f06c78990ac7a8fabbb385c5f74756dfa7795ffd Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Mon, 20 Feb 2023 20:48:38 +0800 Subject: [PATCH 03/30] Create build-on-pr.yml --- .github/workflows/build-on-pr.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/build-on-pr.yml diff --git a/.github/workflows/build-on-pr.yml b/.github/workflows/build-on-pr.yml new file mode 100644 index 000000000..41cb59632 --- /dev/null +++ b/.github/workflows/build-on-pr.yml @@ -0,0 +1,28 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Pull Request Builds + +on: [pull_request] + +jobs: + Build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + cache: 'gradle' + - name: Grant execute permission to gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - uses: actions/upload-artifact@v3 + with: + name: "Compiled artifacts for Pull Request #${{github.event.number}}" + path: build/libs From 9fcc4ec9ab35d4cba4396a2716863a3991e8df11 Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Mon, 20 Feb 2023 20:49:22 +0800 Subject: [PATCH 04/30] Rename .github/workflow/devbuild.yml to .github/workflows/devbuild.yml --- .github/{workflow => workflows}/devbuild.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/devbuild.yml (100%) diff --git a/.github/workflow/devbuild.yml b/.github/workflows/devbuild.yml similarity index 100% rename from .github/workflow/devbuild.yml rename to .github/workflows/devbuild.yml From 9ce25292c9c282175cde257cd69d27007363e14d Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Mon, 20 Feb 2023 22:23:26 +0800 Subject: [PATCH 05/30] perf: caching graadle files with enlarging memory --- .github/workflows/build.yml | 46 +++++++++++++++++++ .github/workflows/devbuild.yml | 28 ----------- .github/workflows/gradle.yml | 15 ++++++ .gitignore | 1 + build.properties | 3 ++ .../dy/masa/itemscroller/config/Configs.java | 8 +++- 6 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/devbuild.yml create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..ecd15efe7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,46 @@ +name: step.build + +on: + workflow_call: + inputs: + release: + type: boolean + required: false + default: false + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3.6.0 + with: + distribution: "temurin" + java-version: 17 + + - name: Cache gradle files + uses: actions/cache@v3.0.11 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ./.gradle/loom-cache + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build with Gradle + run: | + chmod +x gradlew + ./gradlew classes --parallel + ./gradlew build + env: + BUILD_ID: ${{ github.run_number }} + BUILD_RELEASE: ${{ inputs.release }} + + - uses: actions/upload-artifact@v3.1.1 + with: + name: build-artifacts + path: versions/*/build/libs/ diff --git a/.github/workflows/devbuild.yml b/.github/workflows/devbuild.yml deleted file mode 100644 index cbc0631f3..000000000 --- a/.github/workflows/devbuild.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Development Builds - -on: [push] - -jobs: - Build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - cache: 'gradle' - - name: Grant execute permission to gradlew - run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build - - uses: actions/upload-artifact@v3 - with: - name: Compiled artifacts for ${{ github.sha }} - path: build/libs diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 000000000..fd5977fd2 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,15 @@ +name: Dev Builds + +on: + push: + paths: + - "*.gradle" + - "gradle.properties" + - "src/**" + - "versions/**" + - ".github/**" + pull_request: + +jobs: + build: + uses: ./.github/workflows/build.yml diff --git a/.gitignore b/.gitignore index 037246fef..65ea7d6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ build/ eclipse/ .classpath .project +.idea build.number diff --git a/build.properties b/build.properties index c472ce4fa..be9e46852 100644 --- a/build.properties +++ b/build.properties @@ -1,4 +1,7 @@ # Thu Jan 14 08:33:00 EET 2016 +org.gradle.jvmargs = -Xmx4G +1 +# mod information group = fi.dy.masa mod_id = itemscroller mod_name = Item Scroller diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index 94c03c0fc..ee9f88f6a 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -7,6 +7,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.minecraft.client.gui.screen.ingame.AnvilScreen; import net.minecraft.client.gui.screen.ingame.CraftingScreen; import net.minecraft.client.gui.screen.ingame.GrindstoneScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; @@ -21,6 +22,7 @@ import fi.dy.masa.malilib.config.options.ConfigInteger; import fi.dy.masa.malilib.util.FileUtils; import fi.dy.masa.malilib.util.JsonUtils; +import net.minecraft.screen.slot.Slot; public class Configs implements IConfigHandler { @@ -122,8 +124,10 @@ public static void loadFromFile() CraftingHandler.addCraftingGridDefinition(CraftingScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 9)); //"net.minecraft.client.gui.inventory.PlayerInventoryScreen,net.minecraft.inventory.SlotCrafting,0,1-4", // vanilla player inventory crafting grid CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4)); - - CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), CraftingResultSlot.class.getName(), 2, new SlotRange(0, 2)); + // vanilla anvil + CraftingHandler.addCraftingGridDefinition(AnvilScreen.class.getName(), Slot.class.getName(), 2, new SlotRange(0, 2)); + // vanill grindstone + CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), Slot.class.getName(), 2, new SlotRange(0, 2)); } public static void saveToFile() From b655f909e06e76bc2aa5c5009a397b326509dd7a Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Mon, 20 Feb 2023 22:30:58 +0800 Subject: [PATCH 06/30] build: fix path issues of artifact files --- .github/workflows/build.yml | 2 +- build.gradle | 2 +- build.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecd15efe7..3f811c5c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,4 +43,4 @@ jobs: - uses: actions/upload-artifact@v3.1.1 with: name: build-artifacts - path: versions/*/build/libs/ + path: build/libs/ diff --git a/build.gradle b/build.gradle index d7582b489..2f8fa82bc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' + id 'fabric-loom' version '1.0-SNAPSHOT' apply false } sourceCompatibility = JavaVersion.VERSION_17 diff --git a/build.properties b/build.properties index be9e46852..1750eee6e 100644 --- a/build.properties +++ b/build.properties @@ -19,5 +19,5 @@ minecraft_version_out = 1.18.2 minecraft_version = 1.18.2 mappings_version = 1.18.2+build.1 -fabric_loader_version = 0.13.3 +fabric_loader_version = 0.14.14 mod_menu_version = 3.1.0 From c40a3c613687155ec5f3c821a84675da3cd55786 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Mon, 20 Feb 2023 22:36:44 +0800 Subject: [PATCH 07/30] build: try bump versions --- build.gradle | 34 +++++++++--------------- build.properties => gradle.properties | 0 gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) rename build.properties => gradle.properties (100%) diff --git a/build.gradle b/build.gradle index 2f8fa82bc..9a1895823 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' apply false + id 'fabric-loom' version '1.0-SNAPSHOT' } sourceCompatibility = JavaVersion.VERSION_17 @@ -11,31 +11,23 @@ repositories { // maven { url 'https://maven.quiltmc.org/repository/release/' } } -ext.configFile = file "build.properties" - -configFile.withReader { - def prop = new Properties() - prop.load(it) - project.ext.config = new ConfigSlurper().parse prop -} - dependencies { - minecraft "com.mojang:minecraft:${config.minecraft_version}" - mappings "net.fabricmc:yarn:${config.mappings_version}:v2" - modImplementation "net.fabricmc:fabric-loader:${config.fabric_loader_version}" + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.mappings_version}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" implementation "com.google.code.findbugs:jsr305:3.0.2" - modImplementation "fi.dy.masa.malilib:malilib-fabric-${config.minecraft_version_out}:${config.malilib_version}" + modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version_out}:${project.malilib_version}" // Fabric API. This is technically optional, but you probably want it anyway. - //modCompile "net.fabricmc.fabric-api:fabric-api:" + config.fabric_version + //modCompile "net.fabricmc.fabric-api:fabric-api:" + project.fabric_version - modCompileOnly "com.terraformersmc:modmenu:${config.mod_menu_version}" + modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}" } -group = config.group + "." + config.mod_id -archivesBaseName = config.mod_file_name + '-' + config.minecraft_version_out -version = config.mod_version +group = project.group + "." + project.mod_id +archivesBaseName = project.mod_file_name + '-' + project.minecraft_version_out +version = project.mod_version if (version.endsWith('-dev')) { version += "." + new Date().format('yyyyMMdd.HHmmss') @@ -47,12 +39,12 @@ processResources { exclude '**/xcf' // this will ensure that this task is redone when the versions change. - //inputs.property "minecraft_version", project.config.minecraft_version + //inputs.property "minecraft_version", project.project.minecraft_version - inputs.property "mod_version", config.mod_version + inputs.property "mod_version", project.mod_version filesMatching("fabric.mod.json") { - expand "mod_version": config.mod_version + expand "mod_version": project.mod_version } } diff --git a/build.properties b/gradle.properties similarity index 100% rename from build.properties rename to gradle.properties diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f6eeba20a..b5e74cfbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Aug 22 17:36:22 EDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 4645053d1f8a23117e76832bd050807043ca0115 Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:13:19 +0800 Subject: [PATCH 08/30] fix: rendering recipes could be out of index --- .../fi/dy/masa/itemscroller/event/RenderEventHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java index c9aff1aab..428c50c5b 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java @@ -232,7 +232,7 @@ private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, Han for (int i = 0, row = 0; row < recipeDimensions; row++) { - for (int col = 0; col < recipeDimensions; col++, i++) + for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++) { int xOff = col * 17; int yOff = row * 17; @@ -255,7 +255,7 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte { for (int i = 0, row = 0; row < recipeDimensions; row++) { - for (int col = 0; col < recipeDimensions; col++, i++) + for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++) { int xOff = col * scaledGridEntry; int yOff = row * scaledGridEntry; From fcf882ea1f2e4bc1911370b63dcbc44fd883cc6a Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:21:21 +0800 Subject: [PATCH 09/30] feature$build: add a trigger on the build workflow --- .github/workflows/gradle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index fd5977fd2..2db0a2437 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,6 +9,7 @@ on: - "versions/**" - ".github/**" pull_request: + workflow_dispatch: jobs: build: From 1040d9d33a90d932d5175d4e4a2c77816ef5e2d4 Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:29:03 +0800 Subject: [PATCH 10/30] build: change name of uploaded artifact --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f811c5c2..b1c792290 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,4 +43,4 @@ jobs: - uses: actions/upload-artifact@v3.1.1 with: name: build-artifacts - path: build/libs/ + path: build/libs/* From 96e5f52ca4f47106f6333fa19a2529d89a27dd37 Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:32:51 +0800 Subject: [PATCH 11/30] build: change name of uploaded artifact --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1c792290..183348057 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,5 +42,4 @@ jobs: - uses: actions/upload-artifact@v3.1.1 with: - name: build-artifacts path: build/libs/* From c240c3ca5ac3ff9471517f6fc5f32499f3db47a5 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Tue, 21 Feb 2023 10:47:05 +0800 Subject: [PATCH 12/30] fix(mismatch of class name of slots of anvils and grindstone): --- .../java/fi/dy/masa/itemscroller/config/Configs.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index ee9f88f6a..1d597b056 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -11,6 +11,8 @@ import net.minecraft.client.gui.screen.ingame.CraftingScreen; import net.minecraft.client.gui.screen.ingame.GrindstoneScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.screen.ForgingScreenHandler; +import net.minecraft.screen.GrindstoneScreenHandler; import net.minecraft.screen.slot.CraftingResultSlot; import fi.dy.masa.itemscroller.Reference; import fi.dy.masa.itemscroller.recipes.CraftingHandler; @@ -22,7 +24,6 @@ import fi.dy.masa.malilib.config.options.ConfigInteger; import fi.dy.masa.malilib.util.FileUtils; import fi.dy.masa.malilib.util.JsonUtils; -import net.minecraft.screen.slot.Slot; public class Configs implements IConfigHandler { @@ -125,9 +126,9 @@ public static void loadFromFile() //"net.minecraft.client.gui.inventory.PlayerInventoryScreen,net.minecraft.inventory.SlotCrafting,0,1-4", // vanilla player inventory crafting grid CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4)); // vanilla anvil - CraftingHandler.addCraftingGridDefinition(AnvilScreen.class.getName(), Slot.class.getName(), 2, new SlotRange(0, 2)); + CraftingHandler.addCraftingGridDefinition(AnvilScreen.class.getName(), ForgingScreenHandler.class.getName()+"$2", 2, new SlotRange(0, 2)); // vanill grindstone - CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), Slot.class.getName(), 2, new SlotRange(0, 2)); + CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), GrindstoneScreenHandler.class.getName()+"$4", 2, new SlotRange(0, 2)); } public static void saveToFile() @@ -179,7 +180,7 @@ private static void getStrings(JsonObject obj, Set outputSet, String arr private static void writeStrings(JsonObject obj, Set inputSet, String arrayName) { - if (inputSet.isEmpty() == false) + if (!inputSet.isEmpty()) { JsonArray arr = new JsonArray(); From 4a29486d8ed7dcbf8031e2f47e22057904afd336 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Wed, 22 Feb 2023 17:35:15 +0800 Subject: [PATCH 13/30] perf(build): use more efficent gradle build options to accelerate the builds --- gradle.properties | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1750eee6e..d05aaa99b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,9 @@ # Thu Jan 14 08:33:00 EET 2016 +org.gradle.configureondemand=true org.gradle.jvmargs = -Xmx4G -1 +org.gradle.daemon=true +org.gradle.parallel=true + # mod information group = fi.dy.masa mod_id = itemscroller From b1713aff817bc46cb8bd253b2aa328bdc431bfb3 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Wed, 22 Feb 2023 18:14:45 +0800 Subject: [PATCH 14/30] feature: Keep renaming for a bunch of items on anvil When applying craft all items on anvil, the renaming of the previous left items would continue. --- .gitignore | 1 + .../itemscroller/mixin/IMixinAnvilScreen.java | 18 +++++++++ .../itemscroller/util/InventoryUtils.java | 23 +++++++---- src/main/resources/mixins.itemscroller.json | 39 ++++++++++--------- 4 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 src/main/java/fi/dy/masa/itemscroller/mixin/IMixinAnvilScreen.java diff --git a/.gitignore b/.gitignore index 65ea7d6c0..2c83948ef 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ eclipse/ .project .idea build.number +run/ \ No newline at end of file diff --git a/src/main/java/fi/dy/masa/itemscroller/mixin/IMixinAnvilScreen.java b/src/main/java/fi/dy/masa/itemscroller/mixin/IMixinAnvilScreen.java new file mode 100644 index 000000000..43e3ba123 --- /dev/null +++ b/src/main/java/fi/dy/masa/itemscroller/mixin/IMixinAnvilScreen.java @@ -0,0 +1,18 @@ +package fi.dy.masa.itemscroller.mixin; + +import net.minecraft.client.gui.screen.ingame.AnvilScreen; +import net.minecraft.client.gui.widget.TextFieldWidget; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.awt.*; + +@Mixin(AnvilScreen.class) +public interface IMixinAnvilScreen { + @Invoker("onRenamed") + void itemscroller_setItemName(String newName); + + @Accessor("nameField") + TextFieldWidget itemscroller_getNameField(); +} diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index bc5db3b2b..13df39039 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -13,6 +13,7 @@ import fi.dy.masa.itemscroller.ItemScroller; import fi.dy.masa.itemscroller.config.Configs; import fi.dy.masa.itemscroller.config.Hotkeys; +import fi.dy.masa.itemscroller.mixin.IMixinAnvilScreen; import fi.dy.masa.itemscroller.recipes.CraftingHandler; import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange; import fi.dy.masa.itemscroller.recipes.RecipePattern; @@ -22,13 +23,11 @@ import fi.dy.masa.malilib.util.GuiUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.gui.screen.ingame.InventoryScreen; -import net.minecraft.client.gui.screen.ingame.MerchantScreen; +import net.minecraft.client.gui.screen.ingame.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -36,6 +35,7 @@ import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.recipe.RecipeType; +import net.minecraft.screen.AnvilScreenHandler; import net.minecraft.screen.Generic3x3ContainerScreenHandler; import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.screen.ScreenHandler; @@ -52,6 +52,7 @@ import fi.dy.masa.itemscroller.mixin.IMixinCraftingResultSlot; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparator; +import org.apache.commons.lang3.StringUtils; public class InventoryUtils { private static final Set DRAGGED_SLOTS = new HashSet<>(); @@ -1350,13 +1351,16 @@ public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe SlotRange range = CraftingHandler.getCraftingGridSlots(gui, slot); if (range != null) { - + String cacheName = null; for (int i = 0; i < 36; i++) { CraftingRecipe bookRecipe = getBookRecipeFromPattern(recipe); if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible MinecraftClient mc = MinecraftClient.getInstance(); mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); } else { + if(cacheName == null && gui instanceof AnvilScreen) { + cacheName = ((IMixinAnvilScreen)gui).itemscroller_getNameField().getText(); + } // Clear all items from the grid first, to avoid unbalanced stacks if (clearCraftingGridOfItems(recipe, gui, range, false) == false) { continue; @@ -1364,6 +1368,9 @@ public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe tryMoveItemsToCraftingGridSlots(recipe, slot, gui, true); } + if(!StringUtils.isBlank(cacheName) && gui instanceof AnvilScreen) { + ((IMixinAnvilScreen)gui).itemscroller_setItemName(cacheName); + } shiftClickSlot(gui, slot.id); } // craftAsManyItemsAsPossible(recipe, slot, gui); @@ -1622,10 +1629,10 @@ private static int getSlotNumberOfLargestMatchingStackFromDifferentInventory(Scr for (Slot slot : container.slots) { if (areSlotsInSameInventory(slot, slotReference) == false && slot.hasStack() - && areStacksEqual(stackReference, slot.getStack())) { + && areStacksEqual(stackReference, slot.getStack()) && !(slot.inventory instanceof CraftingResultInventory)) { int stackSize = getStackSize(slot.getStack()); - - if (stackSize > largest) { + // 这个stack应该是legal的,也就是我们强行忽略掉overstacked items + if (stackSize > largest && stackSize <= slot.getStack().getMaxCount()) { slotNum = slot.id; largest = stackSize; } diff --git a/src/main/resources/mixins.itemscroller.json b/src/main/resources/mixins.itemscroller.json index 92649b12d..ffdb6963f 100644 --- a/src/main/resources/mixins.itemscroller.json +++ b/src/main/resources/mixins.itemscroller.json @@ -1,21 +1,22 @@ { - "required": true, - "package": "fi.dy.masa.itemscroller.mixin", - "compatibilityLevel": "JAVA_17", - "minVersion": "0.8", - "client": [ - "IMixinCraftingResultSlot", - "IMixinMerchantScreen", - "IMixinScreenWithHandler", - "IMixinSlot", - "MixinAbstractInventoryScreen", - "MixinCraftingScreenHandler", - "MixinGameRenderer", - "MixinMerchantScreen", - "MixinMerchantScreenHandler", - "MixinScreen" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "fi.dy.masa.itemscroller.mixin", + "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", + "client": [ + "IMixinAnvilScreen", + "IMixinCraftingResultSlot", + "IMixinMerchantScreen", + "IMixinScreenWithHandler", + "IMixinSlot", + "MixinAbstractInventoryScreen", + "MixinCraftingScreenHandler", + "MixinGameRenderer", + "MixinMerchantScreen", + "MixinMerchantScreenHandler", + "MixinScreen" + ], + "injectors": { + "defaultRequire": 1 + } } From f06b6bfb196badf569c193ad44aa80ef379e133e Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 11:29:33 +0800 Subject: [PATCH 15/30] fix: overstacked enchantment books could be mass craft now --- .../itemscroller/event/KeybindCallbacks.java | 7 ++-- .../itemscroller/util/InventoryUtils.java | 38 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index c6834753f..18ab5e967 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -195,9 +195,10 @@ public void onClientTick(MinecraftClient mc) InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); } - for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { - InventoryUtils.dropStack(gui, outputSlot.id); - } +// for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { +// InventoryUtils.dropStack(gui, outputSlot.id); +// } + InventoryUtils.dropItem(gui, outputSlot.id); InventoryUtils.tryClearCursor(gui); InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 13df39039..fc70a8466 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1196,7 +1196,7 @@ private static boolean tryMoveItemsToCraftingGridSlots(RecipePattern recipe, // This slot is used to check that we get items from a DIFFERENT inventory than // where this slot is in - Slot slotGridFirst = container.getSlot(range.getFirst()); + Slot[] slotGrids = {container.getSlot(range.getFirst()), slot}; Map ingredientSlots = ItemType.getSlotsPerItem(recipe.getRecipeItems()); for (Map.Entry entry : ingredientSlots.entrySet()) { @@ -1211,9 +1211,9 @@ private static boolean tryMoveItemsToCraftingGridSlots(RecipePattern recipe, } if (fillStacks) { - fillCraftingGrid(gui, slotGridFirst, ingredientReference, targetSlots); + fillCraftingGrid(gui, slotGrids, ingredientReference, targetSlots); } else { - moveOneRecipeItemIntoCraftingGrid(gui, slotGridFirst, ingredientReference, targetSlots); + moveOneRecipeItemIntoCraftingGrid(gui, slotGrids, ingredientReference, targetSlots); } } } @@ -1222,7 +1222,7 @@ private static boolean tryMoveItemsToCraftingGridSlots(RecipePattern recipe, } private static void fillCraftingGrid(HandledScreen gui, - Slot slotGridFirst, + Slot[] slotGrids, ItemStack ingredientReference, IntArrayList targetSlots) { ScreenHandler container = gui.getScreenHandler(); @@ -1235,7 +1235,7 @@ private static void fillCraftingGrid(HandledScreen gui, } while (true) { - slotNum = getSlotNumberOfLargestMatchingStackFromDifferentInventory(container, slotGridFirst, + slotNum = getSlotNumberOfLargestMatchingStackFromDifferentInventory(container, slotGrids, ingredientReference); // Didn't find ingredient items @@ -1541,7 +1541,7 @@ public static void moveOneSetOfItemsFromSlotToPlayerInventory(HandledScreen gui, - Slot slotGridFirst, + Slot[] slotGrids, ItemStack ingredientReference, IntArrayList targetSlots) { ScreenHandler container = gui.getScreenHandler(); @@ -1550,7 +1550,7 @@ private static void moveOneRecipeItemIntoCraftingGrid(HandledScreen largest && stackSize <= slot.getStack().getMaxCount()) { @@ -1649,7 +1649,7 @@ && areStacksEqual(stackReference, slot.getStack()) && !(slot.inventory instanceo * then the largest one is selected. */ private static int getSlotNumberOfSmallestStackFromDifferentInventory(ScreenHandler container, - Slot slotReference, + Slot[] slotReference, ItemStack stackReference, int idealSize) { int slotNumSmallest = -1; @@ -1804,6 +1804,14 @@ public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2) { return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areNbtEqual(stack1, stack2); } + private static boolean areSlotsInSameInventory(Slot slot1, Slot[] slots) { + for (Slot slot: slots) { + if(areSlotsInSameInventory(slot, slot1)) { + return true; + } + } + return false; + } private static boolean areSlotsInSameInventory(Slot slot1, Slot slot2) { return areSlotsInSameInventory(slot1, slot2, false); } @@ -2363,17 +2371,19 @@ private static void dragSplitItemsIntoSlots(HandledScreen= numSlots) { break; } - - clickSlot(gui, slotNum, 1, SlotActionType.QUICK_CRAFT); + ItemStack item = container.slots.get(slotNum).getStack(); + if(item.getCount() < item.getMaxCount()) { + clickSlot(gui, slotNum, 1, SlotActionType.QUICK_CRAFT); + } } // End the drag From 36ac08f7cf5c5380a9f7fefc7b46bac984d636b6 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 16:29:33 +0800 Subject: [PATCH 16/30] feature: massCraft now would leave at least a stack of recipe items for continued crafting This is a feature offered for especially unstable internet connections. --- .../itemscroller/event/KeybindCallbacks.java | 4 ++- .../itemscroller/util/InventoryUtils.java | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 18ab5e967..0000857b7 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -189,7 +189,9 @@ public void onClientTick(MinecraftClient mc) CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); - mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); + if(InventoryUtils.checkRecipeExist(recipe, gui)) { + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); + } } else { // System.out.println("move"); InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index fc70a8466..878500f57 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1495,6 +1495,37 @@ public static void setCraftingGridContentsUsingSwaps(HandledScreen gui) { + Slot craftingOutputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); + ScreenHandler container = gui.getScreenHandler(); + int numSlots = container.slots.size(); + SlotRange range = CraftingHandler.getCraftingGridSlots(gui, craftingOutputSlot); + ItemStack[] recipeItems = recipe.getRecipeItems(); + + // Check that the slot range is valid and that the recipe can fit into this type + // of crafting grid + if (range != null && range.getLast() < numSlots && recipe.getRecipeLength() <= range.getSlotCount()) { + // This slot is used to check that we get items from a DIFFERENT inventory than + // where this slot is in + Slot[] slotReference = {container.getSlot(range.getFirst()), craftingOutputSlot}; + for(ItemStack stackReference : recipeItems) { + boolean isItemExist = false; + for(Slot slot : container.slots) { + if(areSlotsInSameInventory(slot, slotReference) == false && slot.hasStack() + && areStacksEqual(stackReference, slot.getStack())){ + isItemExist = true; + break; + } + } + if(!isItemExist) { + return false; + } + } + return true; + } + return false; + } + private static int putSingleItemIntoSlots(HandledScreen gui, IntArrayList targetSlots, int startIndex) { From 268d9d1c6c9d4af277113e5f114fdb93370ef3a0 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 17:18:51 +0800 Subject: [PATCH 17/30] feature: massCraft now would leave at least a stack of recipe items for continued crafting This is a feature offered for especially unstable internet connections. --- .../itemscroller/event/KeybindCallbacks.java | 5 ++-- .../itemscroller/util/InventoryUtils.java | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 0000857b7..39390fc05 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -189,8 +189,9 @@ public void onClientTick(MinecraftClient mc) CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); - if(InventoryUtils.checkRecipeExist(recipe, gui)) { - mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); + int option = InventoryUtils.checkRecipeEnough(recipe, gui); + if(option > 0) { + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); } } else { // System.out.println("move"); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 878500f57..246a10f9e 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1495,35 +1495,42 @@ public static void setCraftingGridContentsUsingSwaps(HandledScreen gui) { + public static int checkRecipeEnough(RecipePattern recipe, HandledScreen gui) { Slot craftingOutputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); ScreenHandler container = gui.getScreenHandler(); int numSlots = container.slots.size(); SlotRange range = CraftingHandler.getCraftingGridSlots(gui, craftingOutputSlot); - ItemStack[] recipeItems = recipe.getRecipeItems(); // Check that the slot range is valid and that the recipe can fit into this type // of crafting grid if (range != null && range.getLast() < numSlots && recipe.getRecipeLength() <= range.getSlotCount()) { // This slot is used to check that we get items from a DIFFERENT inventory than // where this slot is in + Map ingredientSlots = ItemType.getSlotsPerItem(recipe.getRecipeItems()); Slot[] slotReference = {container.getSlot(range.getFirst()), craftingOutputSlot}; - for(ItemStack stackReference : recipeItems) { - boolean isItemExist = false; + for(Map.Entry entry : ingredientSlots.entrySet()) { + int count = 0; + int numSlotsWithItem = entry.getValue().size(); + ItemStack stackReference = entry.getKey().getStack(); for(Slot slot : container.slots) { - if(areSlotsInSameInventory(slot, slotReference) == false && slot.hasStack() + if(!areSlotsInSameInventory(slot, slotReference) && slot.hasStack() && areStacksEqual(stackReference, slot.getStack())){ - isItemExist = true; - break; + ++count; + if(count > numSlotsWithItem) { + break; + } } } - if(!isItemExist) { - return false; + if(count < numSlotsWithItem) { + return 0; + } + else if (count == numSlotsWithItem) { + return 1; } } - return true; + return 2; } - return false; + return 0; } private static int putSingleItemIntoSlots(HandledScreen gui, From 8ac47fd4f293b8618cbdc4f5d92479500572199a Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 18:00:46 +0800 Subject: [PATCH 18/30] fix: use recipe books to craft items in a more precise way - by taking total number of items into account, fix the issues when items are scarttered in multiple slots - using recipe book to craft conditionally, so the crafting could be with best performance --- .../itemscroller/util/InventoryUtils.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 246a10f9e..d20893166 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1495,6 +1495,13 @@ public static void setCraftingGridContentsUsingSwaps(HandledScreen gui) { Slot craftingOutputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); ScreenHandler container = gui.getScreenHandler(); @@ -1509,23 +1516,18 @@ public static int checkRecipeEnough(RecipePattern recipe, HandledScreen ingredientSlots = ItemType.getSlotsPerItem(recipe.getRecipeItems()); Slot[] slotReference = {container.getSlot(range.getFirst()), craftingOutputSlot}; for(Map.Entry entry : ingredientSlots.entrySet()) { - int count = 0; int numSlotsWithItem = entry.getValue().size(); + int countItems = 0, countSlots = 0; ItemStack stackReference = entry.getKey().getStack(); for(Slot slot : container.slots) { if(!areSlotsInSameInventory(slot, slotReference) && slot.hasStack() && areStacksEqual(stackReference, slot.getStack())){ - ++count; - if(count > numSlotsWithItem) { - break; - } + countItems += slot.getStack().getCount(); + ++countSlots; } } - if(count < numSlotsWithItem) { - return 0; - } - else if (count == numSlotsWithItem) { - return 1; + if(countSlots <= numSlotsWithItem && countItems % numSlotsWithItem == 0) { + return countItems == numSlotsWithItem ? 0 : 1; } } return 2; From 445d48133d3e272f0e9ad5598d2e4552da5475af Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 18:18:55 +0800 Subject: [PATCH 19/30] fix: issues of items distributed in multiple slots e.g. 8 stones in 8 slots while crafting piston. --- .../fi/dy/masa/itemscroller/util/InventoryUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index d20893166..36331fcd2 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1516,17 +1516,17 @@ public static int checkRecipeEnough(RecipePattern recipe, HandledScreen ingredientSlots = ItemType.getSlotsPerItem(recipe.getRecipeItems()); Slot[] slotReference = {container.getSlot(range.getFirst()), craftingOutputSlot}; for(Map.Entry entry : ingredientSlots.entrySet()) { - int numSlotsWithItem = entry.getValue().size(); - int countItems = 0, countSlots = 0; - ItemStack stackReference = entry.getKey().getStack(); + int countItems = 0; + final int numSlotsWithItem = entry.getValue().size(); + final ItemStack stackReference = entry.getKey().getStack(); + final int itemsCraftOnce = numSlotsWithItem * stackReference.getMaxCount(); for(Slot slot : container.slots) { if(!areSlotsInSameInventory(slot, slotReference) && slot.hasStack() && areStacksEqual(stackReference, slot.getStack())){ countItems += slot.getStack().getCount(); - ++countSlots; } } - if(countSlots <= numSlotsWithItem && countItems % numSlotsWithItem == 0) { + if(countItems <= itemsCraftOnce && countItems % numSlotsWithItem == 0) { return countItems == numSlotsWithItem ? 0 : 1; } } From 245db43f8c20b6167a88dcbff1f94250c3db999a Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 23:23:02 +0800 Subject: [PATCH 20/30] feature: Add stonecutter as available crafting gui --- .../dy/masa/itemscroller/config/Configs.java | 10 +++--- .../itemscroller/event/KeybindCallbacks.java | 21 +++++++++--- .../itemscroller/recipes/RecipePattern.java | 3 ++ .../itemscroller/util/InventoryUtils.java | 34 +++++++++++++++---- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index 1d597b056..ef47b87d9 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -7,12 +7,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.minecraft.client.gui.screen.ingame.AnvilScreen; -import net.minecraft.client.gui.screen.ingame.CraftingScreen; -import net.minecraft.client.gui.screen.ingame.GrindstoneScreen; -import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.gui.screen.ingame.*; import net.minecraft.screen.ForgingScreenHandler; import net.minecraft.screen.GrindstoneScreenHandler; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.CraftingResultSlot; import fi.dy.masa.itemscroller.Reference; import fi.dy.masa.itemscroller.recipes.CraftingHandler; @@ -127,8 +125,10 @@ public static void loadFromFile() CraftingHandler.addCraftingGridDefinition(InventoryScreen.class.getName(), CraftingResultSlot.class.getName(), 0, new SlotRange(1, 4)); // vanilla anvil CraftingHandler.addCraftingGridDefinition(AnvilScreen.class.getName(), ForgingScreenHandler.class.getName()+"$2", 2, new SlotRange(0, 2)); - // vanill grindstone + // vanilla grindstone CraftingHandler.addCraftingGridDefinition(GrindstoneScreen.class.getName(), GrindstoneScreenHandler.class.getName()+"$4", 2, new SlotRange(0, 2)); + // vanilla stonecutter + CraftingHandler.addCraftingGridDefinition(StonecutterScreen.class.getName(), StonecutterScreenHandler.class.getName()+"$2", 1, new SlotRange(0, 1)); } public static void saveToFile() diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 39390fc05..1fd149673 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -4,7 +4,9 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.gui.screen.ingame.StonecutterScreen; import net.minecraft.recipe.CraftingRecipe; +import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.screen.slot.Slot; import fi.dy.masa.itemscroller.ItemScroller; import fi.dy.masa.itemscroller.config.Configs; @@ -187,21 +189,30 @@ public void onClientTick(MinecraftClient mc) RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); + StonecuttingRecipe stonecuttingRecipe = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); int option = InventoryUtils.checkRecipeEnough(recipe, gui); if(option > 0) { mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); } - } else { + } + else if(stonecuttingRecipe != null && gui instanceof StonecutterScreen) { + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, stonecuttingRecipe, true); + } + else { // System.out.println("move"); InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); } -// for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { -// InventoryUtils.dropStack(gui, outputSlot.id); -// } - InventoryUtils.dropItem(gui, outputSlot.id); + if(recipe.getResult().isStackable()) { + for (int i = 0; i < recipe.getMaxCraftAmount(); i++) { + InventoryUtils.dropStack(gui, outputSlot.id); + } + } + else { + InventoryUtils.dropItem(gui, outputSlot.id); + } InventoryUtils.tryClearCursor(gui); InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); diff --git a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java index 4a155c93a..11e577dce 100644 --- a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java +++ b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; import net.minecraft.recipe.CraftingRecipe; +import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange; @@ -20,6 +21,8 @@ public class RecipePattern private ItemStack result = InventoryUtils.EMPTY_STACK; private ItemStack[] recipe = new ItemStack[9]; public CraftingRecipe cachedRecipeFromBook = null; + + public StonecuttingRecipe cachedRecipeFromStonecutting = null; private int maxCraftAmount = 64; private HashSet recipeRemainders = new HashSet(); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 36331fcd2..97600ce34 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -27,19 +27,19 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.recipe.RecipeType; -import net.minecraft.screen.AnvilScreenHandler; +import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.screen.Generic3x3ContainerScreenHandler; import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.CraftingResultSlot; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.screen.slot.TradeOutputSlot; @@ -47,9 +47,6 @@ import net.minecraft.util.registry.Registry; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOfferList; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import fi.dy.masa.itemscroller.mixin.IMixinCraftingResultSlot; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparator; import org.apache.commons.lang3.StringUtils; @@ -1342,6 +1339,31 @@ public static CraftingRecipe getBookRecipeFromPattern(RecipePattern recipe) { return null; } + public static StonecuttingRecipe getStonecuttingRecipeFromPattern(RecipePattern recipe) { + if(recipe.cachedRecipeFromStonecutting != null) { + return recipe.cachedRecipeFromStonecutting; + } + else { + MinecraftClient mc = MinecraftClient.getInstance(); + RecipeManager recipeManager = mc.world.getRecipeManager(); + + ItemStack[] items = recipe.getRecipeItems(); + SimpleInventory search = new SimpleInventory(items.length); + // Set dummy slots with recipe pattern + for (int i = 0; i < items.length; i++) { + search.setStack(i, items[i]); + } + List inputRecipes = recipeManager.getAllMatches(RecipeType.STONECUTTING, search, mc.world); + for(StonecuttingRecipe inputRecipe : inputRecipes) { + if(inputRecipe.getOutput().getItem() == recipe.getResult().getItem()) { + recipe.cachedRecipeFromStonecutting = inputRecipe; + return inputRecipe; + } + } + } + return null; + } + public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe, HandledScreen gui) { Slot slot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); From a1b95c86b8511ca1e9c88a6c78bcba4d987a318b Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 24 Feb 2023 00:12:17 +0800 Subject: [PATCH 21/30] fix: confusing between some book and stonecutting recipes some book and stonecutting recipes have same input, which may lead to wrongly use of book recipes --- .../masa/itemscroller/event/KeybindCallbacks.java | 12 ++++++------ .../dy/masa/itemscroller/recipes/RecipePattern.java | 2 +- .../dy/masa/itemscroller/util/InventoryUtils.java | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 1fd149673..85d5c218b 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -7,6 +7,7 @@ import net.minecraft.client.gui.screen.ingame.StonecutterScreen; import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.StonecuttingRecipe; +import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.Slot; import fi.dy.masa.itemscroller.ItemScroller; import fi.dy.masa.itemscroller.config.Configs; @@ -189,20 +190,19 @@ public void onClientTick(MinecraftClient mc) RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); - StonecuttingRecipe stonecuttingRecipe = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); - if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible + int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); + if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); int option = InventoryUtils.checkRecipeEnough(recipe, gui); if(option > 0) { mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); } } - else if(stonecuttingRecipe != null && gui instanceof StonecutterScreen) { - mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, stonecuttingRecipe, true); - } else { - // System.out.println("move"); InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); + if(stonecuttingRecipeIndex != -1 && gui instanceof StonecutterScreen) { + mc.interactionManager.clickButton((gui.getScreenHandler()).syncId, stonecuttingRecipeIndex); + } } if(recipe.getResult().isStackable()) { diff --git a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java index 11e577dce..b6a84abbc 100644 --- a/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java +++ b/src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java @@ -22,7 +22,7 @@ public class RecipePattern private ItemStack[] recipe = new ItemStack[9]; public CraftingRecipe cachedRecipeFromBook = null; - public StonecuttingRecipe cachedRecipeFromStonecutting = null; + public int cachedRecipeFromStonecutting = -1; private int maxCraftAmount = 64; private HashSet recipeRemainders = new HashSet(); diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 97600ce34..508d37762 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1339,8 +1339,8 @@ public static CraftingRecipe getBookRecipeFromPattern(RecipePattern recipe) { return null; } - public static StonecuttingRecipe getStonecuttingRecipeFromPattern(RecipePattern recipe) { - if(recipe.cachedRecipeFromStonecutting != null) { + public static int getStonecuttingRecipeFromPattern(RecipePattern recipe) { + if(recipe.cachedRecipeFromStonecutting != -1) { return recipe.cachedRecipeFromStonecutting; } else { @@ -1354,14 +1354,15 @@ public static StonecuttingRecipe getStonecuttingRecipeFromPattern(RecipePattern search.setStack(i, items[i]); } List inputRecipes = recipeManager.getAllMatches(RecipeType.STONECUTTING, search, mc.world); - for(StonecuttingRecipe inputRecipe : inputRecipes) { + for(int i=0; i Date: Fri, 24 Feb 2023 01:01:17 +0800 Subject: [PATCH 22/30] feature: Add config button for reservedCrafting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reservedCrafting即合成时总会给各配方物品保留一个格子以方便连续合成的吸取. --- .../java/fi/dy/masa/itemscroller/config/Configs.java | 2 ++ .../dy/masa/itemscroller/event/KeybindCallbacks.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index ef47b87d9..e2a29e9a9 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -65,6 +65,7 @@ public static class Generic public static class Toggles { public static final ConfigBoolean CRAFTING_FEATURES = new ConfigBoolean("enableCraftingFeatures", true, "Enables scrolling items to and from crafting grids,\nwith a built-in 18 recipe memory.\nHold down the Recipe key to see the stored recipes and\nto change the selection. While holding the Recipe key,\nyou can either scroll or press a number key to change the selection.\nA recipe is stored to the currently selected \"recipe slot\"\n by clicking pick block over a configured crafting output slot.\nThe supported crafting grids must be added to the scrollableCraftingGrids list."); + public static final ConfigBoolean RESERVED_CRAFTING = new ConfigBoolean("enableReservedCrafting", false, "Enables to reserve slots of items of recipes in inventory,\nso items on the ground could be picked up for further crafting"); public static final ConfigBoolean DROP_MATCHING = new ConfigBoolean("enableDropkeyDropMatching", true, "Enables dropping all matching items from the same\ninventory with the hotkey"); public static final ConfigBoolean RIGHT_CLICK_CRAFT_STACK = new ConfigBoolean("enableRightClickCraftingOneStack", true, "Enables crafting up to one full stack when right clicking on\na slot that has been configured as a crafting output slot."); public static final ConfigBoolean SCROLL_EVERYTHING = new ConfigBoolean("enableScrollingEverything", true, "Enables scroll moving all items at once while\nholding the modifierMoveEverything keybind"); @@ -79,6 +80,7 @@ public static class Toggles public static final ImmutableList OPTIONS = ImmutableList.of( CRAFTING_FEATURES, + RESERVED_CRAFTING, DROP_MATCHING, RIGHT_CLICK_CRAFT_STACK, SCROLL_EVERYTHING, diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 85d5c218b..1d8dfd159 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -193,9 +193,14 @@ public void onClientTick(MinecraftClient mc) int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); - int option = InventoryUtils.checkRecipeEnough(recipe, gui); - if(option > 0) { - mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); + if(Configs.Toggles.RESERVED_CRAFTING.getBooleanValue()) { + int option = InventoryUtils.checkRecipeEnough(recipe, gui); + if (option > 0) { + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1); + } + } + else{ + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); } } else { From faba65cd30f8572b6afce6763974810f5a39bd3b Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 24 Feb 2023 01:03:06 +0800 Subject: [PATCH 23/30] feature: craftEveryThing is now available for stonecutter --- .../java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index 1d8dfd159..d0d23a1ca 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -190,7 +190,6 @@ public void onClientTick(MinecraftClient mc) RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); - int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible // System.out.println("recipe"); if(Configs.Toggles.RESERVED_CRAFTING.getBooleanValue()) { @@ -205,6 +204,7 @@ public void onClientTick(MinecraftClient mc) } else { InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); + int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); if(stonecuttingRecipeIndex != -1 && gui instanceof StonecutterScreen) { mc.interactionManager.clickButton((gui.getScreenHandler()).syncId, stonecuttingRecipeIndex); } From 12156018b583e64725ed1192f0cf42da9ed52451 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 24 Feb 2023 01:05:04 +0800 Subject: [PATCH 24/30] perf: move attempts to search for recipes of stonecutters into more specific conditions --- .../java/fi/dy/masa/itemscroller/util/InventoryUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 508d37762..6291804d6 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -1377,7 +1377,7 @@ public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe String cacheName = null; for (int i = 0; i < 36; i++) { CraftingRecipe bookRecipe = getBookRecipeFromPattern(recipe); - if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible + if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible MinecraftClient mc = MinecraftClient.getInstance(); mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); } else { @@ -1390,6 +1390,12 @@ public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe } tryMoveItemsToCraftingGridSlots(recipe, slot, gui, true); + + int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe); + if(stonecuttingRecipeIndex != -1 && gui instanceof StonecutterScreen) { + MinecraftClient mc = MinecraftClient.getInstance(); + mc.interactionManager.clickButton((gui.getScreenHandler()).syncId, stonecuttingRecipeIndex); + } } if(!StringUtils.isBlank(cacheName) && gui instanceof AnvilScreen) { ((IMixinAnvilScreen)gui).itemscroller_setItemName(cacheName); From f34c05c1ccbf92b26b040e3d89db01c22ccc2e2b Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 24 Feb 2023 01:36:02 +0800 Subject: [PATCH 25/30] docs: Add documentation of changes --- README.md | 26 ++++++++++++++------------ gradle.properties | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d00b09720..9812327c3 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,24 @@ ## Note -This is a customized version of Masa's itemscroller mod that fixes crafting features for 1.18. Masa's original mod can be found [here](https://github.com/maruohon/itemscroller) +This is a customized version of Andrew54757's itemscroller-crafting-fix, which is a customized version of Masa's itemscroller mod that fixes crafting features for 1.18. -Customizations: -* More accurate/faster crafting through recipe book protocol -* Toggleable crafting (so you can keep crafting without holding down a key, eg for crafting millions of pistons) -* Honey crafting +Masa's original mod can be found [here](https://github.com/maruohon/itemscroller) -- Removed carpetControlQ crafting option as it causes a "slow crafting issue" -- Removed packetRateLimit as it may lead to problems. +Andrew54757's mod can be found [here](https://github.com/Andrews54757/itemscroller-crafting-fix) -## This is not Masa's original itemscroller. If you have issues with this mod, please contact Andrews54757 (or open a bug report here). +Customizations: +Beside the customizations offered by crafting-fix, we also provide some features that are not present in the original mod: +* Apply crafting features over anvil, grindstone(could help with building overstacked items), stonecutter. +* Renaming multiple items automatically over anvil +* `reserveCrafting` to make it possible to pick up every kind of recipe items after each crafting -### What's different? -Post 1.13, Mojang has changed the crafting mechanics of the game. Before 1.13, crafting was very fast as much of the logic was handled client-side. In 1.13, most of the crafting logic was moved to the server. This broke Itemscroller's fast crafting features, since every ingredient now had to be moved one slot at a time to the crafting grid for it to work. This drastically worsened server-client desync, a compounding problem, leading to an increasing number of failed crafting attempts and accidental ingredient leaks which made afk crafting impossible. +- Fix rendering bug when recipes do not have the length of a square number -This customized version of the mod, fixes the problem by handling ingredient movement server-side using the recipe book protocols when it can. +除crafting-fix提供的功能外,还提供以下功能: +* 可以在铁砧/砂轮(可用于合成堆叠附魔书等)/切石机上使用快速合成功能 +* 可以在铁砧上批量重命名物品,只需快速合成前在铁砧上预先写好名字并调用对应的快速合成功能即可,注意仅能用于`合成而不扔出` +* `reserveCrafting` 选项可以在合成后保留物品栏中合成材料的槽位,无论地上合成材料扔出的顺序,总有物品栏位置能从地上捡起合成材料 -**Note: Some recipes like fireworks rockets that are not in the recipe book do not take advantage of this protocol, in those cases old itemscroller methods will be used** +## This is not Masa's original itemscroller. If you have issues with this mod, please contact WenDavid552 (or open a bug report here). Item Scroller ============== diff --git a/gradle.properties b/gradle.properties index d05aaa99b..d2457c999 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ author = masa mod_file_name = itemscroller-fabric # Current mod version -mod_version = craftfix-1.2.6 +mod_version = craftaddon-1.0.0 # Required malilib version malilib_version = 0.12.0 From e4f3f90812fccdcf94ad3f366148ab245fad11c8 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 24 Feb 2023 01:49:56 +0800 Subject: [PATCH 26/30] build: add ci for release --- .github/workflows/build.yml | 1 + .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 183348057..b1c792290 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,4 +42,5 @@ jobs: - uses: actions/upload-artifact@v3.1.1 with: + name: build-artifacts path: build/libs/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..e27ec55ca --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +name: Release + +on: + release: + types: + - published + workflow_dispatch: + inputs: + target_release_tag: + description: The tag of the release you want to append the artifact to + type: string + required: true + + +jobs: + matrix_prep: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.setmatrix.outputs.matrix }} + steps: + - uses: actions/checkout@v2.5.0 + + - name: Display context + run: | + echo ref_name = ${{ github.ref_name }} + echo target_release_tag = ${{ github.event.inputs.target_release_tag }} + + build: + uses: ./.github/workflows/build.yml + with: + release: true + + release: + needs: + - build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifacts + path: build-artifacts + + - name: Get github release information + if: ${{ github.event_name == 'workflow_dispatch' }} + id: get_release + uses: cardinalby/git-get-release-action@1.2.4 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag: ${{ github.event.inputs.target_release_tag }} + + - name: Generate publish related infomation + id: release_info + run: | + if [ $GITHUB_EVENT_NAME == 'release' ] + then + echo "::set-output name=tag_name::" # leave an empty value here so softprops/action-gh-release will use the default value + elif [ $GITHUB_EVENT_NAME == 'workflow_dispatch' ] + then + echo "::set-output name=tag_name::${{ github.event.inputs.target_release_tag }}" + else + echo Unknown github event name $GITHUB_EVENT_NAME + exit 1 + fi + + - name: Read Properties mod_version + id: mod_version + uses: christian-draeger/read-properties@1.1.1 + with: + path: gradle.properties + property: mod_version + + - name: Read Properties minecraft_version + id: minecraft_version + uses: christian-draeger/read-properties@1.1.1 + with: + path: gradle.properties + property: minecraft_version + + - name: Publish Minecraft Mods + uses: Kir-Antipov/mc-publish@v3.2 + with: + github-tag: ${{ steps.release_info.outputs.tag_name }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + files-primary: ${{'build-artifacts/!(*-@(dev|sources)).jar'}} + files-secondary: '' + + name: ${{ format('Itemscroller v {0} for mc{1}', steps.mod_version.outputs.value, steps.minecraft_version.outputs.value) }} + version: ${{ format('mc{0}-v{1}', steps.minecraft_version.outputs.value, steps.mod_version.outputs.value) }} + version-type: release + changelog: ${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }} # one of them should be an empty string (null) + + loaders: fabric + game-versions: ${{ matrix.game_versions }} + version-resolver: exact + + retry-attempts: 3 + retry-delay: 10000 \ No newline at end of file From 7d9f3118ac24ff53e090e5deb3b5706b52458538 Mon Sep 17 00:00:00 2001 From: wendavid552 <72400592+wendavid552@users.noreply.github.com> Date: Fri, 24 Feb 2023 03:21:50 +0800 Subject: [PATCH 27/30] Update release.yml --- .github/workflows/release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e27ec55ca..dc696dd15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ on: jobs: - matrix_prep: + prepare: runs-on: ubuntu-latest outputs: matrix: ${{ steps.setmatrix.outputs.matrix }} @@ -33,6 +33,7 @@ jobs: release: needs: - build + - prepare runs-on: ubuntu-latest steps: @@ -100,4 +101,4 @@ jobs: version-resolver: exact retry-attempts: 3 - retry-delay: 10000 \ No newline at end of file + retry-delay: 10000 From 0d21f9d5997c4855b5030e8166a15640121c3543 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Tue, 19 Dec 2023 23:01:21 +0800 Subject: [PATCH 28/30] :bug: Fix missing dependencies. --- src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index ccb13afe7..e5ff4f797 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -21,6 +21,7 @@ import fi.dy.masa.itemscroller.villager.VillagerDataStorage; import fi.dy.masa.itemscroller.villager.VillagerUtils; import fi.dy.masa.malilib.util.GuiUtils; +import org.apache.commons.lang3.StringUtils; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparator; From c80859d34391f330cdbe6f31a5a780810fd2e3a1 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Tue, 19 Dec 2023 23:06:24 +0800 Subject: [PATCH 29/30] :recycle: Clean code. --- src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index e5ff4f797..f8222d0fd 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -43,7 +43,6 @@ import net.minecraft.registry.Registries; import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.StonecutterScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.screen.slot.TradeOutputSlot; From c2a2b14425a293916ac5271fcf88868156a8bfe2 Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Fri, 19 Jan 2024 07:13:03 +0800 Subject: [PATCH 30/30] :bug: Fix Stonecutter recipe with DynamaticRegistryManager --- .../java/fi/dy/masa/itemscroller/util/InventoryUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index f8222d0fd..7e128a439 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -21,6 +21,7 @@ import fi.dy.masa.itemscroller.villager.VillagerDataStorage; import fi.dy.masa.itemscroller.villager.VillagerUtils; import fi.dy.masa.malilib.util.GuiUtils; +import net.minecraft.registry.DynamicRegistryManager; import org.apache.commons.lang3.StringUtils; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparator; @@ -1349,9 +1350,10 @@ public static int getStonecuttingRecipeFromPattern(RecipePattern recipe) { search.setStack(i, items[i]); } List inputRecipes = recipeManager.getAllMatches(RecipeType.STONECUTTING, search, mc.world); + DynamicRegistryManager stonecuttingRegistryManger = mc.world.getRegistryManager(); for(int i=0; i