diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2453a08..392a725 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,8 @@ jobs: if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - name: Build - run: ./gradlew build neoforge:githubRelease neoforge:modrinth neoforge:curseforge fabric:githubRelease fabric:modrinth fabric:curseforge --stacktrace +# run: ./gradlew build neoforge:githubRelease neoforge:modrinth neoforge:curseforge fabric:githubRelease fabric:modrinth fabric:curseforge --stacktrace + run: ./gradlew build neoforge:githubRelease fabric:githubRelease --stacktrace env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} diff --git a/common/build.gradle b/common/build.gradle index 80541c0..aa32adf 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -10,6 +10,7 @@ dependencies { // Mod dependencies use NeoForge version to avoid remapping complications api("me.shedaniel.cloth:cloth-config-neoforge:${clothconfig_version}") + implementation("maven.modrinth:tJzrFuyy:${itemlocks_version}") } neoForge { diff --git a/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocks.java b/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocks.java new file mode 100644 index 0000000..2e763e1 --- /dev/null +++ b/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocks.java @@ -0,0 +1,31 @@ +package dev.terminalmc.clientsort.compat; + +import com.kirdow.itemlocks.client.LockManager; +import dev.terminalmc.clientsort.util.inject.ISlot; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.Slot; + +import static com.kirdow.itemlocks.client.input.KeyBindings.isBypass; +import static com.kirdow.itemlocks.proxy.Components.getComponent; + +public class ItemLocks { + static boolean isLocked(Slot slot) { + if (!(slot.container instanceof Inventory)) return false; + int index = adjustForInventory(((ISlot) slot).mouseWheelie_getIndexInInv()); + return getComponent(LockManager.class).isLockedSlotRaw(index) && !isBypass(); + } + + /** + * Moves the hotbar from 0-8 to 27-35. + */ + private static int adjustForInventory(int slot) { + // + if (0 <= slot && slot <= 8) { + return slot + 27; + } else if (9 <= slot && slot <= 35) { + return slot - 9; + } else { + return slot; + } + } +} diff --git a/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocksWrapper.java b/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocksWrapper.java new file mode 100644 index 0000000..69a3886 --- /dev/null +++ b/common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocksWrapper.java @@ -0,0 +1,17 @@ +package dev.terminalmc.clientsort.compat; + +import net.minecraft.world.inventory.Slot; + +public class ItemLocksWrapper { + private static boolean hasFailed = false; + + public static boolean isLocked(Slot slot) { + if (hasFailed) return false; + try { + return ItemLocks.isLocked(slot); + } catch (NoClassDefFoundError | NoSuchMethodError ignored) { + hasFailed = true; + return false; + } + } +} diff --git a/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java b/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java index b742754..e5bf9fe 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java +++ b/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java @@ -17,6 +17,7 @@ package dev.terminalmc.clientsort.inventory.sort; +import dev.terminalmc.clientsort.compat.ItemLocksWrapper; import dev.terminalmc.clientsort.inventory.ContainerScreenHelper; import dev.terminalmc.clientsort.network.InteractionManager; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -56,7 +57,9 @@ private void collectSlots(Slot originSlot) { ArrayList slotsInScope = new ArrayList<>(); for (Slot slot : containerScreen.getMenu().slots) { if (originScope == screenHelper.getScope(slot, true)) { - slotsInScope.add(slot); + if (!ItemLocksWrapper.isLocked(slot)) { + slotsInScope.add(slot); + } } } this.inventorySlots = slotsInScope.toArray(new Slot[0]); diff --git a/common/src/main/resources/clientsort.mixins.json b/common/src/main/resources/clientsort.mixins.json index 3a3c61c..f7a3fa0 100644 --- a/common/src/main/resources/clientsort.mixins.json +++ b/common/src/main/resources/clientsort.mixins.json @@ -7,13 +7,13 @@ "mixins": [ ], "client": [ - "MixinSlot", - "emi.MixinReloadWorker", "MixinAbstractContainerScreen", "MixinClientPacketListener", "MixinCreativeSlot", "MixinLocalPlayer", - "accessor.LocalPlayerAccessor" + "MixinSlot", + "accessor.LocalPlayerAccessor", + "emi.MixinReloadWorker" ], "server": [ ], diff --git a/fabric/build.gradle b/fabric/build.gradle index 55f48d4..8176510 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -17,6 +17,7 @@ dependencies { modApi("me.shedaniel.cloth:cloth-config-fabric:${clothconfig_version}") { exclude(group: "net.fabricmc.fabric-api") } + modImplementation("maven.modrinth:tJzrFuyy:${itemlocks_version}") } loom { diff --git a/gradle.properties b/gradle.properties index a6fef04..7078fa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ # Neo/Forge version ranges: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html # Project -mod_version=1.0.1+1.21 +mod_version=1.0.2+1.21-beta.01 mod_group=dev.terminalmc mod_id=clientsort mod_name=ClientSort @@ -54,6 +54,9 @@ clothconfig_versions_neoforge=[15,) modmenu_version=11.0.2 modmenu_versions_fabric=>10 +# https://modrinth.com/mod/tJzrFuyy/versions +itemlocks_version=1.21-1.3.9 + # GitHub, Modrinth, CurseForge releases # Plural properties expect CSV lists github_repo_owner=TerminalMC diff --git a/neoforge/build.gradle b/neoforge/build.gradle index d860b1f..6b8d677 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { api("me.shedaniel.cloth:cloth-config-neoforge:${clothconfig_version}") + implementation("maven.modrinth:tJzrFuyy:${itemlocks_version}") } neoForge {