Skip to content

Commit bd90e93

Browse files
author
BuildTools
committed
Will this work
1 parent fe2f724 commit bd90e93

10 files changed

+564
-102
lines changed

build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ repositories {
2525
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
2626
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
2727
// for more information about repositories.
28+
maven {
29+
url "https://cursemaven.com"
30+
}
2831
}
2932

3033
dependencies {
@@ -43,6 +46,8 @@ dependencies {
4346
// In other words, Wurst won't compile without this library,
4447
// even though it's Minecraft that actually uses it.
4548
modImplementation 'com.google.code.findbugs:jsr305:3.0.2'
49+
50+
modImplementation "curse.maven:trade-cycling-570431:4680049"
4651
}
4752

4853
loom {

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fabric_version=0.92.0+1.20.1
1515
# Mod Properties
1616
mod_version = v7.41.1-MC1.20.1
1717
maven_group = net.wurstclient
18-
archives_base_name = Wurst-Client
18+
archives_base_name = Worst-Client
1919

2020
# Dependencies

src/main/java/net/wurstclient/WurstClient.java

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.stream.Collectors;
1616
import java.util.stream.Stream;
1717

18+
import net.fabricmc.loader.api.FabricLoader;
1819
import org.lwjgl.glfw.GLFW;
1920

2021
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
@@ -156,6 +157,12 @@ public void initialize()
156157

157158
analytics.trackPageView("/mc" + MC_VERSION + "/v" + VERSION,
158159
"Wurst " + VERSION + " MC" + MC_VERSION);
160+
161+
}
162+
163+
public final boolean isTradeCylingPresent()
164+
{
165+
return FabricLoader.getInstance().isModLoaded("trade_cycling");
159166
}
160167

161168
private Path createWurstFolder()
@@ -354,4 +361,5 @@ public AltManager getAltManager()
354361
{
355362
return altManager;
356363
}
364+
357365
}

src/main/java/net/wurstclient/hack/HackList.java

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class HackList implements UpdateListener
4848
public final AutoDropHack autoDropHack = new AutoDropHack();
4949
public final AutoLeaveHack autoLeaveHack = new AutoLeaveHack();
5050
public final AutoLibrarianHack autoLibrarianHack = new AutoLibrarianHack();
51+
public final AutoTraderHack autoTraderHack = new AutoTraderHack();
5152
public final AutoEatHack autoEatHack = new AutoEatHack();
5253
public final AutoFarmHack autoFarmHack = new AutoFarmHack();
5354
public final AutoFishHack autoFishHack = new AutoFishHack();

src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java

+151-78
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
2+
* Copyright (c) 2014-2023 Wurst-Imperium and contributors.
33
*
44
* This source code is subject to the terms of the GNU General Public
55
* License, version 3. If a copy of the GPL was not distributed with this
@@ -55,12 +55,15 @@
5555
import net.wurstclient.util.BlockBreaker.BlockBreakingParams;
5656
import net.wurstclient.util.BlockPlacer.BlockPlacingParams;
5757

58+
import de.maxhenkel.tradecycling.FabricTradeCyclingClientMod;
59+
5860
@SearchTags({"auto librarian", "AutoVillager", "auto villager",
5961
"VillagerTrainer", "villager trainer", "LibrarianTrainer",
6062
"librarian trainer", "AutoHmmm", "auto hmmm"})
6163
public final class AutoLibrarianHack extends Hack
6264
implements UpdateListener, RenderListener
6365
{
66+
6467
private final BookOffersSetting wantedBooks = new BookOffersSetting(
6568
"Wanted books",
6669
"A list of enchanted books that you want your villagers to sell.\n\n"
@@ -84,6 +87,10 @@ public final class AutoLibrarianHack extends Hack
8487
+ " 64 emeralds will also work.",
8588
false);
8689

90+
private final CheckboxSetting useTradeCycle =
91+
new CheckboxSetting("TradeCycles",
92+
"Whether to use the Trade Cycles Mod (Must be Installed)", false);
93+
8794
private final UpdateBooksSetting updateBooks = new UpdateBooksSetting();
8895

8996
private final SliderSetting range =
@@ -132,6 +139,7 @@ public AutoLibrarianHack()
132139
setCategory(Category.OTHER);
133140
addSetting(wantedBooks);
134141
addSetting(lockInTrade);
142+
addSetting(useTradeCycle);
135143
addSetting(updateBooks);
136144
addSetting(range);
137145
addSetting(facing);
@@ -170,6 +178,7 @@ protected void onDisable()
170178
@Override
171179
public void onUpdate()
172180
{
181+
173182
if(villager == null)
174183
{
175184
setTargetVillager();
@@ -185,90 +194,153 @@ public void onUpdate()
185194
if(placingJobSite && breakingJobSite)
186195
throw new IllegalStateException(
187196
"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()))
242198
{
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
251282
{
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+
}
257301

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());
262304

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);
265340
}
266-
267-
// update wanted books based on the user's settings
268-
updateBooks.getSelected().update(wantedBooks, bookOffer);
269-
270341
ChatUtils.message("Done!");
271342
setEnabled(false);
343+
272344
}
273345

274346
private void breakJobSite()
@@ -556,4 +628,5 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
556628
if(breakingJobSite)
557629
overlay.render(matrixStack, partialTicks, jobSite);
558630
}
631+
559632
}

0 commit comments

Comments
 (0)