generated from TerminalMC/Framework
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common/src/main/java/dev/terminalmc/clientsort/compat/ItemLocksWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters