diff options
Diffstat (limited to 'src')
5 files changed, 123 insertions, 2 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java index 99e8f22e..ea84dfc3 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java @@ -6,6 +6,7 @@ import kr.syeyoung.dungeonsguide.features.*; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.listener.*; import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -97,4 +98,19 @@ public class FeatureListener { } } } + @SubscribeEvent + public void onTick(GuiOpenEvent tick) { + try { + SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnSkyblock()) return; + + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature instanceof GuiOpenListener) { + ((GuiOpenListener) abstractFeature).onGuiOpen(tick); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index d04ed884..09bb1511 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -1,6 +1,7 @@ package kr.syeyoung.dungeonsguide.features; import kr.syeyoung.dungeonsguide.features.impl.FeatureCooldownCounter; +import kr.syeyoung.dungeonsguide.features.impl.FeatureInstaCloseChest; import kr.syeyoung.dungeonsguide.features.impl.FeatureTooltipDungeonStat; import kr.syeyoung.dungeonsguide.features.impl.FeatureTooltipPrice; import lombok.Getter; @@ -52,5 +53,6 @@ public class FeatureRegistry { public static final SimpleFeature DEBUG = register(new SimpleFeature("hidden", "Debug", "Toggles debug mode", "debug", false)); - public static final FeatureCooldownCounter QOL_COOLDOWN = (FeatureCooldownCounter) register(new FeatureCooldownCounter()); + public static final FeatureCooldownCounter QOL_COOLDOWN = register(new FeatureCooldownCounter()); + public static final FeatureInstaCloseChest QOL_INSTACLOSE = register(new FeatureInstaCloseChest()); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureInstaCloseChest.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureInstaCloseChest.java new file mode 100644 index 00000000..79fbfce6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureInstaCloseChest.java @@ -0,0 +1,96 @@ +package kr.syeyoung.dungeonsguide.features.impl; + +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.features.FeatureParameter; +import kr.syeyoung.dungeonsguide.features.GuiFeature; +import kr.syeyoung.dungeonsguide.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.features.listener.GuiOpenListener; +import kr.syeyoung.dungeonsguide.features.listener.TickListener; +import kr.syeyoung.dungeonsguide.utils.AhUtils; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.client.event.GuiOpenEvent; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + +public class FeatureInstaCloseChest extends SimpleFeature implements GuiOpenListener { + public FeatureInstaCloseChest() { + super("QoL", "Auto-Close Secret Chest", "Automatically closes Secret Chest as soon as you open it\nCan put item price threshold by clicking edit", "qol.autoclose", false); + parameters.put("threshold", new FeatureParameter<Integer>("threshold", "Price Threshold", "The maximum price of item for chest to be closed. Default 1m", 1000000, "integer")); + } + + SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); + @Override + public void onGuiOpen(GuiOpenEvent event) { + if (!skyblockStatus.isOnDungeon()) return; + if (!(event.gui instanceof GuiChest)) return; + + int threshold = this.<Integer>getParameter("threshold").getValue(); + + int priceSum = 0; + for (ItemStack inventoryItemStack : ((GuiChest) event.gui).inventorySlots.inventoryItemStacks) { + priceSum += getPrice(inventoryItemStack); + } + + if (priceSum < threshold) Minecraft.getMinecraft().thePlayer.closeScreen(); + } + + public int getPrice(ItemStack itemStack) { + if (itemStack == null) return 0; + NBTTagCompound compound = itemStack.getTagCompound(); + if (compound == null) + return 0; + if (!compound.hasKey("ExtraAttributes")) + return 0; + final String id = compound.getCompoundTag("ExtraAttributes").getString("id"); + if (id.equals("ENCHANTED_BOOK")) { + final NBTTagCompound enchants = compound.getCompoundTag("ExtraAttributes").getCompoundTag("enchantments"); + Set<String> keys = enchants.getKeySet(); + Set<String> actualKeys = new TreeSet<String>(new Comparator<String>() { + 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 : ((Integer)auctionData.prices.first()).intValue(); + String id3 = id + "::" + o2 + "-" + enchants.getInteger(o2); + AhUtils.AuctionData auctionData2 = AhUtils.auctions.get(id3); + int price2 = (auctionData2 == null) ? 0 : ((Integer)auctionData2.prices.first()).intValue(); + 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; + for (String key : actualKeys) { + String id2 = id + "::" + key + "-" + enchants.getInteger(key); + AhUtils.AuctionData auctionData = AhUtils.auctions.get(id2); + totalLowestPrice += auctionData.prices.first(); + } + return totalLowestPrice; + } else { + AhUtils.AuctionData auctionData = AhUtils.auctions.get(id); + if (auctionData == null) { + return 0; + } else { + if (auctionData.sellPrice == -1 && auctionData.prices.size() > 0) return auctionData.prices.first(); + else if (auctionData.sellPrice != -1 && auctionData.prices.size() == 0) return auctionData.sellPrice; + else { + int ahPrice = auctionData.prices.first(); + if (ahPrice > auctionData.sellPrice) return ahPrice; + else return auctionData.sellPrice; + } + } + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureTooltipPrice.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureTooltipPrice.java index b54fa682..b9059427 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureTooltipPrice.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/FeatureTooltipPrice.java @@ -67,7 +67,7 @@ public class FeatureTooltipPrice extends SimpleFeature implements TooltipListene } if (iterations >= 10) event.toolTip.add("§7"+ (iterations - 10) + " more enchants... "); - event.toolTip.add("§fTotal§7 §e:"+ TextUtils.format(totalLowestPrice) + " §7to§e "+ TextUtils.format(totalHighestPrice)); + event.toolTip.add("§fTotal§7: §e"+ TextUtils.format(totalLowestPrice) + " §7to§e "+ TextUtils.format(totalHighestPrice)); } else { AhUtils.AuctionData auctionData = AhUtils.auctions.get(id); event.toolTip.add(""); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/listener/GuiOpenListener.java b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/GuiOpenListener.java new file mode 100644 index 00000000..07029b74 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/GuiOpenListener.java @@ -0,0 +1,7 @@ +package kr.syeyoung.dungeonsguide.features.listener; + +import net.minecraftforge.client.event.GuiOpenEvent; + +public interface GuiOpenListener { + void onGuiOpen(GuiOpenEvent event); +} |