-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added EssenceShopPrice Feature, moved concatenate methods from ChocolateFactorySolver to Utils as they most likely will be used many times Co-authored-by: Rime <[email protected]> Co-authored-by: Kevinthegreat <[email protected]>
- Loading branch information
1 parent
50b7a16
commit cceaa38
Showing
10 changed files
with
130 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.hysky.skyblocker.skyblock.item.tooltip.adders; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; | ||
import de.hysky.skyblocker.utils.ItemUtils; | ||
import de.hysky.skyblocker.utils.RegexUtils; | ||
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.text.NumberFormat; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.OptionalLong; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class EssenceShopPrice extends TooltipAdder { | ||
private static final Pattern ESSENCE_PATTERN = Pattern.compile("Cost (?<amount>[\\d,]+) (?<type>[A-Za-z]+) Essence"); | ||
private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US); | ||
private static final String[] ESSENCE_TYPES = {"WITHER", "SPIDER", "UNDEAD", "DRAGON", "GOLD", "DIAMOND", "ICE", "CRIMSON"}; | ||
private static final Object2LongArrayMap<String> ESSENCE_PRICES = new Object2LongArrayMap<>(ESSENCE_TYPES, new long[8]); | ||
|
||
public EssenceShopPrice(int priority) { | ||
super("\\S+ Essence Shop", priority); | ||
} | ||
|
||
public static void refreshEssencePrices(JsonObject data) { | ||
for (String essenceType : ESSENCE_TYPES) { | ||
JsonElement price = data.get("ESSENCE_" + essenceType); | ||
if (price == null || !price.isJsonObject()) continue; | ||
JsonElement sellPrice = price.getAsJsonObject().get("sellPrice"); | ||
if (sellPrice == null) continue; | ||
if (sellPrice.isJsonPrimitive()) { | ||
ESSENCE_PRICES.put(essenceType, sellPrice.getAsLong()); | ||
} | ||
} | ||
} | ||
|
||
//Todo: maybe move the price value right after the essence amount ex: "1,500 Wither Essence (645k coins)" | ||
@Override | ||
public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { | ||
if (!SkyblockerConfigManager.get().general.itemTooltip.showEssenceCost) return; | ||
|
||
String lore = ItemUtils.concatenateLore(lines); | ||
Matcher essenceMatcher = ESSENCE_PATTERN.matcher(lore); | ||
OptionalLong cost = RegexUtils.getLongFromMatcher(essenceMatcher); | ||
if (cost.isEmpty()) return; | ||
|
||
String type = essenceMatcher.group("type"); | ||
long priceData = ESSENCE_PRICES.getLong(type.toUpperCase(Locale.ROOT)); | ||
if (priceData == 0) return; //Default value for getLong is 0 if no value exists for that key | ||
|
||
lines.add(Text.empty() | ||
.append(Text.literal("Essence Cost: ").formatted(Formatting.AQUA)) | ||
.append(Text.literal(DECIMAL_FORMAT.format(priceData * cost.getAsLong()) + " coins").formatted(Formatting.DARK_AQUA)) | ||
.append(Text.literal(" (").formatted(Formatting.GRAY)) | ||
.append(Text.literal(DECIMAL_FORMAT.format(priceData) + " each").formatted(Formatting.GRAY)) | ||
.append(Text.literal(")").formatted(Formatting.GRAY)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters