Skip to content

Commit d7f1dfe

Browse files
committed
Backup -- this will be reset
1 parent 1e6ea16 commit d7f1dfe

34 files changed

+779
-144
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: 1 addition & 0 deletions
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/**",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public static void onConfigSaved(Config config) {
5656
options.sortSoundLoc = ResourceLocation.tryParse(options.sortSound);
5757
setInteractionManagerTickRate(config);
5858
}
59-
60-
public static void setInteractionManagerTickRate(Config config) {
59+
60+
public static void setInteractionManagerTickRate(Config.Options options) {
6161
if (Minecraft.getInstance().getSingleplayerServer() == null) {
6262
InteractionManager.setTickRate(config.options.interactionRateServer);
6363
} else {

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;

common/src/main/java/dev/terminalmc/clientsort/config/Config.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.GsonBuilder;
2121
import dev.terminalmc.clientsort.ClientSort;
2222
import dev.terminalmc.clientsort.inventory.sort.SortMode;
23+
import dev.terminalmc.clientsort.platform.Services;
2324
import net.minecraft.resources.ResourceLocation;
2425
import org.jetbrains.annotations.NotNull;
2526
import org.jetbrains.annotations.Nullable;
@@ -31,7 +32,7 @@
3132
import java.nio.file.StandardCopyOption;
3233

3334
public class Config {
34-
private static final Path DIR_PATH = Path.of("config");
35+
private static final Path CONFIG_DIR = Services.PLATFORM.getConfigDir();
3536
private static final String FILE_NAME = ClientSort.MOD_ID + ".json";
3637
private static final String BACKUP_FILE_NAME = ClientSort.MOD_ID + ".unreadable.json";
3738
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
@@ -45,14 +46,22 @@ public static Options options() {
4546
}
4647

4748
public static class Options {
48-
// General
49+
50+
// General options
51+
4952
public static final int interactionRateMin = 1;
5053
public static final int interactionRateMax = 100;
5154
public static final int interactionRateServerDefault = 10;
5255
public int interactionRateServer = interactionRateServerDefault;
5356

5457
public static final int interactionRateClientDefault = 1;
5558
public int interactionRateClient = interactionRateClientDefault;
59+
60+
public static final boolean serverAcceleratedSortingDefault = true;
61+
public boolean serverAcceleratedSorting = serverAcceleratedSortingDefault;
62+
63+
public static final boolean optimizedCreativeSortingDefault = true;
64+
public boolean optimizedCreativeSorting = optimizedCreativeSortingDefault;
5665

5766
public static final HotbarMode hotbarModeDefault = HotbarMode.HARD;
5867
public HotbarMode hotbarMode = hotbarModeDefault;
@@ -89,7 +98,8 @@ public String lowerName() {
8998
public static final boolean lmbBundleDefault = false;
9099
public boolean lmbBundle = lmbBundleDefault;
91100

92-
// Sorting
101+
// Sort mode options
102+
93103
public static final String sortModeDefault = SortMode.CREATIVE.name;
94104
public String sortModeStr = sortModeDefault;
95105
public transient SortMode sortMode;
@@ -105,11 +115,9 @@ public String lowerName() {
105115
public static final String altSortModeDefault = SortMode.RAW_ID.name;
106116
public String altSortModeStr = altSortModeDefault;
107117
public transient SortMode altSortMode;
108-
109-
public static final boolean optimizedCreativeSortingDefault = true;
110-
public boolean optimizedCreativeSorting = optimizedCreativeSortingDefault;
111118

112-
// Sounds
119+
// Sorting sound options
120+
113121
public static final boolean soundEnabledDefault = false;
114122
public boolean soundEnabled = soundEnabledDefault;
115123

@@ -137,9 +145,12 @@ public String lowerName() {
137145
public boolean soundAllowOverlap = soundAllowOverlapDefault;
138146
}
139147

140-
// Cleanup
148+
// Validation
141149

142-
private void cleanup() {
150+
/**
151+
* Ensures that all config values are valid.
152+
*/
153+
private void validate() {
143154
// interactionRateServer
144155
if (options.interactionRateServer < Options.interactionRateMin)
145156
options.interactionRateServer = Options.interactionRateMin;
@@ -201,7 +212,7 @@ public static Config resetAndSave() {
201212
// Load and save
202213

203214
public static @NotNull Config load() {
204-
Path file = DIR_PATH.resolve(FILE_NAME);
215+
Path file = CONFIG_DIR.resolve(FILE_NAME);
205216
Config config = null;
206217
if (Files.exists(file)) {
207218
config = load(file, GSON);
@@ -228,8 +239,8 @@ public static Config resetAndSave() {
228239
private static void backup() {
229240
try {
230241
ClientSort.LOG.warn("Copying {} to {}", FILE_NAME, BACKUP_FILE_NAME);
231-
if (!Files.isDirectory(DIR_PATH)) Files.createDirectories(DIR_PATH);
232-
Path file = DIR_PATH.resolve(FILE_NAME);
242+
if (!Files.isDirectory(CONFIG_DIR)) Files.createDirectories(CONFIG_DIR);
243+
Path file = CONFIG_DIR.resolve(FILE_NAME);
233244
Path backupFile = file.resolveSibling(BACKUP_FILE_NAME);
234245
Files.move(file, backupFile, StandardCopyOption.ATOMIC_MOVE,
235246
StandardCopyOption.REPLACE_EXISTING);
@@ -240,10 +251,10 @@ private static void backup() {
240251

241252
public static void save() {
242253
if (instance == null) return;
243-
instance.cleanup();
254+
instance.validate();
244255
try {
245-
if (!Files.isDirectory(DIR_PATH)) Files.createDirectories(DIR_PATH);
246-
Path file = DIR_PATH.resolve(FILE_NAME);
256+
if (!Files.isDirectory(CONFIG_DIR)) Files.createDirectories(CONFIG_DIR);
257+
Path file = CONFIG_DIR.resolve(FILE_NAME);
247258
Path tempFile = file.resolveSibling(file.getFileName() + ".tmp");
248259
try (OutputStreamWriter writer = new OutputStreamWriter(
249260
new FileOutputStream(tempFile.toFile()), StandardCharsets.UTF_8)) {

common/src/main/java/dev/terminalmc/clientsort/gui/screen/ClothScreenProvider.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ else if (val > Config.Options.interactionRateMax) return Optional.of(
7979
.setSaveConsumer(val -> options.interactionRateClient = val)
8080
.build());
8181

82+
general.addEntry(eb.startBooleanToggle(localized("option", "serverAcceleratedSorting"),
83+
options.serverAcceleratedSorting)
84+
.setTooltip(localized("option", "serverAcceleratedSorting.tooltip"))
85+
.setDefaultValue(Config.Options.serverAcceleratedSortingDefault)
86+
.setSaveConsumer(val -> options.serverAcceleratedSorting = val)
87+
.build());
88+
89+
general.addEntry(eb.startBooleanToggle(localized("option", "optimizedCreativeSorting"),
90+
options.optimizedCreativeSorting)
91+
.setDefaultValue(Config.Options.optimizedCreativeSortingDefault)
92+
.setSaveConsumer(val -> {
93+
options.optimizedCreativeSorting = val;
94+
if (val) CreativeSearchOrder.tryRefreshItemSearchPositionLookup();
95+
})
96+
.build());
97+
8298
general.addEntry(eb.startEnumSelector(localized("option", "hotbarMode"),
8399
Config.Options.HotbarMode.class, options.hotbarMode)
84100
.setEnumNameProvider(val -> localized("hotbarMode",
@@ -141,15 +157,6 @@ else if (val > Config.Options.interactionRateMax) return Optional.of(
141157
.setSaveConsumer(val -> options.altSortModeStr = (String)val)
142158
.build());
143159

144-
sort.addEntry(eb.startBooleanToggle(localized("option", "optimizedCreativeSorting"),
145-
options.optimizedCreativeSorting)
146-
.setDefaultValue(Config.Options.optimizedCreativeSortingDefault)
147-
.setSaveConsumer(val -> {
148-
options.optimizedCreativeSorting = val;
149-
if (val) CreativeSearchOrder.tryRefreshItemSearchPositionLookup();
150-
})
151-
.build());
152-
153160
ConfigCategory sound = builder.getOrCreateCategory(localized("option", "sound"));
154161

155162
sound.addEntry(eb.startBooleanToggle(localized("option", "soundEnabled"),

common/src/main/java/dev/terminalmc/clientsort/inventory/ContainerScreenHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public InteractionManager.InteractionEvent createClickEvent(Slot slot, int actio
5252
}
5353

5454
public boolean isHotbarSlot(Slot slot) {
55-
return ((ISlot) slot).mouseWheelie_getIndexInInv() < 9;
55+
return ((ISlot) slot).clientSort$getIndexInInv() < 9;
5656
}
5757

5858
public int getScope(Slot slot) {
@@ -76,7 +76,7 @@ public int getScope(Slot slot, boolean preferSmallerScopes) {
7676
|| options.hotbarMode == Config.Options.HotbarMode.SOFT && preferSmallerScopes) {
7777
return -1;
7878
}
79-
} else if (((ISlot) slot).mouseWheelie_getIndexInInv() >= 40) {
79+
} else if (((ISlot) slot).clientSort$getIndexInInv() >= 40) {
8080
if (options.extraSlotMode == Config.Options.ExtraSlotMode.NONE) {
8181
return -2;
8282
} else if (options.extraSlotMode == Config.Options.ExtraSlotMode.HOTBAR

common/src/main/java/dev/terminalmc/clientsort/inventory/CreativeContainerScreenHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import net.minecraft.world.entity.player.Inventory;
2323
import net.minecraft.world.inventory.Slot;
2424

25-
public class CreativeContainerScreenHelper<T extends CreativeModeInventoryScreen> extends ContainerScreenHelper<T> {
25+
public class CreativeContainerScreenHelper<T extends CreativeModeInventoryScreen>
26+
extends ContainerScreenHelper<T> {
27+
2628
public CreativeContainerScreenHelper(T screen, ClickEventFactory clickEventFactory) {
2729
super(screen, clickEventFactory);
2830
}

0 commit comments

Comments
 (0)