package kr.syeyoung.dungeonsguide.features.impl; import kr.syeyoung.dungeonsguide.features.FeatureParameter; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.features.SimpleFeature; import kr.syeyoung.dungeonsguide.features.listener.TooltipListener; import kr.syeyoung.dungeonsguide.utils.AhUtils; import kr.syeyoung.dungeonsguide.utils.TextUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import org.lwjgl.input.Keyboard; import java.util.Comparator; import java.util.Set; import java.util.TreeSet; public class FeatureTooltipPrice extends SimpleFeature implements TooltipListener { public FeatureTooltipPrice() { super("ETC", "Item Price", "Shows price of items", "tooltip.price"); parameters.put("reqShift", new FeatureParameter("reqShift", "Require Shift", "If shift needs to be pressed in order for this feature to be activated", false, "boolean")); } @Override public void onTooltip(ItemTooltipEvent event) { if (!isEnabled()) return; boolean activated = !this.getParameter("reqShift").getValue() || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); ItemStack hoveredItem = event.itemStack; NBTTagCompound compound = hoveredItem.getTagCompound(); if (compound == null) return; if (!compound.hasKey("ExtraAttributes")) return; if (!activated) { event.toolTip.add("§7Shift to view price"); return; } final String id = compound.getCompoundTag("ExtraAttributes").getString("id"); if (id.equals("ENCHANTED_BOOK")) { final NBTTagCompound enchants = compound.getCompoundTag("ExtraAttributes").getCompoundTag("enchantments"); Set keys = enchants.getKeySet(); Set actualKeys = new TreeSet(new Comparator() { public int compare(String o1, String o2) { String id2 = id + "::" + o1 + "-" + enchants.getInteger(o1); AhUtils.AuctionData auctionData = AhUtils.auctions.get(id2); int price1 = (auctionData == null) ? 0 : auctionData.lowestBin; String id3 = id + "::" + o2 + "-" + enchants.getInteger(o2); AhUtils.AuctionData auctionData2 = AhUtils.auctions.get(id3); int price2 = (auctionData2 == null) ? 0 : auctionData2.lowestBin; return (compare2(price1, price2) == 0) ? o1.compareTo(o2) : compare2(price1, price2); } public int compare2(int y, int x) { return (x < y) ? -1 : ((x == y) ? 0 : 1); } }); actualKeys.addAll(keys); int totalLowestPrice = 0; int iterations = 0; for (String key : actualKeys) { iterations++; String id2 = id + "::" + key + "-" + enchants.getInteger(key); AhUtils.AuctionData auctionData = AhUtils.auctions.get(id2); if (auctionData == null) { if (iterations < 10) event.toolTip.add("§f"+ key + " " + enchants.getInteger(key) + "§7: §cn/a"); continue; } if (iterations < 10) event.toolTip.add("§f"+ key + " " + enchants.getInteger(key) + "§7: §e"+ TextUtils.format( auctionData.lowestBin)); totalLowestPrice += auctionData.lowestBin; } if (iterations >= 10) event.toolTip.add("§7"+ (iterations - 10) + " more enchants... "); event.toolTip.add("§fTotal Lowest§7: §e"+ TextUtils.format(totalLowestPrice)); } else { AhUtils.AuctionData auctionData = AhUtils.auctions.get(id); event.toolTip.add(""); if (auctionData == null) { event.toolTip.add("§fLowest ah §7: §cn/a"); event.toolTip.add("§fBazaar sell price §7: §cn/a"); event.toolTip.add("§fBazaar buy price §7: §cn/a"); } else { event.toolTip.add("§fLowest ah §7: " + ((auctionData.lowestBin != -1) ? ("§e"+ TextUtils.format(auctionData.lowestBin)) : "§cn/a")); event.toolTip.add("§fBazaar sell price §7: " + ((auctionData.sellPrice == -1) ? "§cn/a": ("§e"+ TextUtils.format(auctionData.sellPrice)))); event.toolTip.add("§fBazaar buy price §7: " + ((auctionData.buyPrice == -1) ? "§cn/a": ("§e"+ TextUtils.format(auctionData.buyPrice)))); } } } }