From a40f87f555e01b09e99ab61e83caf8939ad1a8fd Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Mon, 16 May 2022 22:17:17 -0400 Subject: Add minion last collected display --- README.md | 1 + src/main/java/me/Danker/DankersSkyblockMod.java | 2 + .../java/me/Danker/commands/ToggleCommand.java | 1 + .../me/Danker/features/MinionLastCollected.java | 128 +++++++++++++++++++++ src/main/java/me/Danker/gui/DankerGui.java | 7 ++ .../java/me/Danker/handlers/ConfigHandler.java | 11 ++ src/main/java/me/Danker/utils/RenderUtils.java | 24 ++++ 7 files changed, 174 insertions(+) create mode 100644 src/main/java/me/Danker/features/MinionLastCollected.java diff --git a/README.md b/README.md index d22f75e..98bf434 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Discord Server: https://discord.gg/QsEkNQS - Fire pillar display - Chat aliases - Thunder/Lord Jawbus spawn alerts +- Show when minion was last collected
diff --git a/src/main/java/me/Danker/DankersSkyblockMod.java b/src/main/java/me/Danker/DankersSkyblockMod.java index 6e82137..a63552c 100644 --- a/src/main/java/me/Danker/DankersSkyblockMod.java +++ b/src/main/java/me/Danker/DankersSkyblockMod.java @@ -141,6 +141,7 @@ public class DankersSkyblockMod { MinecraftForge.EVENT_BUS.register(new IceWalkSolver()); MinecraftForge.EVENT_BUS.register(new LividSolver()); MinecraftForge.EVENT_BUS.register(new LowHealthNotifications()); + MinecraftForge.EVENT_BUS.register(new MinionLastCollected()); MinecraftForge.EVENT_BUS.register(new NecronNotifications()); MinecraftForge.EVENT_BUS.register(new NoF3Coords()); MinecraftForge.EVENT_BUS.register(new NotifySlayerSlain()); @@ -181,6 +182,7 @@ public class DankersSkyblockMod { Alerts.configFile = configDirectory + "/dsmalerts.json"; ChatAliases.configFile = configDirectory + "/dsmaliases.json"; + MinionLastCollected.configFile = configDirectory + "/dsmminions.json"; ConfigHandler.reloadConfig(); GoldenEnchants.init(); diff --git a/src/main/java/me/Danker/commands/ToggleCommand.java b/src/main/java/me/Danker/commands/ToggleCommand.java index 91584f8..c08d50a 100644 --- a/src/main/java/me/Danker/commands/ToggleCommand.java +++ b/src/main/java/me/Danker/commands/ToggleCommand.java @@ -64,6 +64,7 @@ public class ToggleCommand extends CommandBase implements ICommand { public static boolean firePillar; public static boolean aliases; public static boolean fishingAlert; + public static boolean minionLastCollected; // Chat Messages public static boolean sceptreMessages; public static boolean midasStaffMessages; diff --git a/src/main/java/me/Danker/features/MinionLastCollected.java b/src/main/java/me/Danker/features/MinionLastCollected.java new file mode 100644 index 0000000..884dccf --- /dev/null +++ b/src/main/java/me/Danker/features/MinionLastCollected.java @@ -0,0 +1,128 @@ +package me.Danker.features; + +import com.google.gson.GsonBuilder; +import me.Danker.commands.ToggleCommand; +import me.Danker.events.ChestSlotClickedEvent; +import me.Danker.events.PacketWriteEvent; +import me.Danker.utils.RenderUtils; +import me.Danker.utils.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.util.BlockPos; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class MinionLastCollected { + + public static List minions = new ArrayList<>(); + public static String configFile; + static BlockPos lastMinion = null; + public static int LAST_COLLECTED_COLOUR; + + @SubscribeEvent + public void onPacketWrite(PacketWriteEvent event) { + if (ToggleCommand.minionLastCollected && Utils.inSkyblock && Utils.isInScoreboard("Your Island")) { + if (event.packet instanceof C02PacketUseEntity) { + C02PacketUseEntity packet = (C02PacketUseEntity) event.packet; + Entity entity = packet.getEntityFromWorld(Minecraft.getMinecraft().theWorld); + if (isAMinion(entity)) { + lastMinion = entity.getPosition(); + if (getMinionFromPos(lastMinion) == null) { + minions.add(new Minion(lastMinion)); + save(); + } + } + } + } + } + + @SubscribeEvent + public void onSlotClick(ChestSlotClickedEvent event) { + if (ToggleCommand.minionLastCollected && Utils.tabLocation.equals("Private Island")) { + String inventoryName = event.inventoryName; + ItemStack item = event.item; + if (inventoryName.contains(" Minion ") && item != null && lastMinion != null) { + if (item.getDisplayName().contains("Collect All")) { + getMinionFromPos(lastMinion).collectNow(); + save(); + } else if (item.getDisplayName().contains("Pickup Minion")) { + minions.remove(getMinionFromPos(lastMinion)); + save(); + } + } + } + } + + @SubscribeEvent + public void onWorldRender(RenderWorldLastEvent event) { + if (ToggleCommand.minionLastCollected && Utils.inSkyblock && Utils.tabLocation.equals("Private Island")) { + for (Minion minion : minions) { + RenderUtils.draw3DString(minion.pos.getX() + 0.5, minion.pos.getY() + 2.2, minion.pos.getZ() + 0.5, minion.getTimeCollected(), LAST_COLLECTED_COLOUR, event.partialTicks); + } + } + } + + public boolean isAMinion(Entity entity) { + if (!(entity instanceof EntityArmorStand)) return false; + EntityArmorStand armourStand = (EntityArmorStand) entity; + + for (int i = 0; i <= 3; i++) { + if (armourStand.getCurrentArmor(i) == null) return false; + } + + return (Item.getIdFromItem(armourStand.getCurrentArmor(0).getItem()) == 301 && + Item.getIdFromItem(armourStand.getCurrentArmor(1).getItem()) == 300 && + Item.getIdFromItem(armourStand.getCurrentArmor(2).getItem()) == 299 && + Item.getIdFromItem(armourStand.getCurrentArmor(3).getItem()) == 397); + } + + public Minion getMinionFromPos(BlockPos pos) { + for (Minion minion : minions) { + if (minion.pos.equals(pos)) return minion; + } + return null; + } + + public static void save() { + try (FileWriter writer = new FileWriter(configFile)) { + new GsonBuilder().create().toJson(minions, writer); + writer.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public static class Minion { + + public BlockPos pos; + public double lastCollect; + + public Minion(BlockPos pos) { + this.pos = pos; + this.lastCollect = -1; + } + + public String getTimeCollected() { + String lastCollected = "Last Collected: "; + if (lastCollect == -1) { + return lastCollected + "Never"; + } + return lastCollected + Utils.getTimeBetween(lastCollect, System.currentTimeMillis() / 1000) + " ago"; + } + + public void collectNow() { + lastCollect = System.currentTimeMillis() / 1000; + } + + } + +} diff --git a/src/main/java/me/Danker/gui/DankerGui.java b/src/main/java/me/Danker/gui/DankerGui.java index 663adf5..c247eab 100644 --- a/src/main/java/me/Danker/gui/DankerGui.java +++ b/src/main/java/me/Danker/gui/DankerGui.java @@ -92,6 +92,7 @@ public class DankerGui extends GuiScreen { private GuiButton autoJoinSkyblock; private GuiButton firePillar; private GuiButton fishingAlert; + private GuiButton minionLastCollected; // Chat Messages private GuiButton sceptreMessages; private GuiButton midasStaffMessages; @@ -188,6 +189,7 @@ public class DankerGui extends GuiScreen { autoJoinSkyblock = new FeatureButton("Automatically Join Skyblock: " + Utils.getColouredBoolean(ToggleCommand.autoJoinSkyblock), "Automatically join Skyblock when you join Hypixel.\nYou have an addiction."); firePillar = new FeatureButton("Fire Pillar Display: " + Utils.getColouredBoolean(ToggleCommand.firePillar), "Displays blaze fire pillar text on screen"); fishingAlert = new FeatureButton("Fishing Spawn Alerts: " + Utils.getColouredBoolean(ToggleCommand.fishingAlert), "Alerts when a Thunder or Lord Jawbus spawns nearby"); + minionLastCollected = new FeatureButton("Show When Minion Last Collected: " + Utils.getColouredBoolean(ToggleCommand.minionLastCollected), "Displays when a minion was last collected over the minion."); allButtons.clear(); allButtons.add(changeDisplay); @@ -250,6 +252,7 @@ public class DankerGui extends GuiScreen { allButtons.add(autoJoinSkyblock); allButtons.add(firePillar); allButtons.add(fishingAlert); + allButtons.add(minionLastCollected); search.setText(initSearchText); search.setVisible(true); @@ -551,6 +554,10 @@ public class DankerGui extends GuiScreen { ToggleCommand.customNametags = !ToggleCommand.customNametags; ConfigHandler.writeBooleanConfig("toggles", "CustomNametags", ToggleCommand.customNametags); customNametags.displayString = "Custom Color on Nametags: " + Utils.getColouredBoolean(ToggleCommand.customNametags); + } else if (button == minionLastCollected) { + ToggleCommand.minionLastCollected = !ToggleCommand.minionLastCollected; + ConfigHandler.writeBooleanConfig("toggles", "MinionLastCollected", ToggleCommand.minionLastCollected); + minionLastCollected.displayString = "Show When Minion Last Collected: " + Utils.getColouredBoolean(ToggleCommand.minionLastCollected); } } diff --git a/src/main/java/me/Danker/handlers/ConfigHandler.java b/src/main/java/me/Danker/handlers/ConfigHandler.java index 1f00c9f..bd60639 100644 --- a/src/main/java/me/Danker/handlers/ConfigHandler.java +++ b/src/main/java/me/Danker/handlers/ConfigHandler.java @@ -249,6 +249,7 @@ public class ConfigHandler { ToggleCommand.firePillar = initBoolean("toggles", "FirePillar", false); ToggleCommand.aliases = initBoolean("toggles", "Aliases", false); ToggleCommand.fishingAlert = initBoolean("toggles", "FishingAlert", false); + ToggleCommand.minionLastCollected = initBoolean("toggles", "MinionLastCollected", false); // Chat Messages ToggleCommand.sceptreMessages = initBoolean("toggles", "SceptreMessages", true); ToggleCommand.midasStaffMessages = initBoolean("toggles", "MidasStaffMessages", true); @@ -714,6 +715,7 @@ public class ConfigHandler { BoulderSolver.BOULDER_ARROW_COLOUR = initInt("colors", "boulderArrow", 0x006000); SilverfishSolver.SILVERFISH_LINE_COLOUR = initInt("colors", "silverfishLine", 0x40FF40); IceWalkSolver.ICE_WALK_LINE_COLOUR = initInt("colors", "iceWalkLine", 0x40FF40); + MinionLastCollected.LAST_COLLECTED_COLOUR = initInt("colors", "lastCollected", 0x55FFFF); // Commands if (!hasKey("commands", "reparty")) writeBooleanConfig("commands", "reparty", false); @@ -739,6 +741,15 @@ public class ConfigHandler { } ChatAliases.Alias[] aliases = gson.fromJson(new FileReader(ChatAliases.configFile), ChatAliases.Alias[].class); if (aliases != null) ChatAliases.aliases = new ArrayList<>(Arrays.asList(aliases)); + + // Minions + if (!(new File(MinionLastCollected.configFile).exists())) { + FileWriter file = new FileWriter(MinionLastCollected.configFile); + file.write(new JsonArray().toString()); + file.close(); + } + MinionLastCollected.Minion[] minions = gson.fromJson(new FileReader(MinionLastCollected.configFile), MinionLastCollected.Minion[].class); + if (minions != null) MinionLastCollected.minions = new ArrayList<>(Arrays.asList(minions)); } catch (IOException ex) { ex.printStackTrace(); } diff --git a/src/main/java/me/Danker/utils/RenderUtils.java b/src/main/java/me/Danker/utils/RenderUtils.java index b5ede19..c3efc90 100644 --- a/src/main/java/me/Danker/utils/RenderUtils.java +++ b/src/main/java/me/Danker/utils/RenderUtils.java @@ -138,6 +138,30 @@ public class RenderUtils { GlStateManager.popMatrix(); } + public static void draw3DString(double x, double y, double z, String text, int colour, float partialTicks) { + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + double realX = (x - player.lastTickPosX) + ((x - player.posX) - (x - player.lastTickPosX)) * partialTicks; + double realY = (y - player.lastTickPosY) + ((y - player.posY) - (y - player.lastTickPosY)) * partialTicks; + double realZ = (z - player.lastTickPosZ) + ((z - player.posZ) - (z - player.lastTickPosZ)) * partialTicks; + RenderManager renderManager = mc.getRenderManager(); + + float f = 1.6F; + float f1 = 0.016666668F * f; + int width = mc.fontRendererObj.getStringWidth(text) / 2; + GlStateManager.pushMatrix(); + GlStateManager.translate(realX, realY, realZ); + GL11.glNormal3f(0f, 1f, 0f); + GlStateManager.rotate(-renderManager.playerViewY, 0f, 1f, 0f); + GlStateManager.rotate(renderManager.playerViewX, 1f, 0f, 0f); + GlStateManager.scale(-f1, -f1, -f1); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + mc.fontRendererObj.drawString(text, -width, 0, colour); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + // I couldnt get waypoint strings to work so in the end I just copied from NEU // If anyone sees this please help /*public static void draw3DWaypointString(CrystalHollowWaypoints.Waypoint waypoint, float partialTicks) { -- cgit