22
33import com .google .gson .JsonObject ;
44import com .jelly .farmhelperv2 .handler .MacroHandler ;
5- import com .jelly .farmhelperv2 .handler .RotationHandler ;
65import com .jelly .farmhelperv2 .remote .command .commands .ClientCommand ;
76import com .jelly .farmhelperv2 .remote .command .commands .Command ;
87import com .jelly .farmhelperv2 .remote .struct .RemoteMessage ;
9- import com .jelly .farmhelperv2 .util .*;
8+ import com .jelly .farmhelperv2 .util .InventoryUtils ;
9+ import com .jelly .farmhelperv2 .util .LogUtils ;
10+ import com .jelly .farmhelperv2 .util .PlayerUtils ;
1011import com .jelly .farmhelperv2 .util .helper .Clock ;
11- import com .jelly .farmhelperv2 .util .helper .Rotation ;
12- import com .jelly .farmhelperv2 .util .helper .RotationConfiguration ;
1312import com .jelly .farmhelperv2 .util .helper .SignUtils ;
14- import net .minecraft .init .Blocks ;
15- import net .minecraft .util .BlockPos ;
16- import net .minecraft .util .MovingObjectPosition ;
17- import net .minecraft .util .Vec3 ;
18- import net .minecraftforge .client .event .ClientChatReceivedEvent ;
1913import net .minecraftforge .event .world .WorldEvent ;
2014import net .minecraftforge .fml .common .eventhandler .SubscribeEvent ;
2115import net .minecraftforge .fml .common .gameevent .TickEvent ;
2216
23- import java .util .Arrays ;
24-
2517/*
2618 Credits to mostly Yuro with few changes by May2Bee for this superb class
2719*/
2820@ Command (label = "setspeed" )
2921public class SetSpeedCommand extends ClientCommand {
3022 private static final Clock clock = new Clock ();
31- private static final RotationHandler rotation = RotationHandler .getInstance ();
3223 private static int speed = -1 ;
3324 private static JsonObject data ;
3425 private static boolean enabled = false ;
3526 private static State currentState = State .NONE ;
36- private static Rotation lastRotation = new Rotation (0f , 0f );
37- private final float [][] vectors = {
38- {0.5F , 3.5F , 3.5F },
39- {-6.5F , 1.5F , 0F },
40- {6.5F , 1.5F , 0F },
41- {0.5F , 7.5F , 0F }
42- };
43- int freeSlot = -1 ;
44- int freeHotbarSlot = -1 ;
4527 boolean wasMacroing = false ;
4628
4729 @ Override
4830 public void execute (RemoteMessage message ) {
4931 JsonObject args = message .args ;
50- freeSlot = -1 ;
51- freeHotbarSlot = -1 ;
5232 speed = args .get ("speed" ).getAsInt ();
5333 data = new JsonObject ();
5434 data .addProperty ("username" , mc .getSession ().getUsername ());
@@ -63,19 +43,9 @@ public void execute(RemoteMessage message) {
6343 for (int i = 36 ; i < 44 ; i ++) {
6444 if (ClientCommand .mc .thePlayer .inventoryContainer .getSlot (i ).getStack () == null ) {
6545 LogUtils .sendDebug ("Found free slot: " + i );
66- freeSlot = i ;
67- freeHotbarSlot = i - 36 ;
6846 break ;
6947 }
7048 }
71- if (freeSlot == -1 ) {
72- disableWithError ("You don't have any free slot in your hotbar! Disabling..." );
73- return ;
74- }
75- if (freeHotbarSlot < 0 || freeHotbarSlot > 7 ) {
76- disableWithError ("Free hotbar slot is invalid! Disabling..." );
77- return ;
78- }
7949 try {
8050 enabled = true ;
8151 currentState = State .START ;
@@ -109,59 +79,17 @@ public void onTick(TickEvent.ClientTickEvent event) {
10979 if (wasMacroing ) {
11080 MacroHandler .getInstance ().pauseMacro ();
11181 }
112- currentState = State .OPEN_INVENTORY ;
113- clock .schedule (500 );
114- break ;
115- case OPEN_INVENTORY :
116- InventoryUtils .openInventory ();
117- currentState = State .TAKE_OFF_BOOTS ;
118- clock .schedule (500 );
119- break ;
120- case TAKE_OFF_BOOTS :
121- if (ClientCommand .mc .thePlayer .openContainer == null ) {
122- currentState = State .OPEN_INVENTORY ;
123- clock .schedule (500 );
124- break ;
125- }
126- InventoryUtils .clickContainerSlot (8 , InventoryUtils .ClickType .LEFT , InventoryUtils .ClickMode .PICKUP );
127- InventoryUtils .clickContainerSlot (freeSlot , InventoryUtils .ClickType .LEFT , InventoryUtils .ClickMode .PICKUP );
128- currentState = State .CLOSE_INVENTORY ;
82+ currentState = State .TYPE_COMMAND ;
12983 clock .schedule (500 );
13084 break ;
131- case CLOSE_INVENTORY :
132- PlayerUtils .closeScreen ();
133- lastRotation = new Rotation (AngleUtils .get360RotationYaw (), ClientCommand .mc .thePlayer .rotationPitch );
134- currentState = State .LOOK_IN_THE_AIR ;
135- clock .schedule (500 );
136- break ;
137- case LOOK_IN_THE_AIR :
138- lookInTheAir ();
139- currentState = State .HOLD_RANCHER_BOOTS ;
140- clock .schedule (500 );
141- break ;
142- case HOLD_RANCHER_BOOTS :
143- if (ClientCommand .mc .currentScreen != null ) {
144- currentState = State .CLOSE_INVENTORY ;
145- clock .schedule (500 );
146- break ;
147- }
148- ClientCommand .mc .thePlayer .inventory .currentItem = freeHotbarSlot ;
149- currentState = State .CLICK_RANCHER_BOOTS ;
150- clock .schedule (500 );
151- break ;
152- case CLICK_RANCHER_BOOTS :
153- if (ClientCommand .mc .thePlayer .inventoryContainer .getSlot (freeSlot ).getStack () == null || ClientCommand .mc .thePlayer .inventory .currentItem != freeHotbarSlot ) {
154- currentState = State .HOLD_RANCHER_BOOTS ;
155- clock .schedule (500 );
156- break ;
157- }
158- KeyBindUtils .leftClick ();
85+ case TYPE_COMMAND :
86+ mc .thePlayer .sendChatMessage ("/setmaxspeed" );
15987 currentState = State .TYPE_IN_SPEED ;
16088 clock .schedule (500 );
16189 break ;
16290 case TYPE_IN_SPEED :
16391 if (ClientCommand .mc .currentScreen == null ) {
164- currentState = State .CLICK_RANCHER_BOOTS ;
92+ currentState = State .TYPE_COMMAND ;
16593 clock .schedule (500 );
16694 break ;
16795 }
@@ -176,38 +104,6 @@ public void onTick(TickEvent.ClientTickEvent event) {
176104 break ;
177105 }
178106 SignUtils .confirmSign ();
179- currentState = State .LOOK_BACK ;
180- clock .schedule (500 );
181- break ;
182- case LOOK_BACK :
183- rotation .reset ();
184- rotation .easeTo (
185- new RotationConfiguration (
186- new Rotation (lastRotation .getYaw (), lastRotation .getPitch ()),
187- 300 , null
188- )
189- );
190- currentState = State .OPEN_INVENTORY_AGAIN ;
191- clock .schedule (500 );
192- break ;
193- case OPEN_INVENTORY_AGAIN :
194- InventoryUtils .openInventory ();
195- currentState = State .PUT_ON_BOOTS ;
196- clock .schedule (500 );
197- break ;
198- case PUT_ON_BOOTS :
199- if (ClientCommand .mc .thePlayer .openContainer == null ) {
200- currentState = State .OPEN_INVENTORY_AGAIN ;
201- clock .schedule (500 );
202- break ;
203- }
204- InventoryUtils .clickContainerSlot (freeSlot , InventoryUtils .ClickType .LEFT , InventoryUtils .ClickMode .PICKUP );
205- InventoryUtils .clickContainerSlot (8 , InventoryUtils .ClickType .LEFT , InventoryUtils .ClickMode .PICKUP );
206- currentState = State .CLOSE_INVENTORY_AGAIN ;
207- clock .schedule (500 );
208- break ;
209- case CLOSE_INVENTORY_AGAIN :
210- PlayerUtils .closeScreen ();
211107 currentState = State .END ;
212108 clock .schedule (500 );
213109 break ;
@@ -236,42 +132,6 @@ private void disableWithError(String message) {
236132 send (response );
237133 }
238134
239- private void lookInTheAir () {
240- LogUtils .sendDebug ("Looking in the air..." );
241- for (float [] vector : vectors ) {
242- Vec3 target = new Vec3 (BlockUtils .getRelativeBlockPos (vector [0 ], vector [1 ], vector [2 ]));
243- MovingObjectPosition rayTraceResult = ClientCommand .mc .theWorld .rayTraceBlocks (ClientCommand .mc .thePlayer .getPositionEyes (1 ), target , false , false , true );
244-
245- if (rayTraceResult != null ) {
246- if (rayTraceResult .typeOfHit == MovingObjectPosition .MovingObjectType .MISS ) {
247- BlockPos blockPos = rayTraceResult .getBlockPos ();
248- if (ClientCommand .mc .theWorld .getBlockState (blockPos ).getBlock () == null || ClientCommand .mc .theWorld .getBlockState (blockPos ).getBlock () == Blocks .air ) {
249- LogUtils .sendDebug ("Looking at " + Arrays .toString (vector ));
250- rotation .reset ();
251- rotation .easeTo (
252- new RotationConfiguration (
253- new Rotation (rotation .getRotation (target , true ).getYaw (), rotation .getRotation (target , true ).getPitch ()),
254- 300 , null
255- )
256- );
257- return ;
258- }
259- }
260- }
261- LogUtils .sendDebug ("Couldn't find an empty space to look at! Trying the next vector..." );
262- }
263- disableWithError ("Couldn't find an empty space to look at! Disabling..." );
264- }
265-
266- @ SubscribeEvent
267- public void onChatMessage (ClientChatReceivedEvent event ) {
268- if (enabled && event .type == 0 && event .message != null && event .message .getFormattedText ().contains ("§eClick in the air!" )) {
269- lookInTheAir ();
270- currentState = State .HOLD_RANCHER_BOOTS ;
271- clock .schedule (500 );
272- }
273- }
274-
275135 @ SubscribeEvent
276136 public void onWorldChange (WorldEvent .Unload event ) {
277137 if (enabled ) {
@@ -282,18 +142,9 @@ public void onWorldChange(WorldEvent.Unload event) {
282142 public enum State {
283143 NONE ,
284144 START ,
285- OPEN_INVENTORY ,
286- TAKE_OFF_BOOTS ,
287- CLOSE_INVENTORY ,
288- LOOK_IN_THE_AIR ,
289- HOLD_RANCHER_BOOTS ,
290- CLICK_RANCHER_BOOTS ,
145+ TYPE_COMMAND ,
291146 TYPE_IN_SPEED ,
292147 CLOSE_SIGN ,
293- LOOK_BACK ,
294- OPEN_INVENTORY_AGAIN ,
295- PUT_ON_BOOTS ,
296- CLOSE_INVENTORY_AGAIN ,
297148 END
298149 }
299150}
0 commit comments