From 1254320033d9345c8cf27e2dbeeb0b098735d029 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 11 May 2024 00:35:40 -0400 Subject: (AutoTrade) Allow setting a maximum acceptable price. --- .../chrisoft/trashyaddon/modules/AutoTrade.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/chrisoft/trashyaddon/modules/AutoTrade.java') diff --git a/src/main/java/org/chrisoft/trashyaddon/modules/AutoTrade.java b/src/main/java/org/chrisoft/trashyaddon/modules/AutoTrade.java index c5df1b9..0b71598 100644 --- a/src/main/java/org/chrisoft/trashyaddon/modules/AutoTrade.java +++ b/src/main/java/org/chrisoft/trashyaddon/modules/AutoTrade.java @@ -20,14 +20,11 @@ import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOfferList; import org.chrisoft.trashyaddon.mixin.MerchantScreenAccessor; -import java.util.ArrayList; -import java.util.Formatter; -import java.util.List; -import java.util.Optional; +import java.util.*; public class AutoTrade extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private static final List allSellItems = List.of( + public static final List allSellItems = List.of( Items.COAL, Items.CHICKEN, Items.PORKCHOP, @@ -73,7 +70,7 @@ public class AutoTrade extends Module { Items.QUARTZ ); - private static final List allBuyItems = List.of( + public static final List allBuyItems = List.of( Items.BELL, Items.COOKED_PORKCHOP, Items.COOKED_CHICKEN, @@ -129,6 +126,12 @@ public class AutoTrade extends Module { .filter((item) -> allBuyItems.contains(item)) .build() ); + private final Setting acceptablePricesSetting = sgGeneral.add(new GenericSetting.Builder() + .name("acceptable-prices") + .description("Configure maximum acceptable price for each item.") + .defaultValue(new AcceptablePrices(new HashMap<>())) + .build() + ); private final Setting interactionRate = sgGeneral.add(new IntSetting.Builder() .name("Interaction Rate") .description("Number of ticks between interactions.") @@ -190,10 +193,21 @@ public class AutoTrade extends Module { ItemStack msell = o.getSellItem(); List sells = sellingEnabled.get() ? this.sellsSetting.get() : List.of(); List buys = buyingEnabled.get() ? this.buysSetting.get() : List.of(); - if (!sells.contains(mbuy.getItem()) && !buys.contains(msell.getItem())) + Item interestedItem = null; + if (sells.contains(mbuy.getItem())) + interestedItem = mbuy.getItem(); + if (buys.contains(msell.getItem())) + interestedItem = msell.getItem(); + if (interestedItem == null) return false; + Integer maxPrice = acceptablePricesSetting.get().getMaxPriceForItem(interestedItem); + if (maxPrice != null && mbuy.getCount() > maxPrice) { + return false; + } FindItemResult rs = InvUtils.find((stack) -> stack.getItem().equals(mbuy.getItem()) && stack.getCount() >= mbuy.getCount()); - if (!rs.found()) + ItemStack s0is = screen.getScreenHandler().slots.get(0).getStack(); + boolean remainingFirstSlotSufficient = s0is.getItem().equals(mbuy.getItem()) && s0is.getCount() >= mbuy.getCount(); + if (!rs.found() && !remainingFirstSlotSufficient) return false; return true; } -- cgit v1.2.3