aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/garden
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-06-16 11:24:33 -0400
committerGitHub <noreply@github.com>2024-06-16 11:24:33 -0400
commit28c362384e728dbb2b02961e4ef46849286ce84d (patch)
tree93da757fb2fe778a8cfad1cd8d069658828f9bca /src/main/java/de/hysky/skyblocker/skyblock/garden
parentbf36add23cc29997674877986105fe355339ce12 (diff)
parent8bb84dfe1574f9890d67d2f16d6227aa13979115 (diff)
downloadSkyblocker-28c362384e728dbb2b02961e4ef46849286ce84d.tar.gz
Skyblocker-28c362384e728dbb2b02961e4ef46849286ce84d.tar.bz2
Skyblocker-28c362384e728dbb2b02961e4ef46849286ce84d.zip
Merge pull request #775 from SkyblockerMod/farming-price-fix
Use NPC price if its higher
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/garden')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
index d081910d..c413ad44 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
@@ -2,6 +2,7 @@ package de.hysky.skyblocker.skyblock.garden;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
+import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
@@ -68,9 +69,7 @@ public class FarmingHudWidget extends Widget {
addSimpleIcoText(cropStack, FarmingHud.counterText(), Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter()));
float cropsPerMinute = FarmingHud.cropsPerMinute();
addSimpleIcoText(cropStack, "Crops/min: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) cropsPerMinute / 10 * 10));
- DoubleBooleanPair itemPrice = ItemUtils.getItemPrice(cropItemId);
- addSimpleIcoText(Ico.GOLD, "Coins/h: ", Formatting.GOLD, itemPrice.rightBoolean() ? FarmingHud.NUMBER_FORMAT.format((int) (itemPrice.leftDouble() * cropsPerMinute * 0.6) * 100) : "No Data"); // Multiply by 60 to convert to hourly and divide by 100 for rounding is combined into multiplying by 0.6
-
+ addSimpleIcoText(Ico.GOLD, "Coins/h: ", Formatting.GOLD, getPriceText(cropItemId, cropsPerMinute));
addSimpleIcoText(cropStack, "Blocks/s: ", Formatting.YELLOW, Integer.toString(FarmingHud.blockBreaks()));
//noinspection DataFlowIssue
addComponent(new ProgressComponent(Ico.LANTERN, Text.literal("Farming Level: "), FarmingHud.farmingXpPercentProgress(), Formatting.GOLD.getColorValue()));
@@ -85,4 +84,18 @@ public class FarmingHudWidget extends Widget {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.garden.hud.mouseLocked").formatted(Formatting.ITALIC)));
}
}
+
+ /**
+ * Gets the price text of the given crop id, calculated with the given crops per minute and the npc price if it's higher than the bazaar sell price, or the bazaar sell price otherwise.
+ */
+ private String getPriceText(String cropItemId, float cropsPerMinute) {
+ DoubleBooleanPair itemBazaarPrice = ItemUtils.getItemPrice(cropItemId); // Gets the bazaar sell price of the crop.
+ double itemNpcPrice = TooltipInfoType.NPC.hasOrNullWarning(cropItemId) ? TooltipInfoType.NPC.getData().get(cropItemId).getAsDouble() : Double.MIN_VALUE; // Gets the npc sell price of the crop or set to the min double value if it doesn't exist.
+ boolean shouldUseNpcPrice = itemNpcPrice > itemBazaarPrice.leftDouble(); // Use the npc price if it's more than the bazaar sell price.
+ double price = shouldUseNpcPrice ? itemNpcPrice : itemBazaarPrice.leftDouble(); // same as above
+
+ // Return the formatted price if npc price is higher or bazaar price is present.
+ // Multiply by 60 to convert to hourly and divide by 100 for rounding is combined into multiplying by 0.6.
+ return shouldUseNpcPrice || itemBazaarPrice.rightBoolean() ? FarmingHud.NUMBER_FORMAT.format((int) (price * cropsPerMinute * 0.6) * 100) : "No Data";
+ }
}