From 21abe2f9ea26f17f6d332ca7bf3f4b0f044aa77a Mon Sep 17 00:00:00 2001 From: syeyoung Date: Thu, 24 Dec 2020 16:41:27 +0900 Subject: TOOLTIPS --- .../java/kr/syeyoung/dungeonsguide/Config.java | 12 +- .../kr/syeyoung/dungeonsguide/EventListener.java | 234 -------------------- .../kr/syeyoung/dungeonsguide/SkyblockStatus.java | 1 + .../dungeon/data/DungeonRoomInfo.java | 2 +- src/main/java/kr/syeyoung/dungeonsguide/e.java | 10 +- .../eventlistener/DungeonListener.java | 238 +++++++++++++++++++++ .../eventlistener/ItemGuiListener.java | 106 +++++++++ .../kr/syeyoung/dungeonsguide/utils/AhUtils.java | 131 ++++++++++++ .../kr/syeyoung/dungeonsguide/utils/TextUtils.java | 29 +++ 9 files changed, 522 insertions(+), 241 deletions(-) delete mode 100755 src/main/java/kr/syeyoung/dungeonsguide/EventListener.java create mode 100755 src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java (limited to 'src/main/java') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/Config.java b/src/main/java/kr/syeyoung/dungeonsguide/Config.java index 03bd2396..eec433f9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/Config.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/Config.java @@ -6,8 +6,9 @@ import net.minecraftforge.common.config.Property; public class Config { public static Configuration configuration; - public static final String CATEGORY_ADVANCED = "advanced"; - public static final String CATEGORY_PUZZLE_SOLVER = "solver"; + public static final String CATEGORY_ADVANCED = "Advanced"; + public static final String CATEGORY_PUZZLE_SOLVER = "Solver"; + public static final String CATEGORY_QOL = "Tooltips"; public static boolean DEBUG = true; @@ -22,6 +23,10 @@ public class Config { public static boolean solver_creeper; public static boolean solver_teleport; + + public static boolean itemtooltip_dungeonstat; + public static boolean itemtooltip_price; + public static void syncConfig(boolean load) { // Gets called from preInit try { // Load config @@ -40,7 +45,8 @@ public class Config { solver_waterpuzzle = configuration.get(Config.CATEGORY_PUZZLE_SOLVER, "water", "true", "Water puzzle solver", Property.Type.BOOLEAN).getBoolean(); solver_box = configuration.get(Config.CATEGORY_PUZZLE_SOLVER, "box", "true", "Box puzzle solver", Property.Type.BOOLEAN).getBoolean(); - + itemtooltip_dungeonstat = configuration.get(Config.CATEGORY_QOL, "dungeonstat", "true", "Show what floor dungeon item was obtained", Property.Type.BOOLEAN).getBoolean(); + itemtooltip_price = configuration.get(Config.CATEGORY_QOL, "price", "true", "Show prices of any item", Property.Type.BOOLEAN).getBoolean(); DEBUG = configuration.get(Config.CATEGORY_ADVANCED, "debug","false", "Enable debug mode", Property.Type.BOOLEAN).getBoolean(); // Comment } catch (Exception e) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java deleted file mode 100755 index 8b7273c5..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java +++ /dev/null @@ -1,234 +0,0 @@ -package kr.syeyoung.dungeonsguide; - -import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; -import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; -import kr.syeyoung.dungeonsguide.roomedit.EditingContext; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit; -import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonValueEdit; -import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEdit; -import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; -import kr.syeyoung.dungeonsguide.utils.MapUtils; -import kr.syeyoung.dungeonsguide.utils.RenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -import java.awt.*; - -public class EventListener { - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent e) { - try { - if (e.phase == TickEvent.Phase.START) { - SkyblockStatus skyblockStatus = (SkyblockStatus) kr.syeyoung.dungeonsguide.e.getDungeonsGuide().getSkyblockStatus(); - { - boolean isOnDungeon = skyblockStatus.isOnDungeon(); - skyblockStatus.updateStatus(); - if (!skyblockStatus.isOnDungeon()) { - skyblockStatus.setContext(null); - MapUtils.clearMap(); - return; - } - if (isOnDungeon) { - skyblockStatus.getContext().tick(); - } - else skyblockStatus.setContext(new DungeonContext(Minecraft.getMinecraft().thePlayer.worldObj)); - } - - if (!skyblockStatus.isOnDungeon()) return; - - if (skyblockStatus.getContext() != null) { - DungeonContext context = skyblockStatus.getContext(); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - if (thePlayer == null) return; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().tick(); - } - } - } - } catch (Throwable e2) {e2.printStackTrace();} - } - - DynamicTexture dynamicTexture = new DynamicTexture(128, 128); - ResourceLocation location = Minecraft.getMinecraft().renderEngine.getDynamicTextureLocation("dungeons/map/", dynamicTexture); - @SubscribeEvent - public void onRender(RenderGameOverlayEvent.Post postRender) { - try { - if (postRender.type != RenderGameOverlayEvent.ElementType.TEXT) return; - SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); - if (!skyblockStatus.isOnDungeon()) return; - if (Config.DEBUG) { - int[] textureData = dynamicTexture.getTextureData(); - MapUtils.getImage().getRGB(0, 0, 128, 128, textureData, 0, 128); - dynamicTexture.updateDynamicTexture(); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - GlStateManager.enableAlpha(); - GuiScreen.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 128, 128, 128, 128); - } - - if (skyblockStatus.getContext() != null) { - DungeonContext context = skyblockStatus.getContext(); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - if (dungeonRoom == null) { - if (Config.DEBUG) - fontRenderer.drawString("Where are you?!", 5, 128, 0xFFFFFF); - } else { - if (Config.DEBUG) { - fontRenderer.drawString("you're in the room... " + dungeonRoom.getColor() + " / " + dungeonRoom.getShape(), 5, 128, 0xFFFFFF); - fontRenderer.drawString("room uuid: " + dungeonRoom.getDungeonRoomInfo().getUuid() + (dungeonRoom.getDungeonRoomInfo().isRegistered() ? "" : " (not registered)"), 5, 138, 0xFFFFFF); - fontRenderer.drawString("room name: " + dungeonRoom.getDungeonRoomInfo().getName(), 5, 148, 0xFFFFFF); - } - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().drawScreen(postRender.partialTicks); - } - } - - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - - @SubscribeEvent - public void onChatReceived(ClientChatReceivedEvent clientChatReceivedEvent) { - try { - if (clientChatReceivedEvent.type == 2) return; - SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); - if (!skyblockStatus.isOnDungeon()) return; - - DungeonContext context = skyblockStatus.getContext(); - - if (skyblockStatus.getContext() != null) { - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - - RoomProcessor roomProcessor = null; - try { - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().chatReceived(clientChatReceivedEvent.message); - roomProcessor = dungeonRoom.getRoomProcessor(); - } - } - } catch (Throwable t) { - t.printStackTrace(); - } - for (RoomProcessor globalRoomProcessor : context.getGlobalRoomProcessors()) { - if (globalRoomProcessor == roomProcessor) continue;; - try { - globalRoomProcessor.chatReceived(clientChatReceivedEvent.message); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - - - @SubscribeEvent - public void onWorldRender(RenderWorldLastEvent renderWorldLastEvent) { - try { - SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); - if (!skyblockStatus.isOnDungeon()) return; - - DungeonContext context = skyblockStatus.getContext(); - if (context == null) return; - if (Config.DEBUG) { - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { - for(DungeonDoor door : dungeonRoom.getDoors()) { - RenderUtils.renderDoor(door, renderWorldLastEvent.partialTicks); - } - } - } - - - if (skyblockStatus.getContext() != null) { - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().drawWorld(renderWorldLastEvent.partialTicks); - } - } - - } - - if (EditingContext.getEditingContext() != null) { - GuiScreen guiScreen = EditingContext.getEditingContext().getCurrent(); - if (guiScreen instanceof GuiDungeonParameterEdit) { - ValueEdit valueEdit = ((GuiDungeonParameterEdit) guiScreen).getValueEdit(); - if (valueEdit != null) { - valueEdit.renderWorld(renderWorldLastEvent.partialTicks); - } - } else if (guiScreen instanceof GuiDungeonValueEdit) { - ValueEdit valueEdit = ((GuiDungeonValueEdit) guiScreen).getValueEdit(); - if (valueEdit != null) { - valueEdit.renderWorld(renderWorldLastEvent.partialTicks); - } - } else if (guiScreen instanceof GuiDungeonAddSet) { - ((GuiDungeonAddSet) guiScreen).onWorldRender(renderWorldLastEvent.partialTicks); - } - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - - @SubscribeEvent - public void onKeyInput(InputEvent.KeyInputEvent keyInputEvent) { - if (Config.DEBUG &&Keybinds.editingSession.isKeyDown() ){ - EditingContext ec = EditingContext.getEditingContext(); - if (ec == null) { - DungeonContext context = e.getDungeonsGuide().getSkyblockStatus().getContext(); - if (context == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Not in dungeons")); - return; - } - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - - if (dungeonRoom == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Can't determine the dungeon room you're in")); - return; - } - - if (EditingContext.getEditingContext() != null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("There is an editing session currently open.")); - return; - } - - EditingContext.createEditingContext(dungeonRoom); - EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); - } else ec.reopen(); - } - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java index 3b951c89..bda98879 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java @@ -71,6 +71,7 @@ public class SkyblockStatus { for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { if (objectiveName.startsWith(skyblock)) { skyblockFound = true; + isOnSkyblock = true; break; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java index 83427c14..05cd57d6 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java @@ -12,7 +12,7 @@ import java.util.UUID; @Getter @Setter public class DungeonRoomInfo implements Serializable { - private static final long serialVersionUID = 42L; + private static final long serialVersionUID = -8291811286448196640L; public DungeonRoomInfo(short shape, byte color) { this.uuid = UUID.randomUUID(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index 80440e36..8cd34154 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -2,14 +2,15 @@ package kr.syeyoung.dungeonsguide; import kr.syeyoung.dungeonsguide.commands.*; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import kr.syeyoung.dungeonsguide.eventlistener.DungeonListener; +import kr.syeyoung.dungeonsguide.eventlistener.ItemGuiListener; +import kr.syeyoung.dungeonsguide.utils.AhUtils; import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.commons.io.IOUtils; @@ -49,11 +50,14 @@ public class e implements c { dungeonsGuide = this; skyblockStatus = new SkyblockStatus(); - MinecraftForge.EVENT_BUS.register(new EventListener()); + MinecraftForge.EVENT_BUS.register(new DungeonListener()); + MinecraftForge.EVENT_BUS.register(new ItemGuiListener()); CommandDungeonsGuide commandDungeonsGuide; ClientCommandHandler.instance.registerCommand(commandDungeonsGuide = new CommandDungeonsGuide()); MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); + AhUtils.registerTimer(); + try { DungeonRoomInfoRegistry.loadAll(configDir); } catch (BadPaddingException e) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java new file mode 100755 index 00000000..118626f5 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java @@ -0,0 +1,238 @@ +package kr.syeyoung.dungeonsguide.eventlistener; + +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.Keybinds; +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.roomedit.EditingContext; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonValueEdit; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEdit; +import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; +import kr.syeyoung.dungeonsguide.utils.MapUtils; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import java.awt.*; + +public class DungeonListener { + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent e) { + try { + if (e.phase == TickEvent.Phase.START) { + SkyblockStatus skyblockStatus = (SkyblockStatus) kr.syeyoung.dungeonsguide.e.getDungeonsGuide().getSkyblockStatus(); + { + boolean isOnDungeon = skyblockStatus.isOnDungeon(); + skyblockStatus.updateStatus(); + if (!skyblockStatus.isOnDungeon()) { + skyblockStatus.setContext(null); + MapUtils.clearMap(); + return; + } + if (isOnDungeon) { + skyblockStatus.getContext().tick(); + } + else skyblockStatus.setContext(new DungeonContext(Minecraft.getMinecraft().thePlayer.worldObj)); + } + + if (!skyblockStatus.isOnDungeon()) return; + + if (skyblockStatus.getContext() != null) { + DungeonContext context = skyblockStatus.getContext(); + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + if (thePlayer == null) return; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().tick(); + } + } + } + } catch (Throwable e2) {e2.printStackTrace();} + } + + DynamicTexture dynamicTexture = new DynamicTexture(128, 128); + ResourceLocation location = Minecraft.getMinecraft().renderEngine.getDynamicTextureLocation("dungeons/map/", dynamicTexture); + @SubscribeEvent + public void onRender(RenderGameOverlayEvent.Post postRender) { + try { + if (postRender.type != RenderGameOverlayEvent.ElementType.TEXT) return; + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnDungeon()) return; + if (Config.DEBUG) { + int[] textureData = dynamicTexture.getTextureData(); + MapUtils.getImage().getRGB(0, 0, 128, 128, textureData, 0, 128); + dynamicTexture.updateDynamicTexture(); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + GlStateManager.enableAlpha(); + GuiScreen.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 128, 128, 128, 128); + } + + if (skyblockStatus.getContext() != null) { + DungeonContext context = skyblockStatus.getContext(); + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + if (dungeonRoom == null) { + if (Config.DEBUG) + fontRenderer.drawString("Where are you?!", 5, 128, 0xFFFFFF); + } else { + if (Config.DEBUG) { + fontRenderer.drawString("you're in the room... " + dungeonRoom.getColor() + " / " + dungeonRoom.getShape(), 5, 128, 0xFFFFFF); + fontRenderer.drawString("room uuid: " + dungeonRoom.getDungeonRoomInfo().getUuid() + (dungeonRoom.getDungeonRoomInfo().isRegistered() ? "" : " (not registered)"), 5, 138, 0xFFFFFF); + fontRenderer.drawString("room name: " + dungeonRoom.getDungeonRoomInfo().getName(), 5, 148, 0xFFFFFF); + } + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().drawScreen(postRender.partialTicks); + } + } + + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + @SubscribeEvent + public void onChatReceived(ClientChatReceivedEvent clientChatReceivedEvent) { + try { + if (clientChatReceivedEvent.type == 2) return; + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnDungeon()) return; + + DungeonContext context = skyblockStatus.getContext(); + + if (skyblockStatus.getContext() != null) { + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + + RoomProcessor roomProcessor = null; + try { + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().chatReceived(clientChatReceivedEvent.message); + roomProcessor = dungeonRoom.getRoomProcessor(); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + for (RoomProcessor globalRoomProcessor : context.getGlobalRoomProcessors()) { + if (globalRoomProcessor == roomProcessor) continue;; + try { + globalRoomProcessor.chatReceived(clientChatReceivedEvent.message); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + + @SubscribeEvent + public void onWorldRender(RenderWorldLastEvent renderWorldLastEvent) { + try { + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnDungeon()) return; + + DungeonContext context = skyblockStatus.getContext(); + if (context == null) return; + if (Config.DEBUG) { + for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for(DungeonDoor door : dungeonRoom.getDoors()) { + RenderUtils.renderDoor(door, renderWorldLastEvent.partialTicks); + } + } + } + + + if (skyblockStatus.getContext() != null) { + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().drawWorld(renderWorldLastEvent.partialTicks); + } + } + + } + + if (EditingContext.getEditingContext() != null) { + GuiScreen guiScreen = EditingContext.getEditingContext().getCurrent(); + if (guiScreen instanceof GuiDungeonParameterEdit) { + ValueEdit valueEdit = ((GuiDungeonParameterEdit) guiScreen).getValueEdit(); + if (valueEdit != null) { + valueEdit.renderWorld(renderWorldLastEvent.partialTicks); + } + } else if (guiScreen instanceof GuiDungeonValueEdit) { + ValueEdit valueEdit = ((GuiDungeonValueEdit) guiScreen).getValueEdit(); + if (valueEdit != null) { + valueEdit.renderWorld(renderWorldLastEvent.partialTicks); + } + } else if (guiScreen instanceof GuiDungeonAddSet) { + ((GuiDungeonAddSet) guiScreen).onWorldRender(renderWorldLastEvent.partialTicks); + } + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + @SubscribeEvent + public void onKeyInput(InputEvent.KeyInputEvent keyInputEvent) { + if (Config.DEBUG && Keybinds.editingSession.isKeyDown() ){ + EditingContext ec = EditingContext.getEditingContext(); + if (ec == null) { + DungeonContext context = e.getDungeonsGuide().getSkyblockStatus().getContext(); + if (context == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Not in dungeons")); + return; + } + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + + if (dungeonRoom == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Can't determine the dungeon room you're in")); + return; + } + + if (EditingContext.getEditingContext() != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("There is an editing session currently open.")); + return; + } + + EditingContext.createEditingContext(dungeonRoom); + EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); + } else ec.reopen(); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java new file mode 100644 index 00000000..829513bf --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java @@ -0,0 +1,106 @@ +package kr.syeyoung.dungeonsguide.eventlistener; + +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.utils.AhUtils; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.*; + +public class ItemGuiListener { + @SubscribeEvent + public void dungeonTooltip(ItemTooltipEvent event) { + if (!e.getDungeonsGuide().getSkyblockStatus().isOnSkyblock()) return; + if (!Config.itemtooltip_dungeonstat) return; + + ItemStack hoveredItem = event.itemStack; + NBTTagCompound compound = hoveredItem.getTagCompound(); + if (compound == null) + return; + if (!compound.hasKey("ExtraAttributes")) + return; + NBTTagCompound nbtTagCompound = compound.getCompoundTag("ExtraAttributes"); + + int floor = nbtTagCompound.getInteger("item_tier"); + int percentage = nbtTagCompound.getInteger("baseStatBoostPercentage"); + + if (nbtTagCompound.hasKey("item_tier")) + event.toolTip.add("§7Obtained in: §c"+(floor == 0 ? "Entrance" : "Floor "+floor)); + if (nbtTagCompound.hasKey("baseStatBoostPercentage")) + event.toolTip.add("§7Stat Percentage: §"+(percentage == 50 ? "6§l":"c")+(percentage * 2)+"%"); + } + @SubscribeEvent + public void priceTooltip(ItemTooltipEvent event) { + if (!e.getDungeonsGuide().getSkyblockStatus().isOnSkyblock()) return; + if (!Config.itemtooltip_price) return; + + ItemStack hoveredItem = event.itemStack; + NBTTagCompound compound = hoveredItem.getTagCompound(); + if (compound == null) + return; + if (!compound.hasKey("ExtraAttributes")) + 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 : ((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; + int totalHighestPrice = 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((Integer) auctionData.prices.first()) + " §7to§e "+ TextUtils.format(auctionData.prices.last())); + totalLowestPrice += auctionData.prices.first(); + totalHighestPrice += auctionData.prices.last(); + } + 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)); + } 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("§fHighest 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.prices.size() != 0) ? ("§e"+ TextUtils.format(auctionData.prices.first().intValue())) : "§cn/a")); + event.toolTip.add("§fHighest ah §7: " + ((auctionData.prices.size() != 0) ? ("§e"+ TextUtils.format((auctionData.prices.last()).intValue())) : "§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)))); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java new file mode 100644 index 00000000..1f7644bc --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java @@ -0,0 +1,131 @@ +package kr.syeyoung.dungeonsguide.utils; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.Timer; +import java.util.TimerTask; +import java.util.TreeSet; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; + +public class AhUtils { + public static volatile Map auctions = new HashMap(); + + private static Map semi_auctions = new HashMap(); + + public static Timer timer = new Timer(); + + public static int totalAuctions = 0; + + public static void registerTimer() { + timer.schedule(new TimerTask() { + public void run() { + AhUtils.loadAuctions(); + } + }, 0L, 1800000L); + } + + public static void loadAuctions() { + try { + int i = 0; + do { + + } while (loadPage(i++)); + loadBazaar(); + auctions = semi_auctions; + semi_auctions = new HashMap(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void loadBazaar() throws IOException { + System.out.println("Fetching bazaar data"); + URL url = new URL("https://api.hypixel.net/skyblock/bazaar"); + InputStreamReader reader = new InputStreamReader(url.openStream()); + JsonObject object = (JsonObject)(new JsonParser()).parse(reader); + boolean success = object.get("success").getAsBoolean(); + if (!success) + return; + JsonObject element = object.getAsJsonObject("products"); + for (Map.Entry product : (Iterable>)element.entrySet()) { + String id = product.getKey(); + AuctionData auctionData = semi_auctions.get(id); + boolean notexisted = (auctionData == null); + if (notexisted) + auctionData = new AuctionData(id); + auctionData.sellPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("sellPrice").getAsInt(); + auctionData.buyPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("buyPrice").getAsInt(); + if (notexisted) + semi_auctions.put(id, auctionData); + } + } + + public static boolean loadPage(int page) throws IOException { + System.out.println("Fetching page " + page + " of auctions"); + URL url = new URL("https://api.hypixel.net/skyblock/auctions?page=" + page); + InputStreamReader reader = new InputStreamReader(url.openStream()); + JsonObject object = (JsonObject)(new JsonParser()).parse(reader); + boolean success = object.get("success").getAsBoolean(); + if (!success) + return false; + int maxPage = object.get("totalPages").getAsInt(); + int totalAuctions = object.get("totalAuctions").getAsInt(); + System.out.println("Fetched page " + page + "/" + maxPage + " of auctions! (" + totalAuctions + " total)"); + JsonArray array = object.get("auctions").getAsJsonArray(); + for (JsonElement element2 : array) { + JsonObject element = element2.getAsJsonObject(); + JsonElement isBin = element.get("bin"); + if (isBin == null || !isBin.getAsBoolean()) + continue; + byte[] itemData = Base64.decode(element.get("item_bytes").getAsString().replace("\\u003d", "=")); + NBTTagCompound nbtTagCompound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(itemData)); + NBTTagCompound acutalItem = (NBTTagCompound)nbtTagCompound.getTagList("i", 10).get(0); + NBTTagCompound attributes = acutalItem.getCompoundTag("tag").getCompoundTag("ExtraAttributes"); + String id = attributes.getString("id"); + if (id.equals("ENCHANTED_BOOK")) { + NBTTagCompound enchants = attributes.getCompoundTag("enchantments"); + Set keys = enchants.getKeySet(); + if (keys.size() != 1) + continue; + String ench = keys.iterator().next(); + int lv = enchants.getInteger(ench); + id = id + "::" + ench + "-" + lv; + } + AuctionData auctionData = semi_auctions.get(id); + boolean notexisted = (auctionData == null); + if (notexisted) + auctionData = new AuctionData(id); + auctionData.prices.add(element.get("starting_bid").getAsInt()); + if (notexisted) + semi_auctions.put(id, auctionData); + } + return (page < maxPage); + } + + public static class AuctionData { + public String id; + + public SortedSet prices; + + public int sellPrice = -1; + + public int buyPrice = -1; + + public AuctionData(String id) { + this.id = id; + this.prices = new TreeSet(); + } + } +} \ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java index d56584c3..300cf6ba 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java @@ -2,6 +2,8 @@ package kr.syeyoung.dungeonsguide.utils; import java.text.DecimalFormat; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.regex.Pattern; public class TextUtils { @@ -33,4 +35,31 @@ public class TextUtils { return stringBuilder.toString(); } + + + private static final TreeMap suffixes = new TreeMap(); + + static { + suffixes.put(1000L, "k"); + suffixes.put(1000000L, "m"); + suffixes.put(1000000000L, "b"); + } + + public static String format(long value) { +// return String.valueOf(value); + + if (value == Long.MIN_VALUE) + return format(-9223372036854775807L); + if (value < 0L) + return "-" + format(-value); + if (value < 1000L) + return Long.toString(value); + Map.Entry e = suffixes.floorEntry(value); + Long divideBy = e.getKey(); + String suffix = e.getValue(); + long truncated = value * 10 / divideBy ; + boolean hasDecimal = (truncated < 100L && (truncated / 10.0D) != (truncated / 10L)); + return hasDecimal ? ((truncated / 10.0D) + suffix) : ((truncated / 10L) + suffix); + } + } \ No newline at end of file -- cgit