Skip to content

Commit

Permalink
AutoBazaar (Visitors Macro):
Browse files Browse the repository at this point in the history
 = Buying hotfix (and another one)
  • Loading branch information
May2Beez committed Mar 31, 2024
1 parent 338f5ed commit 36b9fec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.5.12
version=2.5.13
shouldRelease=true
20 changes: 14 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AutoBazaar.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,9 @@ private void handleBuyFromBz() {
if (this.openedChestGuiNameStartsWith(this.itemToBuy + " ➜ Instant Buy")) {
log("Opened instant buy page");
this.timer.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
this.buyState = BuyState.OPEN_SIGN;

Predicate<Slot> buyPredicate = slot -> slot.getHasStack()
&& StringUtils.stripControlCodes(slot.getStack().getDisplayName()).startsWith("Buy")
&& (StringUtils.stripControlCodes(slot.getStack().getDisplayName()).startsWith("Buy") || StringUtils.stripControlCodes(slot.getStack().getDisplayName()).startsWith("Fill"))
&& slot.slotNumber < mc.thePlayer.openContainer.inventorySlots.size() - 37;
List<Slot> buySlots = InventoryUtils.getIndexesOfItemsFromContainer(buyPredicate);

Expand All @@ -262,16 +261,25 @@ private void handleBuyFromBz() {
String lore = String.join(" ", InventoryUtils.getItemLore(slot.getStack()));
Matcher matcher = this.instabuyAmountPattern.matcher(lore);

if (matcher.find() && this.buyAmount == Integer.parseInt(matcher.group(1))) {
if (matcher.find() && this.buyAmount == Integer.parseInt(matcher.group(1).replace(",", ""))) {
this.buyNowButtonSlot = slot.slotNumber;
this.buyState = BuyState.CLICK_BUY;
System.out.println("Clicking button at slot: " + slot.slotNumber);
return;
}
if (lore.contains("Loading...")) { // Makes more sense down here
this.buyState = BuyState.BUY_INSTANTLY_VERIFY;
return;
}
}

Slot customAmount = InventoryUtils.getSlotOfItemInContainer("Custom Amount");
if (customAmount != null && customAmount.getHasStack()) {
this.buyState = BuyState.OPEN_SIGN;
this.buyNowButtonSlot = customAmount.slotNumber;
LogUtils.sendDebug("[Auto Bazaar] Buying custom amount");
return;
}
}
if (this.hasTimerEnded()) {
this.disable("Could not open buy instantly page.");
Expand All @@ -280,13 +288,13 @@ private void handleBuyFromBz() {
case OPEN_SIGN:
if (!this.hasTimerEnded()) return;

int signSlot = InventoryUtils.getSlotIdOfItemInContainer("Custom Amount");
if (signSlot == -1) {
Slot signSlot = InventoryUtils.getSlotOfIdInContainer(this.buyNowButtonSlot);
if (signSlot == null || !signSlot.getHasStack()) {
this.disable("Could not find sign.");
return;
}

InventoryUtils.clickContainerSlot(signSlot, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
InventoryUtils.clickContainerSlot(signSlot.slotNumber, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
this.timer.schedule(2000);
this.buyState = BuyState.OPEN_SIGN_VERIFY;
log("In open Sign.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ private void onVisitorsState() {
return;
}
if (FlyPathFinderExecutor.getInstance().isRunning()) {
if (!rotation.isRotating() && currentCharacter.isPresent()) {
rotation.easeTo(
new RotationConfiguration(
new Target(currentCharacter.get()),
FarmHelperConfig.getRandomRotationTime(),
null
).followTarget(true)
);
}
return;
}
if (PlayerUtils.getFarmingTool(MacroHandler.getInstance().getCrop(), true, true) != -1) {
Expand Down Expand Up @@ -1011,6 +1020,18 @@ private void onVisitorsState() {
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
break;
}
if (FlyPathFinderExecutor.getInstance().isRunning()) {
if (!rotation.isRotating() && currentCharacter.isPresent()) {
rotation.easeTo(
new RotationConfiguration(
new Target(currentCharacter.get()),
FarmHelperConfig.getRandomRotationTime(),
null
).followTarget(true)
);
}
return;
}
if (rotation.isRotating()) return;
if (PlayerUtils.getFarmingTool(MacroHandler.getInstance().getCrop(), true, true) != -1) {
mc.thePlayer.inventory.currentItem = PlayerUtils.getFarmingTool(MacroHandler.getInstance().getCrop(), true, true);
Expand Down Expand Up @@ -1282,7 +1303,7 @@ private Entity getClosestVisitor() {
private Stream<Entity> getVisitors() {
return mc.theWorld.getLoadedEntityList().stream()
.filter(e -> e instanceof EntityArmorStand)
.filter(e -> e.getDistanceToEntity(mc.thePlayer) < 12)
.filter(e -> e.getDistanceToEntity(mc.thePlayer) < 25)
.filter(e -> !servedCustomers.contains(e))
.filter(entity2 -> entity2.hasCustomName() && visitors.stream().anyMatch(v -> equalsWithoutFormatting(v, entity2.getCustomNameTag())))
.filter(entity2 -> !ignoredNPCs.contains(entity2));
Expand Down

0 comments on commit 36b9fec

Please sign in to comment.