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 26, 2024
1 parent 1a6ec35 commit 187b01d
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

- Updated bundle handling
- Added Ukrainian translation (ttrafford7)
- Added support for ItemLocks
3 changes: 3 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ dependencies {

// Cloth Config API
api("me.shedaniel.cloth:cloth-config-neoforge:${clothconfig_version}")

// ItemLocks
implementation("maven.modrinth:tJzrFuyy:${itemlocks_version}")
}

neoForge {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.itemlocks;

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,33 @@
/*
* 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.itemlocks;

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.itemlocks.ItemLocksWrapper;
import dev.terminalmc.clientsort.config.Config;
import dev.terminalmc.clientsort.inventory.ContainerScreenHelper;
import dev.terminalmc.clientsort.network.InteractionManager;
Expand Down Expand Up @@ -57,7 +58,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
3 changes: 3 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dependencies {
modApi("me.shedaniel.cloth:cloth-config-fabric:${clothconfig_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

// ItemLocks
modImplementation("maven.modrinth:tJzrFuyy:${itemlocks_version}")
}

loom {
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ dependencies {

// Cloth Config API
api("me.shedaniel.cloth:cloth-config-neoforge:${clothconfig_version}")

// ItemLocks
implementation("maven.modrinth:tJzrFuyy:${itemlocks_version}")
}

neoForge {
Expand Down

0 comments on commit 187b01d

Please sign in to comment.