Skip to content

Commit

Permalink
Add ItemLocks compat
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Nov 22, 2024
1 parent 824a204 commit 3fa64f3
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2022 Siphalor
* Copyright 2024 TerminalMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2022 Siphalor
* Copyright 2024 TerminalMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,9 @@ private void collectSlots(Slot originSlot) {
ArrayList<Slot> 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]);
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/resources/clientsort.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"mixins": [
],
"client": [
"MixinSlot",
"emi.MixinReloadWorker",
"MixinAbstractContainerScreen",
"MixinClientPacketListener",
"MixinCreativeSlot",
"MixinLocalPlayer",
"accessor.LocalPlayerAccessor"
"MixinSlot",
"accessor.LocalPlayerAccessor",
"emi.MixinReloadWorker"
],
"server": [
],
Expand Down
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {

dependencies {
api("me.shedaniel.cloth:cloth-config-neoforge:${clothconfig_version}")
implementation("maven.modrinth:tJzrFuyy:${itemlocks_version}")
}

neoForge {
Expand Down

0 comments on commit 3fa64f3

Please sign in to comment.