1717package dev .terminalmc .clientsort .client ;
1818
1919import com .mojang .blaze3d .platform .InputConstants ;
20+ import dev .terminalmc .clientsort .client .gui .ControlButtonManager ;
21+ import dev .terminalmc .clientsort .client .gui .widget .ControlButton ;
2022import dev .terminalmc .clientsort .client .order .SortOrder ;
2123import dev .terminalmc .clientsort .client .config .Config ;
2224import dev .terminalmc .clientsort .client .network .InteractionManager ;
25+ import dev .terminalmc .clientsort .client .util .inject .ISlot ;
26+ import dev .terminalmc .clientsort .util .ModLogger ;
2327import net .minecraft .client .KeyMapping ;
2428import net .minecraft .client .Minecraft ;
29+ import net .minecraft .client .gui .screens .Screen ;
2530import net .minecraft .resources .ResourceLocation ;
31+ import net .minecraft .world .inventory .Slot ;
2632
2733import java .util .ArrayList ;
2834import java .util .List ;
2935
3036import static dev .terminalmc .clientsort .util .Localization .translationKey ;
3137
3238public class ClientSort {
39+ public static final String MOD_ID = dev .terminalmc .clientsort .ClientSort .MOD_ID ;
40+ public static final String MOD_NAME = dev .terminalmc .clientsort .ClientSort .MOD_NAME ;
41+ public static final ModLogger LOG = dev .terminalmc .clientsort .ClientSort .LOG ;
42+
3343 public static final KeyMapping SORT_KEY = new KeyMapping (
3444 translationKey ("key" , "group.sort" ), InputConstants .Type .MOUSE ,
3545 InputConstants .MOUSE_BUTTON_MIDDLE , translationKey ("key" , "group" ));
@@ -39,12 +49,42 @@ public class ClientSort {
3949 public static final KeyMapping FILL_STACKS_KEY = new KeyMapping (
4050 translationKey ("key" , "group.fillStacks" ), InputConstants .Type .KEYSYM ,
4151 InputConstants .UNKNOWN .getValue (), translationKey ("key" , "group" ));
52+
53+ // TODO remove
54+ public static int slotNumberType = 0 ;
55+ public static final KeyMapping CYCLE_INDICATOR_KEY = new KeyMapping (
56+ translationKey ("key" , "group.cycleIndicator" ), InputConstants .Type .KEYSYM ,
57+ InputConstants .KEY_PERIOD , translationKey ("key" , "group" ));
58+ public static String getNumber (Slot slot ) {
59+ return switch (slotNumberType ) {
60+ case 0 -> String .valueOf (((ISlot )slot ).clientSort$getIdInContainer ());
61+ case 1 -> String .valueOf (((ISlot )slot ).clientSort$getIndexInInv ());
62+ case 2 -> String .valueOf (slot .getContainerSlot ());
63+ default -> "?" ;
64+ };
65+ }
66+ public static void cycleSlotNumberType () {
67+ slotNumberType += 1 ;
68+ dev .terminalmc .clientsort .ClientSort .LOG .warn ("Slot Indicator: {}" , switch (slotNumberType ) {
69+ case 0 -> "index" ;
70+ case 1 -> "slot" ;
71+ case 2 -> "getContainerSlot" ;
72+ default -> {
73+ slotNumberType = 0 ;
74+ yield "index" ;
75+ }
76+ });
77+ }
78+
4279 public static final List <KeyMapping > KEYBINDS = List .of (
4380 SORT_KEY ,
4481 TRANSFER_KEY ,
45- FILL_STACKS_KEY
82+ FILL_STACKS_KEY ,
83+ CYCLE_INDICATOR_KEY
4684 );
4785
86+ public static final List <ControlButton > buttons = new ArrayList <>();
87+
4888 public static final List <ScheduledAction > SCHEDULED_ACTIONS = new ArrayList <>();
4989 public static class ScheduledAction {
5090 int ticks ;
@@ -65,7 +105,7 @@ public static void init() {
65105 Config .getAndSave ();
66106 }
67107
68- public static void onEndTick (Minecraft mc ) {
108+ public static void afterClientTick (Minecraft mc ) {
69109 SCHEDULED_ACTIONS .removeIf ((sa ) -> {
70110 if (--sa .ticks <= 0 ) {
71111 sa .action .run ();
@@ -74,22 +114,21 @@ public static void onEndTick(Minecraft mc) {
74114 return false ;
75115 });
76116 }
117+
118+ public static void afterScreenInit (Screen screen ) {
119+ ControlButtonManager .afterScreenInit (screen );
120+ }
77121
78122 public static void onConfigSaved (Config config ) {
79123 Config .Options options = config .options ;
124+ // Convert config sort order strings into enum values
80125 options .sortOrder = SortOrder .SORT_MODES .get (options .sortOrderStr );
81126 options .shiftSortOrder = SortOrder .SORT_MODES .get (options .shiftSortOrderStr );
82127 options .ctrlSortOrder = SortOrder .SORT_MODES .get (options .ctrlSortOrderStr );
83128 options .altSortOrder = SortOrder .SORT_MODES .get (options .altSortOrderStr );
129+ // Parse sound location string
84130 options .sortSoundLoc = ResourceLocation .tryParse (options .sortSound );
85- setInteractionManagerTickRate (config .options );
86- }
87-
88- public static void setInteractionManagerTickRate (Config .Options options ) {
89- if (Minecraft .getInstance ().getSingleplayerServer () == null ) {
90- InteractionManager .setTickRate (options .interactionRateServer );
91- } else {
92- InteractionManager .setTickRate (options .interactionRateClient );
93- }
131+ // Update interaction manager tick rate
132+ InteractionManager .setTickRate (options .interactionInterval );
94133 }
95134}
0 commit comments