1111import net .evmodder .evmod .Main ;
1212import net .evmodder .evmod .mixin .AccessorPlayerListHud ;
1313import net .minecraft .client .MinecraftClient ;
14+ import net .minecraft .network .packet .c2s .play .BundleItemSelectedC2SPacket ;
1415import net .minecraft .screen .slot .SlotActionType ;
1516import net .minecraft .text .MutableText ;
1617import net .minecraft .text .Text ;
1718
1819public class ClickUtils {
19- public record ClickEvent (int slotId , int button , SlotActionType actionType ){}
20+ public enum ActionType {
21+ CLICK (SlotActionType .PICKUP ),
22+ SHIFT_CLICK (SlotActionType .QUICK_MOVE ),
23+ HOTBAR_SWAP (SlotActionType .SWAP ),
24+ THROW (SlotActionType .THROW ),
25+ BUNDLE_SELECT (null );
26+
27+ SlotActionType action ;
28+ ActionType (SlotActionType a ){action = a ;}
29+ }
30+ public record InvAction (int slot , int button , ActionType action ){}
2031
2132 public final int MAX_CLICKS ;
2233 private final int [] tickDurationArr ;
@@ -129,7 +140,7 @@ private int calcRemainingTicks(int clicksToExecute){
129140 private boolean clickOpOngoing /*, waitedForClicks*/ ;
130141 private int estimatedMsLeft ;
131142 public final boolean hasOngoingClicks (){return clickOpOngoing ;}
132- public final void executeClicks (Queue <ClickEvent > clicks , Function <ClickEvent , Boolean > canProceed , Runnable onComplete ){
143+ public final void executeClicks (Queue <InvAction > clicks , Function <InvAction , Boolean > canProceed , Runnable onComplete ){
133144 final MinecraftClient client = MinecraftClient .getInstance ();
134145 if (clickOpOngoing ){
135146 Main .LOGGER .warn ("executeClicks() already has an ongoing operation" );
@@ -171,11 +182,14 @@ public final void executeClicks(Queue<ClickEvent> clicks, Function<ClickEvent, B
171182 Main .LOGGER .error ("executeClicks() lost available click mid-op, seemingly due to click(s) occuring during check of canProceed()!" );
172183 break ;
173184 }
174- ClickEvent click = clicks .remove ();
185+ InvAction click = clicks .remove ();
175186 try {
176187 //Main.LOGGER.info("Executing click: "+click.syncId+","+click.slotId+","+click.button+","+click.actionType);
177188 thisClickIsBotted = true ;
178- client .interactionManager .clickSlot (syncId , click .slotId , click .button , click .actionType , client .player );
189+ if (click .action == ActionType .BUNDLE_SELECT ){
190+ client .player .networkHandler .sendPacket (new BundleItemSelectedC2SPacket (click .slot , click .button ));
191+ }
192+ else client .interactionManager .clickSlot (syncId , click .slot , click .button , click .action .action , client .player );
179193 thisClickIsBotted = false ;
180194 }
181195 catch (NullPointerException e ){
@@ -216,8 +230,8 @@ public final void executeClicks(Queue<ClickEvent> clicks, Function<ClickEvent, B
216230
217231 public static void executeClicksLEGACY (
218232 MinecraftClient client ,
219- Queue <ClickEvent > clicks , final int MILLIS_BETWEEN_CLICKS , final int MAX_CLICKS_PER_SECOND ,
220- Function <ClickEvent , Boolean > canProceed , Runnable onComplete )
233+ Queue <InvAction > clicks , final int MILLIS_BETWEEN_CLICKS , final int MAX_CLICKS_PER_SECOND ,
234+ Function <InvAction , Boolean > canProceed , Runnable onComplete )
221235 {
222236 if (clicks .isEmpty ()){
223237 Main .LOGGER .warn ("executeClicks() called with an empty ClickEvent list" );
@@ -237,9 +251,12 @@ public static void executeClicksLEGACY(
237251 @ Override public void run (){
238252 int clicksThisStep = 0 ;
239253 while (clicksInLastSecond < MAX_CLICKS_PER_SECOND && canProceed .apply (clicks .peek ())){
240- ClickEvent click = clicks .remove ();
254+ InvAction click = clicks .remove ();
241255 try {
242- client .interactionManager .clickSlot (syncId , click .slotId , click .button , click .actionType , client .player );
256+ if (click .action == ActionType .BUNDLE_SELECT ){
257+ client .player .networkHandler .sendPacket (new BundleItemSelectedC2SPacket (click .slot , click .button ));
258+ }
259+ else client .interactionManager .clickSlot (syncId , click .slot , click .button , click .action .action , client .player );
243260 }
244261 catch (NullPointerException e ){
245262 Main .LOGGER .error ("executeClicks()-MODE:c/ms(array) failure due to null client. Clicks left: " +clicks .size ());
@@ -259,9 +276,12 @@ else if(MILLIS_BETWEEN_CLICKS > 1000){
259276 new Timer ().schedule (new TimerTask (){@ Override public void run (){
260277 if (clicks .isEmpty ()){cancel (); onComplete .run (); return ;}
261278 if (!canProceed .apply (clicks .peek ())) return ;
262- ClickEvent click = clicks .remove ();
279+ InvAction click = clicks .remove ();
263280 try {
264- client .interactionManager .clickSlot (syncId , click .slotId , click .button , click .actionType , client .player );
281+ if (click .action == ActionType .BUNDLE_SELECT ){
282+ client .player .networkHandler .sendPacket (new BundleItemSelectedC2SPacket (click .slot , click .button ));
283+ }
284+ else client .interactionManager .clickSlot (syncId , click .slot , click .button , click .action .action , client .player );
265285 }
266286 catch (NullPointerException e ){
267287 Main .LOGGER .error ("executeClicks()-MODE:c/ms(simple) failure due to null client. Clicks left: " +clicks .size ());
@@ -275,10 +295,13 @@ else new Timer().schedule(new TimerTask(){
275295 int clicksInLastSecondArrIndex = 0 ;
276296 @ Override public void run (){
277297 if (clicksInLastSecond < MAX_CLICKS_PER_SECOND && canProceed .apply (clicks .peek ())){
278- ClickEvent click = clicks .remove ();
298+ InvAction click = clicks .remove ();
279299 //Main.LOGGER.info("click: "+click.syncId+","+click.slotId+","+click.button+","+click.actionType);
280300 try {
281- client .interactionManager .clickSlot (syncId , click .slotId , click .button , click .actionType , client .player );
301+ if (click .action == ActionType .BUNDLE_SELECT ){
302+ client .player .networkHandler .sendPacket (new BundleItemSelectedC2SPacket (click .slot , click .button ));
303+ }
304+ else client .interactionManager .clickSlot (syncId , click .slot , click .button , click .action .action , client .player );
282305 }
283306 catch (NullPointerException e ){
284307 Main .LOGGER .error ("executeClicks()-MODE:ms/c failure due to null client. Clicks left: " +clicks .size ());
0 commit comments