1
1
/*
2
- * Copyright (c) 2014-2024 Wurst-Imperium and contributors.
2
+ * Copyright (c) 2014-2023 Wurst-Imperium and contributors.
3
3
*
4
4
* This source code is subject to the terms of the GNU General Public
5
5
* License, version 3. If a copy of the GPL was not distributed with this
55
55
import net .wurstclient .util .BlockBreaker .BlockBreakingParams ;
56
56
import net .wurstclient .util .BlockPlacer .BlockPlacingParams ;
57
57
58
+ import de .maxhenkel .tradecycling .FabricTradeCyclingClientMod ;
59
+
58
60
@ SearchTags ({"auto librarian" , "AutoVillager" , "auto villager" ,
59
61
"VillagerTrainer" , "villager trainer" , "LibrarianTrainer" ,
60
62
"librarian trainer" , "AutoHmmm" , "auto hmmm" })
61
63
public final class AutoLibrarianHack extends Hack
62
64
implements UpdateListener , RenderListener
63
65
{
66
+
64
67
private final BookOffersSetting wantedBooks = new BookOffersSetting (
65
68
"Wanted books" ,
66
69
"A list of enchanted books that you want your villagers to sell.\n \n "
@@ -84,6 +87,10 @@ public final class AutoLibrarianHack extends Hack
84
87
+ " 64 emeralds will also work." ,
85
88
false );
86
89
90
+ private final CheckboxSetting useTradeCycle =
91
+ new CheckboxSetting ("TradeCycles" ,
92
+ "Whether to use the Trade Cycles Mod (Must be Installed)" , false );
93
+
87
94
private final UpdateBooksSetting updateBooks = new UpdateBooksSetting ();
88
95
89
96
private final SliderSetting range =
@@ -132,6 +139,7 @@ public AutoLibrarianHack()
132
139
setCategory (Category .OTHER );
133
140
addSetting (wantedBooks );
134
141
addSetting (lockInTrade );
142
+ addSetting (useTradeCycle );
135
143
addSetting (updateBooks );
136
144
addSetting (range );
137
145
addSetting (facing );
@@ -170,6 +178,7 @@ protected void onDisable()
170
178
@ Override
171
179
public void onUpdate ()
172
180
{
181
+
173
182
if (villager == null )
174
183
{
175
184
setTargetVillager ();
@@ -185,90 +194,153 @@ public void onUpdate()
185
194
if (placingJobSite && breakingJobSite )
186
195
throw new IllegalStateException (
187
196
"Trying to place and break job site at the same time. Something is wrong." );
188
-
189
- if (placingJobSite )
190
- {
191
- placeJobSite ();
192
- return ;
193
- }
194
-
195
- if (breakingJobSite )
196
- {
197
- breakJobSite ();
198
- return ;
199
- }
200
-
201
- if (!(MC .currentScreen instanceof MerchantScreen tradeScreen ))
202
- {
203
- openTradeScreen ();
204
- return ;
205
- }
206
-
207
- // Can't see experience until the trade screen is open, so we have to
208
- // check it here and start over if the villager is already experienced.
209
- int experience = tradeScreen .getScreenHandler ().getExperience ();
210
- if (experience > 0 )
211
- {
212
- ChatUtils .warning ("Villager at "
213
- + villager .getBlockPos ().toShortString ()
214
- + " is already experienced, meaning it can't be trained anymore." );
215
- ChatUtils .message ("Looking for another villager..." );
216
- experiencedVillagers .add (villager );
217
- villager = null ;
218
- jobSite = null ;
219
- closeTradeScreen ();
220
- return ;
221
- }
222
-
223
- // check which book the villager is selling
224
- BookOffer bookOffer =
225
- findEnchantedBookOffer (tradeScreen .getScreenHandler ().getRecipes ());
226
-
227
- if (bookOffer == null )
228
- {
229
- ChatUtils .message ("Villager is not selling an enchanted book." );
230
- closeTradeScreen ();
231
- breakingJobSite = true ;
232
- System .out .println ("Breaking job site..." );
233
- return ;
234
- }
235
-
236
- ChatUtils .message (
237
- "Villager is selling " + bookOffer .getEnchantmentNameWithLevel ()
238
- + " for " + bookOffer .getFormattedPrice () + "." );
239
-
240
- // if wrong enchantment, break job site and start over
241
- if (!wantedBooks .isWanted (bookOffer ))
197
+ if (!(useTradeCycle .isChecked ()))
242
198
{
243
- breakingJobSite = true ;
244
- System .out .println ("Breaking job site..." );
245
- closeTradeScreen ();
246
- return ;
247
- }
248
-
249
- // lock in the trade, if enabled
250
- if (lockInTrade .isChecked ())
199
+ if (placingJobSite )
200
+ {
201
+ placeJobSite ();
202
+ return ;
203
+ }
204
+
205
+ if (breakingJobSite )
206
+ {
207
+ breakJobSite ();
208
+ return ;
209
+ }
210
+
211
+ if (!(MC .currentScreen instanceof MerchantScreen tradeScreen ))
212
+ {
213
+ openTradeScreen ();
214
+ return ;
215
+ }
216
+
217
+ // Can't see experience until the trade screen is open, so we have
218
+ // to
219
+ // check it here and start over if the villager is already
220
+ // experienced.
221
+ int experience = tradeScreen .getScreenHandler ().getExperience ();
222
+ if (experience > 0 )
223
+ {
224
+ ChatUtils .warning ("Villager at "
225
+ + villager .getBlockPos ().toShortString ()
226
+ + " is already experienced, meaning it can't be trained anymore." );
227
+ ChatUtils .message ("Looking for another villager..." );
228
+ experiencedVillagers .add (villager );
229
+ villager = null ;
230
+ jobSite = null ;
231
+ closeTradeScreen ();
232
+ return ;
233
+ }
234
+
235
+ // check which book the villager is selling
236
+ BookOffer bookOffer = findEnchantedBookOffer (
237
+ tradeScreen .getScreenHandler ().getRecipes ());
238
+
239
+ if (bookOffer == null )
240
+ {
241
+ ChatUtils .message ("Villager is not selling an enchanted book." );
242
+ closeTradeScreen ();
243
+ breakingJobSite = true ;
244
+ System .out .println ("Breaking job site..." );
245
+ return ;
246
+ }
247
+
248
+ ChatUtils .message (
249
+ "Villager is selling " + bookOffer .getEnchantmentNameWithLevel ()
250
+ + " for " + bookOffer .getFormattedPrice () + "." );
251
+
252
+ // if wrong enchantment, break job site and start over
253
+ if (!wantedBooks .isWanted (bookOffer ))
254
+ {
255
+ breakingJobSite = true ;
256
+ System .out .println ("Breaking job site..." );
257
+ closeTradeScreen ();
258
+ return ;
259
+ }
260
+
261
+ // lock in the trade, if enabled
262
+ if (lockInTrade .isChecked ())
263
+ {
264
+ // select the first valid trade
265
+ tradeScreen .getScreenHandler ().setRecipeIndex (0 );
266
+ tradeScreen .getScreenHandler ().switchTo (0 );
267
+ MC .getNetworkHandler ()
268
+ .sendPacket (new SelectMerchantTradeC2SPacket (0 ));
269
+
270
+ // buy whatever the villager is selling
271
+ MC .interactionManager .clickSlot (
272
+ tradeScreen .getScreenHandler ().syncId , 2 , 0 ,
273
+ SlotActionType .PICKUP , MC .player );
274
+
275
+ // close the trade screen
276
+ closeTradeScreen ();
277
+ }
278
+
279
+ // update wanted books based on the user's settings
280
+ updateBooks .getSelected ().update (wantedBooks , bookOffer );
281
+ }else
251
282
{
252
- // select the first valid trade
253
- tradeScreen .getScreenHandler ().setRecipeIndex (0 );
254
- tradeScreen .getScreenHandler ().switchTo (0 );
255
- MC .getNetworkHandler ()
256
- .sendPacket (new SelectMerchantTradeC2SPacket (0 ));
283
+ if (!(MC .currentScreen instanceof MerchantScreen tradeScreen ))
284
+ {
285
+ openTradeScreen ();
286
+ return ;
287
+ }
288
+ int experience = tradeScreen .getScreenHandler ().getExperience ();
289
+ if (experience > 0 )
290
+ {
291
+ ChatUtils .warning ("Villager at "
292
+ + villager .getBlockPos ().toShortString ()
293
+ + " is already experienced, meaning it can't be trained anymore." );
294
+ ChatUtils .message ("Looking for another villager..." );
295
+ experiencedVillagers .add (villager );
296
+ villager = null ;
297
+ jobSite = null ;
298
+ closeTradeScreen ();
299
+ return ;
300
+ }
257
301
258
- // buy whatever the villager is selling
259
- MC .interactionManager .clickSlot (
260
- tradeScreen .getScreenHandler ().syncId , 2 , 0 ,
261
- SlotActionType .PICKUP , MC .player );
302
+ BookOffer bookOffer = findEnchantedBookOffer (
303
+ tradeScreen .getScreenHandler ().getRecipes ());
262
304
263
- // close the trade screen
264
- closeTradeScreen ();
305
+ if (bookOffer == null )
306
+ {
307
+ ChatUtils .message ("Villager is not selling an enchanted book." );
308
+ FabricTradeCyclingClientMod .sendCycleTradesPacket ();
309
+ return ;
310
+ }
311
+ ChatUtils .message (
312
+ "Villager is selling " + bookOffer .getEnchantmentNameWithLevel ()
313
+ + " for " + bookOffer .getFormattedPrice () + "." );
314
+
315
+ // if wrong enchantment, refresh and start over
316
+ if (!wantedBooks .isWanted (bookOffer ))
317
+ {
318
+ FabricTradeCyclingClientMod .sendCycleTradesPacket ();
319
+ return ;
320
+ }
321
+
322
+ if (lockInTrade .isChecked ())
323
+ {
324
+ // select the first valid trade
325
+ tradeScreen .getScreenHandler ().setRecipeIndex (0 );
326
+ tradeScreen .getScreenHandler ().switchTo (0 );
327
+ MC .getNetworkHandler ()
328
+ .sendPacket (new SelectMerchantTradeC2SPacket (0 ));
329
+
330
+ // buy whatever the villager is selling
331
+ MC .interactionManager .clickSlot (
332
+ tradeScreen .getScreenHandler ().syncId , 2 , 0 ,
333
+ SlotActionType .PICKUP , MC .player );
334
+
335
+ // close the trade screen
336
+ closeTradeScreen ();
337
+ }
338
+ // update wanted books based on the user's settings
339
+ updateBooks .getSelected ().update (wantedBooks , bookOffer );
265
340
}
266
-
267
- // update wanted books based on the user's settings
268
- updateBooks .getSelected ().update (wantedBooks , bookOffer );
269
-
270
341
ChatUtils .message ("Done!" );
271
342
setEnabled (false );
343
+
272
344
}
273
345
274
346
private void breakJobSite ()
@@ -556,4 +628,5 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
556
628
if (breakingJobSite )
557
629
overlay .render (matrixStack , partialTicks , jobSite );
558
630
}
631
+
559
632
}
0 commit comments