Skip to content

Commit

Permalink
Apply hotbar mode to all inventories and add tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Jul 1, 2024
1 parent d4c26da commit 9cc3310
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
14 changes: 11 additions & 3 deletions common/src/main/java/dev/terminalmc/clientsort/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ public static class Options {
public static final int defaultInteractionRateClient = 1;
public int interactionRateClient = defaultInteractionRateClient;

public static final HotbarMode defaultHotbarMode = HotbarMode.SOFT;
public static final HotbarMode defaultHotbarMode = HotbarMode.HARD;
public HotbarMode hotbarMode = defaultHotbarMode;

public enum HotbarMode {
SOFT,
NONE,
HARD,
NONE
SOFT;

public String lowerName() {
return switch(this) {
case NONE -> "merge";
case HARD -> "split";
case SOFT -> "off";
};
}
}

// Sorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ public int getScope(Slot slot, boolean preferSmallerScopes) {
if (screen instanceof EffectRenderingInventoryScreen) {
if (slot.container instanceof Inventory) {
if (isHotbarSlot(slot)) {
return 0;
Config.Options options = Config.get().options;
if (options.hotbarMode == Config.Options.HotbarMode.HARD
|| options.hotbarMode == Config.Options.HotbarMode.SOFT && preferSmallerScopes) {
return -1;
}
} else if (((ISlot) slot).mouseWheelie_getIndexInInv() >= 40) {
return -1;
} else {
return 1;
}
return 0;
} else {
return 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,41 @@ else if (val > 100) return Optional.of(

general.addEntry(eb.startEnumSelector(localized("option", "hotbar_mode"),
Config.Options.HotbarMode.class, options.hotbarMode)
.setEnumNameProvider(val -> localized("hotbar_mode",
((Config.Options.HotbarMode)val).lowerName()))
.setTooltipSupplier(val -> Optional.of(new Component[]{
localized("hotbar_mode", val.lowerName() + ".tooltip")
}))
.setDefaultValue(Config.Options.defaultHotbarMode)
.setSaveConsumer(val -> options.hotbarMode = val)
.build());


ConfigCategory sort = builder.getOrCreateCategory(localized("option", "sorting"));

sort.addEntry(eb.startSelector(localized("option", "sort_mode"),
SortMode.SORT_MODES.values().toArray(), options.sortMode)
.setNameProvider(val -> Component.literal(((SortMode)val).name))
.setNameProvider(val -> localized("sort_order", ((SortMode)val).name))
.setDefaultValue(Config.Options.defaultSortMode)
.setSaveConsumer(val -> options.sortMode = (SortMode)val)
.build());

sort.addEntry(eb.startSelector(localized("option", "shift_sort_mode"),
SortMode.SORT_MODES.values().toArray(), options.shiftSortMode)
.setNameProvider(val -> Component.literal(((SortMode)val).name))
.setNameProvider(val -> localized("sort_order", ((SortMode)val).name))
.setDefaultValue(Config.Options.defaultShiftSortMode)
.setSaveConsumer(val -> options.shiftSortMode = (SortMode)val)
.build());

sort.addEntry(eb.startSelector(localized("option", "ctrl_sort_mode"),
SortMode.SORT_MODES.values().toArray(), options.ctrlSortMode)
.setNameProvider(val -> Component.literal(((SortMode)val).name))
.setNameProvider(val -> localized("sort_order", ((SortMode)val).name))
.setDefaultValue(Config.Options.defaultCtrlSortMode)
.setSaveConsumer(val -> options.ctrlSortMode = (SortMode)val)
.build());

sort.addEntry(eb.startSelector(localized("option", "alt_sort_mode"),
SortMode.SORT_MODES.values().toArray(), options.altSortMode)
.setNameProvider(val -> Component.literal(((SortMode)val).name))
.setNameProvider(val -> localized("sort_order", ((SortMode)val).name))
.setDefaultValue(Config.Options.defaultAltSortMode)
.setSaveConsumer(val -> options.altSortMode = (SortMode)val)
.build());
Expand Down
14 changes: 13 additions & 1 deletion common/src/main/resources/assets/clientsort/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@
"option.${mod_id}.interaction_rate_client": "Singleplayer Interaction Rate",
"option.${mod_id}.interaction_rate.tooltip": "Reduce to sort faster, increase if you are experiencing packet rate issues",
"option.${mod_id}.hotbar_mode": "Hotbar Mode",

"option.${mod_id}.sorting": "Sorting",
"option.${mod_id}.sort_mode": "Sort Mode",
"option.${mod_id}.shift_sort_mode": "Shift Sort Mode",
"option.${mod_id}.ctrl_sort_mode": "Ctrl Sort Mode",
"option.${mod_id}.alt_sort_mode": "Alt Sort Mode",
"option.${mod_id}.optimized_creative_sorting": "Optimized Creative Sorting",

"hotbar_mode.${mod_id}.merge": "Merge",
"hotbar_mode.${mod_id}.merge.tooltip": "Hotbar will be treated as part of the main inventory",
"hotbar_mode.${mod_id}.split": "Split",
"hotbar_mode.${mod_id}.split.tooltip": "Hotbar will be treated as a different inventory",
"hotbar_mode.${mod_id}.off": "Off",
"hotbar_mode.${mod_id}.off.tooltip": "Hotbar cannot be sorted",

"sort_order.${mod_id}.none": "None",
"sort_order.${mod_id}.alphabet": "Alphabet",
"sort_order.${mod_id}.creative": "Creative",
"sort_order.${mod_id}.quantity": "Quantity",
"sort_order.${mod_id}.raw_id": "Raw ID",

"option.${mod_id}.error.low": "Too low",
"option.${mod_id}.error.high": "Too high"
}

0 comments on commit 9cc3310

Please sign in to comment.