Skip to content

Commit f2ca008

Browse files
committed
Add support for server accelerated sorting, refactor and document
1 parent 1e6ea16 commit f2ca008

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1538
-678
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.3.0
4+
5+
- Enabled server accelerated sorting
6+
37
## 1.2.0-beta.1
48

59
- Fixed version metadata

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ subprojects {
2525
// Alternate license
2626
matching(includes: [
2727
"**/inventory/**",
28+
"**/main/**",
2829
"**/mixin/**",
2930
"**/network/**",
3031
"**/util/inject/**",
@@ -160,7 +161,7 @@ String versionChangelog() {
160161
}
161162

162163
static String capsLoader(String loader) {
163-
switch(loader) {
164+
switch (loader) {
164165
case "fabric": return "Fabric"
165166
case "quilt": return "Quilt"
166167
case "forge": return "Forge"

common/src/main/java/dev/terminalmc/clientsort/ClientSort.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,46 @@
1818

1919
import com.mojang.blaze3d.platform.InputConstants;
2020
import dev.terminalmc.clientsort.config.Config;
21-
import dev.terminalmc.clientsort.inventory.sort.SortMode;
21+
import dev.terminalmc.clientsort.inventory.sort.SortOrder;
2222
import dev.terminalmc.clientsort.network.InteractionManager;
23-
import dev.terminalmc.clientsort.util.ModLogger;
2423
import net.minecraft.client.KeyMapping;
2524
import net.minecraft.client.Minecraft;
2625
import net.minecraft.resources.ResourceLocation;
2726

27+
import java.util.concurrent.locks.Lock;
28+
import java.util.concurrent.locks.ReentrantLock;
29+
2830
import static dev.terminalmc.clientsort.util.Localization.translationKey;
2931

3032
public class ClientSort {
31-
public static final String MOD_ID = "clientsort";
32-
public static final String MOD_NAME = "ClientSort";
33-
public static final ModLogger LOG = new ModLogger(MOD_NAME);
3433
public static final KeyMapping SORT_KEY = new KeyMapping(
3534
translationKey("key", "group.sort"), InputConstants.Type.MOUSE,
3635
InputConstants.MOUSE_BUTTON_MIDDLE, translationKey("key", "group"));
3736

3837
public static boolean searchOrderUpdated = false;
3938

40-
public static boolean emiReloading = false;
39+
public static Lock emiReloadLock = new ReentrantLock();
4140
public static boolean updateBlockedByEmi = false;
4241

4342
public static void init() {
4443
Config.getAndSave();
4544
}
46-
47-
public static void onEndTick(Minecraft mc) {
48-
}
49-
45+
5046
public static void onConfigSaved(Config config) {
5147
Config.Options options = config.options;
52-
options.sortMode = SortMode.SORT_MODES.get(options.sortModeStr);
53-
options.shiftSortMode = SortMode.SORT_MODES.get(options.shiftSortModeStr);
54-
options.ctrlSortMode = SortMode.SORT_MODES.get(options.ctrlSortModeStr);
55-
options.altSortMode = SortMode.SORT_MODES.get(options.altSortModeStr);
48+
options.sortOrder = SortOrder.SORT_MODES.get(options.sortOrderStr);
49+
options.shiftSortOrder = SortOrder.SORT_MODES.get(options.shiftSortOrderStr);
50+
options.ctrlSortOrder = SortOrder.SORT_MODES.get(options.ctrlSortOrderStr);
51+
options.altSortOrder = SortOrder.SORT_MODES.get(options.altSortOrderStr);
5652
options.sortSoundLoc = ResourceLocation.tryParse(options.sortSound);
57-
setInteractionManagerTickRate(config);
53+
setInteractionManagerTickRate(config.options);
5854
}
59-
60-
public static void setInteractionManagerTickRate(Config config) {
55+
56+
public static void setInteractionManagerTickRate(Config.Options options) {
6157
if (Minecraft.getInstance().getSingleplayerServer() == null) {
62-
InteractionManager.setTickRate(config.options.interactionRateServer);
58+
InteractionManager.setTickRate(options.interactionRateServer);
6359
} else {
64-
InteractionManager.setTickRate(config.options.interactionRateClient);
60+
InteractionManager.setTickRate(options.interactionRateClient);
6561
}
6662
}
6763
}

common/src/main/java/dev/terminalmc/clientsort/compat/itemlocks/ItemLocks.java renamed to common/src/main/java/dev/terminalmc/clientsort/compat/itemlocks/ItemLocksCompat.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@
2424
import static com.kirdow.itemlocks.client.input.KeyBindings.isBypass;
2525
import static com.kirdow.itemlocks.proxy.Components.getComponent;
2626

27-
public class ItemLocks {
27+
public class ItemLocksCompat {
28+
/**
29+
* @param slot the slot to check.
30+
* @return {@code true} if the slot is valid, locked, and the bypass is not
31+
* active.
32+
*/
2833
static boolean isLocked(Slot slot) {
2934
if (!(slot.container instanceof Inventory)) return false;
30-
int index = adjustForInventory(((ISlot) slot).mouseWheelie_getIndexInInv());
35+
int index = adjustForInventory(((ISlot) slot).clientSort$getIndexInInv());
3136
return getComponent(LockManager.class).isLockedSlotRaw(index) && !isBypass();
3237
}
3338

3439
/**
3540
* Moves the hotbar from 0-8 to 27-35.
3641
*/
3742
private static int adjustForInventory(int slot) {
38-
//
3943
if (0 <= slot && slot <= 8) {
4044
return slot + 27;
4145
} else if (9 <= slot && slot <= 35) {

common/src/main/java/dev/terminalmc/clientsort/compat/itemlocks/ItemLocksWrapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
public class ItemLocksWrapper {
2222
private static boolean hasFailed = false;
2323

24+
/**
25+
* Wraps {@link ItemLocksCompat#isLocked} to catch errors if the ItemLocks
26+
* mod is not loaded or the expected method is not available.
27+
* @param slot the slot to check.
28+
* @return {@code true} if the slot is valid, locked, and the bypass is not
29+
* active.
30+
*/
2431
public static boolean isLocked(Slot slot) {
2532
if (hasFailed) return false;
2633
try {
27-
return ItemLocks.isLocked(slot);
34+
return ItemLocksCompat.isLocked(slot);
2835
} catch (NoClassDefFoundError | NoSuchMethodError ignored) {
2936
hasFailed = true;
3037
return false;

0 commit comments

Comments
 (0)