diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:15:21 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:17:22 -0400 |
commit | a8e475fa0a7977f64f072548459d592274169d66 (patch) | |
tree | 2f6e3c2fc4aa55c52b848adc493a9ecc842e53f8 /src/main/java/com/thatgravyboat/skyblockhud/tracker | |
parent | bb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (diff) | |
download | SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.gz SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.bz2 SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.zip |
Format v2
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/tracker')
3 files changed, 446 insertions, 420 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java index d82a521..552837b 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java @@ -13,72 +13,74 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class KillTrackerHandler { - public static final Set<UUID> attackedEntities = new HashSet<>(); + public static final Set<UUID> attackedEntities = new HashSet<>(); - @SubscribeEvent - public void onAttack(AttackEntityEvent event) { - if (event.target != null) { - attackedEntities.add(event.target.getUniqueID()); + @SubscribeEvent + public void onAttack(AttackEntityEvent event) { + if (event.target != null) { + attackedEntities.add(event.target.getUniqueID()); + } } - } - @SubscribeEvent - public void onDeath(LivingDeathEvent event) { - if (false) { - //Used for testing - System.out.println( - "----------------------------------------------------------------------------------------------------------------" - ); - System.out.println("Name : " + event.entity.getName()); - System.out.println("UUID : " + event.entity.getUniqueID()); - NBTTagCompound tag = new NBTTagCompound(); - event.entity.writeToNBT(tag); - System.out.println("Tag : " + tag); - System.out.println("Damage : " + getDamageSourceString(event.source)); - System.out.println( - "----------------------------------------------------------------------------------------------------------------" - ); - } + @SubscribeEvent + public void onDeath(LivingDeathEvent event) { + if (false) { + //Used for testing + System.out.println( + "----------------------------------------------------------------------------------------------------------------" + ); + System.out.println("Name : " + event.entity.getName()); + System.out.println("UUID : " + event.entity.getUniqueID()); + NBTTagCompound tag = new NBTTagCompound(); + event.entity.writeToNBT(tag); + System.out.println("Tag : " + tag); + System.out.println( + "Damage : " + getDamageSourceString(event.source) + ); + System.out.println( + "----------------------------------------------------------------------------------------------------------------" + ); + } - attackedEntities.remove(event.entity.getUniqueID()); - } + attackedEntities.remove(event.entity.getUniqueID()); + } - public static String getDamageSourceString(DamageSource source) { - return ( - "{ " + - source.getDamageType() + - ", " + - source.isDamageAbsolute() + - ", " + - source.isDifficultyScaled() + - ", " + - source.isFireDamage() + - ", " + - source.isProjectile() + - ", " + - source.isUnblockable() + - ", " + - source.isExplosion() + - ", " + - source.isMagicDamage() + - ", " + - source.isCreativePlayer() + - ", " + - source.getSourceOfDamage() + - " }" - ); - } + public static String getDamageSourceString(DamageSource source) { + return ( + "{ " + + source.getDamageType() + + ", " + + source.isDamageAbsolute() + + ", " + + source.isDifficultyScaled() + + ", " + + source.isFireDamage() + + ", " + + source.isProjectile() + + ", " + + source.isUnblockable() + + ", " + + source.isExplosion() + + ", " + + source.isMagicDamage() + + ", " + + source.isCreativePlayer() + + ", " + + source.getSourceOfDamage() + + " }" + ); + } - @SubscribeEvent - public void onWorldChange(EntityJoinWorldEvent event) { - if (event.entity != null) { - if ( - event.entity - .getUniqueID() - .equals(Minecraft.getMinecraft().thePlayer.getUniqueID()) - ) { - attackedEntities.clear(); - } + @SubscribeEvent + public void onWorldChange(EntityJoinWorldEvent event) { + if (event.entity != null) { + if ( + event.entity + .getUniqueID() + .equals(Minecraft.getMinecraft().thePlayer.getUniqueID()) + ) { + attackedEntities.clear(); + } + } } - } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java index 4accb25..7035fee 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java @@ -18,224 +18,237 @@ import net.minecraft.util.ResourceLocation; public class TrackerFileLoader { - private static final Gson gson = new GsonBuilder().create(); - - public static ItemStack getDisplayItem(JsonObject jsonObject) { - int meta = jsonObject.get("meta").getAsInt(); - String displayItemId = jsonObject.get("item").getAsString(); - Item item = Item.itemRegistry.getObject( - new ResourceLocation(displayItemId) - ); - ItemStack stack = new ItemStack(item, 0, meta); - if ( - jsonObject.has("skullData") && - displayItemId.equals("minecraft:skull") && - meta == 3 - ) { - stack.setTagInfo( - "SkullOwner", - getSkullTag(jsonObject.getAsJsonObject("skullData")) - ); - } - if ( - jsonObject.has("enchanted") && jsonObject.get("enchanted").getAsBoolean() - ) stack.setTagInfo("ench", new NBTTagList()); - return stack; - } - - public static NBTBase getSkullTag(JsonObject skullObject) { - NBTTagCompound skullOwner = new NBTTagCompound(); - NBTTagCompound properties = new NBTTagCompound(); - NBTTagList textures = new NBTTagList(); - NBTTagCompound value = new NBTTagCompound(); - - skullOwner.setString("Id", skullObject.get("id").getAsString()); - - value.setString("Value", skullObject.get("texture").getAsString()); - textures.appendTag(value); - - properties.setTag("textures", textures); - - skullOwner.setTag("Properties", properties); - return skullOwner; - } - - private static void loadTrackers(JsonObject object) { - for (JsonElement element : object.get("trackers").getAsJsonArray()) { - JsonObject tracker = element.getAsJsonObject(); - StringBuilder builder = new StringBuilder(); - tracker - .get("location") - .getAsJsonArray() - .forEach(loc -> builder.append(loc.getAsString())); - String location = builder.toString(); - - Map<String, ItemStack> stacks = new HashMap<>(); - for (JsonElement drop : tracker.get("drops").getAsJsonArray()) { - JsonObject dropObject = drop.getAsJsonObject(); - - //Display Item Creation - ItemStack stack = getDisplayItem( - dropObject.getAsJsonObject("displayItem") + private static final Gson gson = new GsonBuilder().create(); + + public static ItemStack getDisplayItem(JsonObject jsonObject) { + int meta = jsonObject.get("meta").getAsInt(); + String displayItemId = jsonObject.get("item").getAsString(); + Item item = Item.itemRegistry.getObject( + new ResourceLocation(displayItemId) ); - String itemId = dropObject.get("id").getAsString(); + ItemStack stack = new ItemStack(item, 0, meta); + if ( + jsonObject.has("skullData") && + displayItemId.equals("minecraft:skull") && + meta == 3 + ) { + stack.setTagInfo( + "SkullOwner", + getSkullTag(jsonObject.getAsJsonObject("skullData")) + ); + } + if ( + jsonObject.has("enchanted") && + jsonObject.get("enchanted").getAsBoolean() + ) stack.setTagInfo("ench", new NBTTagList()); + return stack; + } - stacks.put(itemId, stack); - } + public static NBTBase getSkullTag(JsonObject skullObject) { + NBTTagCompound skullOwner = new NBTTagCompound(); + NBTTagCompound properties = new NBTTagCompound(); + NBTTagList textures = new NBTTagList(); + NBTTagCompound value = new NBTTagCompound(); - String event = tracker.has("event") - ? tracker.get("event").getAsString() - : null; + skullOwner.setString("Id", skullObject.get("id").getAsString()); - Map<String, Map<String, ItemStack>> events = new HashMap<>(); - events.put(event, stacks); + value.setString("Value", skullObject.get("texture").getAsString()); + textures.appendTag(value); - if (TrackerHandler.trackers.containsKey(location)) { - TrackerHandler.trackers.get(location).dropTrackers.put(event, stacks); - } else { - TrackerHandler.trackers.putIfAbsent( - location, - new TrackerHandler.TrackerData(events) - ); - } - - tracker - .get("location") - .getAsJsonArray() - .forEach( - loc -> - TrackerHandler.trackerIds.put( - Locations.get(loc.getAsString()), - location - ) + properties.setTag("textures", textures); + + skullOwner.setTag("Properties", properties); + return skullOwner; + } + + private static void loadTrackers(JsonObject object) { + for (JsonElement element : object.get("trackers").getAsJsonArray()) { + JsonObject tracker = element.getAsJsonObject(); + StringBuilder builder = new StringBuilder(); + tracker + .get("location") + .getAsJsonArray() + .forEach(loc -> builder.append(loc.getAsString())); + String location = builder.toString(); + + Map<String, ItemStack> stacks = new HashMap<>(); + for (JsonElement drop : tracker.get("drops").getAsJsonArray()) { + JsonObject dropObject = drop.getAsJsonObject(); + + //Display Item Creation + ItemStack stack = getDisplayItem( + dropObject.getAsJsonObject("displayItem") + ); + String itemId = dropObject.get("id").getAsString(); + + stacks.put(itemId, stack); + } + + String event = tracker.has("event") + ? tracker.get("event").getAsString() + : null; + + Map<String, Map<String, ItemStack>> events = new HashMap<>(); + events.put(event, stacks); + + if (TrackerHandler.trackers.containsKey(location)) { + TrackerHandler.trackers + .get(location) + .dropTrackers.put(event, stacks); + } else { + TrackerHandler.trackers.putIfAbsent( + location, + new TrackerHandler.TrackerData(events) + ); + } + + tracker + .get("location") + .getAsJsonArray() + .forEach( + loc -> + TrackerHandler.trackerIds.put( + Locations.get(loc.getAsString()), + location + ) + ); + } + } + + private static JsonElement getTrackerFile() { + List<JsonObject> trackerStats = new ArrayList<>(); + TrackerHandler.trackers.forEach( + (locations, trackerData) -> + trackerData.dropTrackers.forEach( + (event, drops) -> { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("location", locations); + + if (event == null) jsonObject.add( + "event", + new JsonNull() + ); else jsonObject.addProperty("event", event); + + JsonObject dropsData = new JsonObject(); + drops.forEach( + (s, stack) -> + dropsData.addProperty(s, stack.stackSize) + ); + jsonObject.add("drops", dropsData); + trackerStats.add(jsonObject); + } + ) ); + JsonArray stats = new JsonArray(); + trackerStats.forEach(stats::add); + return stats; } - } - - private static JsonElement getTrackerFile() { - List<JsonObject> trackerStats = new ArrayList<>(); - TrackerHandler.trackers.forEach( - (locations, trackerData) -> - trackerData.dropTrackers.forEach( - (event, drops) -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("location", locations); - - if (event == null) jsonObject.add( - "event", - new JsonNull() - ); else jsonObject.addProperty("event", event); - - JsonObject dropsData = new JsonObject(); - drops.forEach( - (s, stack) -> dropsData.addProperty(s, stack.stackSize) + + public static void loadTrackersFile() { + try { + ResourceLocation trackers = new ResourceLocation( + "skyblockhud:data/trackers.json" ); - jsonObject.add("drops", dropsData); - trackerStats.add(jsonObject); - } - ) - ); - JsonArray stats = new JsonArray(); - trackerStats.forEach(stats::add); - return stats; - } - - public static void loadTrackersFile() { - try { - ResourceLocation trackers = new ResourceLocation( - "skyblockhud:data/trackers.json" - ); - InputStream is = Minecraft - .getMinecraft() - .getResourceManager() - .getResource(trackers) - .getInputStream(); - - try ( - BufferedReader reader = new BufferedReader( - new InputStreamReader(is, StandardCharsets.UTF_8) - ) - ) { - loadTrackers(gson.fromJson(reader, JsonObject.class)); - } - } catch (Exception ignored) {} - } - - public static boolean loadTrackerStatsFile(File configDirectory) { - File configFile = new File(configDirectory, "sbh-trackers-stats.json"); - - try { - if (configFile.createNewFile()) { - return true; - } - - try ( - BufferedReader reader = new BufferedReader( - new InputStreamReader( - new FileInputStream(configFile), - StandardCharsets.UTF_8 - ) - ) - ) { - JsonObject json = gson.fromJson(reader, JsonObject.class); - if (json.has("trackerStats")) { - json - .getAsJsonArray("trackerStats") - .forEach( - element -> { - if (element.isJsonObject()) { - JsonObject object = element.getAsJsonObject(); - String location = object.get("location").getAsString(); - Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get( - location - ) - .dropTrackers; - - JsonElement event = object.get("event"); - String eventString = event == null || event.isJsonNull() - ? null - : event.getAsString(); - Map<String, ItemStack> drops = trackers.get(eventString); - - if (drops != null) { - for (Map.Entry<String, JsonElement> drop : object - .getAsJsonObject("drops") - .entrySet()) { - if (drops.containsKey(drop.getKey())) { - drops.get(drop.getKey()).stackSize = - drop.getValue().getAsInt(); - } - } - drops = TrackerHandler.sortTrackers(drops); - trackers.put(eventString, drops); - } + InputStream is = Minecraft + .getMinecraft() + .getResourceManager() + .getResource(trackers) + .getInputStream(); + + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader(is, StandardCharsets.UTF_8) + ) + ) { + loadTrackers(gson.fromJson(reader, JsonObject.class)); + } + } catch (Exception ignored) {} + } + + public static boolean loadTrackerStatsFile(File configDirectory) { + File configFile = new File(configDirectory, "sbh-trackers-stats.json"); + + try { + if (configFile.createNewFile()) { + return true; + } + + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader( + new FileInputStream(configFile), + StandardCharsets.UTF_8 + ) + ) + ) { + JsonObject json = gson.fromJson(reader, JsonObject.class); + if (json.has("trackerStats")) { + json + .getAsJsonArray("trackerStats") + .forEach( + element -> { + if (element.isJsonObject()) { + JsonObject object = element.getAsJsonObject(); + String location = object + .get("location") + .getAsString(); + Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get( + location + ) + .dropTrackers; + + JsonElement event = object.get("event"); + String eventString = event == null || + event.isJsonNull() + ? null + : event.getAsString(); + Map<String, ItemStack> drops = trackers.get( + eventString + ); + + if (drops != null) { + for (Map.Entry<String, JsonElement> drop : object + .getAsJsonObject("drops") + .entrySet()) { + if ( + drops.containsKey(drop.getKey()) + ) { + drops.get(drop.getKey()) + .stackSize = + drop.getValue().getAsInt(); + } + } + drops = + TrackerHandler.sortTrackers(drops); + trackers.put(eventString, drops); + } + } + } + ); } - } - ); - } - } - } catch (Exception ignored) {} - return false; - } - - public static void saveTrackerStatsFile(File configDirectory) { - File configFile = new File(configDirectory, "sbh-trackers-stats.json"); - - try { - configFile.createNewFile(); - - try ( - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter( - new FileOutputStream(configFile), - StandardCharsets.UTF_8 - ) - ) - ) { - JsonObject json = new JsonObject(); - json.add("trackerStats", getTrackerFile()); - writer.write(gson.toJson(json)); - } - } catch (IOException ignored) {} - } + } + } catch (Exception ignored) {} + return false; + } + + public static void saveTrackerStatsFile(File configDirectory) { + File configFile = new File(configDirectory, "sbh-trackers-stats.json"); + + try { + configFile.createNewFile(); + + try ( + BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(configFile), + StandardCharsets.UTF_8 + ) + ) + ) { + JsonObject json = new JsonObject(); + json.add("trackerStats", getTrackerFile()); + writer.write(gson.toJson(json)); + } + } catch (IOException ignored) {} + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java index 1d1e33c..8c8a521 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java @@ -18,164 +18,175 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class TrackerHandler { - public static class TrackerData { + public static class TrackerData { - public Map<String, Map<String, ItemStack>> dropTrackers; + public Map<String, Map<String, ItemStack>> dropTrackers; - public TrackerData(Map<String, Map<String, ItemStack>> trackers) { - this.dropTrackers = trackers; - } + public TrackerData(Map<String, Map<String, ItemStack>> trackers) { + this.dropTrackers = trackers; + } - public String getDropId(String event) { - if ( - event == null || - event.isEmpty() || - !eventGoing() || - !dropTrackers.containsKey(event.toLowerCase().trim()) - ) return null; - return event.toLowerCase().trim(); - } + public String getDropId(String event) { + if ( + event == null || + event.isEmpty() || + !eventGoing() || + !dropTrackers.containsKey(event.toLowerCase().trim()) + ) return null; + return event.toLowerCase().trim(); + } - private boolean eventGoing() { - return SeasonDateHandler - .getCurrentEventTime() - .trim() - .toLowerCase() - .contains("ends in"); - } - } - - public static Map<String, TrackerData> trackers = new HashMap<>(); - public static Map<Locations, String> trackerIds = new HashMap<>(); - - public static Map<String, ItemStack> sortTrackers( - Map<String, ItemStack> map - ) { - List<Map.Entry<String, ItemStack>> list = new ArrayList<>(map.entrySet()); - list.sort( - (entry1, entry2) -> - Integer.compare( - entry2.getValue().stackSize, - entry1.getValue().stackSize - ) - ); - - Map<String, ItemStack> result = new LinkedHashMap<>(); - for (Map.Entry<String, ItemStack> entry : list) { - result.put(entry.getKey(), entry.getValue()); + private boolean eventGoing() { + return SeasonDateHandler + .getCurrentEventTime() + .trim() + .toLowerCase() + .contains("ends in"); + } } - return result; - } - - public static void onItemAdded( - String id, - int amount, - String enchant, - int level - ) { - if ( - SkyblockHud.hasSkyblockScoreboard() && - trackerIds.containsKey(LocationHandler.getCurrentLocation()) - ) { - String trackerId = trackerIds.get(LocationHandler.getCurrentLocation()); - TrackerData tracked = trackers.get(trackerId); - String dropTrackerId = tracked.getDropId( - SeasonDateHandler.getCurrentEvent() - ); - Map<String, ItemStack> tracker = tracked.dropTrackers.get(dropTrackerId); - String dropId = id; - if (enchant != null) { - dropId = enchant.toUpperCase() + ";" + level; - } - - if (tracker != null && tracker.containsKey(dropId)) { - ItemStack stack = tracker.get(dropId); - stack.stackSize += amount; - tracked.dropTrackers.put(dropTrackerId, sortTrackers(tracker)); - } - } - } - - public static void drawItemStack(ItemStack stack, int x, int y) { - if (stack == null) return; - RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); - RenderHelper.enableGUIStandardItemLighting(); - itemRender.zLevel = -145; - itemRender.renderItemAndEffectIntoGUI(stack, x, y); - itemRender.zLevel = 0; - RenderHelper.disableStandardItemLighting(); - } - - @SubscribeEvent - public void renderOverlay(RenderGameOverlayEvent.Post event) { - if ( - Utils.overlayShouldRender( - event.type, - SkyblockHud.hasSkyblockScoreboard(), - trackerIds.containsKey(LocationHandler.getCurrentLocation()), - !SkyblockHud.config.trackers.hideTracker - ) + public static Map<String, TrackerData> trackers = new HashMap<>(); + public static Map<Locations, String> trackerIds = new HashMap<>(); + + public static Map<String, ItemStack> sortTrackers( + Map<String, ItemStack> map ) { - String trackerId = trackerIds.get(LocationHandler.getCurrentLocation()); - Minecraft mc = Minecraft.getMinecraft(); - TrackerData tracked = trackers.get(trackerId); - - Map<String, ItemStack> tracker = tracked.dropTrackers.get( - tracked.getDropId(SeasonDateHandler.getCurrentEvent()) - ); - if (tracker != null) { - Position pos = SkyblockHud.config.trackers.trackerPosition; - int startPos = pos.getAbsX( - event.resolution, - (tracker.size() >= 6 ? 120 : tracker.size() * 20) + List<Map.Entry<String, ItemStack>> list = new ArrayList<>( + map.entrySet() ); - int y = pos.getAbsY( - event.resolution, - (int) (10 + Math.ceil(tracker.size() / 5d) * 20) + list.sort( + (entry1, entry2) -> + Integer.compare( + entry2.getValue().stackSize, + entry1.getValue().stackSize + ) ); - Gui.drawRect(startPos, y, startPos + 120, y + 10, -1072689136); - mc.fontRendererObj.drawString( - "Tracker", - startPos + 4, - y + 1, - 0xffffff, - false - ); - y += 10; - Gui.drawRect( - startPos, - y, - startPos + (tracker.size() >= 6 ? 120 : tracker.size() * 20), - (int) (y + (Math.ceil(tracker.size() / 5d) * 20)), - 1610612736 - ); - int x = startPos; - for (ItemStack stack : tracker.values()) { - String s = String.valueOf(stack.stackSize); - GlStateManager.disableLighting(); - GlStateManager.enableDepth(); - drawItemStack(stack, x, y); - GlStateManager.disableDepth(); - GlStateManager.disableBlend(); - mc.fontRendererObj.drawStringWithShadow( - s, - (float) (x + 19 - 2 - mc.fontRendererObj.getStringWidth(s)), - (float) (y + 9), - stack.stackSize < 1 ? 16733525 : 16777215 - ); - GlStateManager.enableBlend(); - GlStateManager.enableDepth(); - - if ((x - startPos) / 20 == 5) { - x = startPos; - y += 20; - } else { - x += 20; - } + Map<String, ItemStack> result = new LinkedHashMap<>(); + for (Map.Entry<String, ItemStack> entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + + public static void onItemAdded( + String id, + int amount, + String enchant, + int level + ) { + if ( + SkyblockHud.hasSkyblockScoreboard() && + trackerIds.containsKey(LocationHandler.getCurrentLocation()) + ) { + String trackerId = trackerIds.get( + LocationHandler.getCurrentLocation() + ); + TrackerData tracked = trackers.get(trackerId); + String dropTrackerId = tracked.getDropId( + SeasonDateHandler.getCurrentEvent() + ); + Map<String, ItemStack> tracker = tracked.dropTrackers.get( + dropTrackerId + ); + String dropId = id; + if (enchant != null) { + dropId = enchant.toUpperCase() + ";" + level; + } + + if (tracker != null && tracker.containsKey(dropId)) { + ItemStack stack = tracker.get(dropId); + stack.stackSize += amount; + tracked.dropTrackers.put(dropTrackerId, sortTrackers(tracker)); + } + } + } + + public static void drawItemStack(ItemStack stack, int x, int y) { + if (stack == null) return; + RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); + RenderHelper.enableGUIStandardItemLighting(); + itemRender.zLevel = -145; + itemRender.renderItemAndEffectIntoGUI(stack, x, y); + itemRender.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + } + + @SubscribeEvent + public void renderOverlay(RenderGameOverlayEvent.Post event) { + if ( + Utils.overlayShouldRender( + event.type, + SkyblockHud.hasSkyblockScoreboard(), + trackerIds.containsKey(LocationHandler.getCurrentLocation()), + !SkyblockHud.config.trackers.hideTracker + ) + ) { + String trackerId = trackerIds.get( + LocationHandler.getCurrentLocation() + ); + Minecraft mc = Minecraft.getMinecraft(); + TrackerData tracked = trackers.get(trackerId); + + Map<String, ItemStack> tracker = tracked.dropTrackers.get( + tracked.getDropId(SeasonDateHandler.getCurrentEvent()) + ); + if (tracker != null) { + Position pos = SkyblockHud.config.trackers.trackerPosition; + int startPos = pos.getAbsX( + event.resolution, + (tracker.size() >= 6 ? 120 : tracker.size() * 20) + ); + int y = pos.getAbsY( + event.resolution, + (int) (10 + Math.ceil(tracker.size() / 5d) * 20) + ); + + Gui.drawRect(startPos, y, startPos + 120, y + 10, -1072689136); + mc.fontRendererObj.drawString( + "Tracker", + startPos + 4, + y + 1, + 0xffffff, + false + ); + y += 10; + Gui.drawRect( + startPos, + y, + startPos + + (tracker.size() >= 6 ? 120 : tracker.size() * 20), + (int) (y + (Math.ceil(tracker.size() / 5d) * 20)), + 1610612736 + ); + int x = startPos; + for (ItemStack stack : tracker.values()) { + String s = String.valueOf(stack.stackSize); + GlStateManager.disableLighting(); + GlStateManager.enableDepth(); + drawItemStack(stack, x, y); + GlStateManager.disableDepth(); + GlStateManager.disableBlend(); + mc.fontRendererObj.drawStringWithShadow( + s, + (float) ( + x + 19 - 2 - mc.fontRendererObj.getStringWidth(s) + ), + (float) (y + 9), + stack.stackSize < 1 ? 16733525 : 16777215 + ); + GlStateManager.enableBlend(); + GlStateManager.enableDepth(); + + if ((x - startPos) / 20 == 5) { + x = startPos; + y += 20; + } else { + x += 20; + } + } + } } - } } - } } |