diff options
author | bowser0000 <bowser0000@gmail.com> | 2022-08-15 20:40:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 20:40:34 -0400 |
commit | 3aa11b859a2a22be30a5035f7273e1a604a4dde4 (patch) | |
tree | 8f428b29a6b56cc9d010b0441bf41b6b78373548 /src/main/java/me/Danker/utils | |
parent | 33710ac6d9f57fa59e8dfb19a81b053346f1b097 (diff) | |
parent | daceea1e42371c295c36f80b3246601a6ffb2cc5 (diff) | |
download | SkyblockMod-master.tar.gz SkyblockMod-master.tar.bz2 SkyblockMod-master.zip |
1.8.7
Diffstat (limited to 'src/main/java/me/Danker/utils')
-rw-r--r-- | src/main/java/me/Danker/utils/BoulderUtils.java | 20 | ||||
-rw-r--r-- | src/main/java/me/Danker/utils/RenderUtils.java | 416 | ||||
-rw-r--r-- | src/main/java/me/Danker/utils/Utils.java | 494 |
3 files changed, 689 insertions, 241 deletions
diff --git a/src/main/java/me/Danker/utils/BoulderUtils.java b/src/main/java/me/Danker/utils/BoulderUtils.java index 2d437d0..ca26c96 100644 --- a/src/main/java/me/Danker/utils/BoulderUtils.java +++ b/src/main/java/me/Danker/utils/BoulderUtils.java @@ -254,26 +254,26 @@ public class BoulderUtils { double averageZ = (aabb.minZ + aabb.maxZ) / 2; if (((boulderRoomDirection.equals("north") || boulderRoomDirection.equals("south")) && (direction == 'u' || direction == 'd')) || ((boulderRoomDirection.equals("east") || boulderRoomDirection.equals("west")) && (direction == 'l' || direction == 'r'))) { - Utils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(averageX, aabb.minY, aabb.maxZ), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(averageX, aabb.minY, aabb.maxZ), colourInt, 10, false, partialTicks); } else { - Utils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.maxX, aabb.minY, averageZ), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.maxX, aabb.minY, averageZ), colourInt, 10, false, partialTicks); } if ((boulderRoomDirection.equals("north") && direction == 'u') || (boulderRoomDirection.equals("south") && direction == 'd') || (boulderRoomDirection.equals("east") && direction == 'l') || (boulderRoomDirection.equals("west") && direction == 'r')) { - Utils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); - Utils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.minZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); } else if ((boulderRoomDirection.equals("north") && direction == 'd') || (boulderRoomDirection.equals("south") && direction == 'u') || (boulderRoomDirection.equals("east") && direction == 'r') || (boulderRoomDirection.equals("west") && direction == 'l')) { - Utils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.maxZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); - Utils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.maxZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.maxZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(averageX, aabb.minY, aabb.maxZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); } else if ((boulderRoomDirection.equals("north") && direction == 'l') || (boulderRoomDirection.equals("south") && direction == 'r') || (boulderRoomDirection.equals("east") && direction == 'd') || (boulderRoomDirection.equals("west") && direction == 'u')) { - Utils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); - Utils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(aabb.minX, aabb.minY, averageZ), new Vec3(aabb.minX + thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); } else { - Utils.draw3DLine(new Vec3(aabb.maxX, aabb.minY, averageZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); - Utils.draw3DLine(new Vec3(aabb.maxX, aabb.minY, averageZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(aabb.maxX, aabb.minY, averageZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.minZ + thirtyPercent), colourInt, 10, false, partialTicks); + RenderUtils.draw3DLine(new Vec3(aabb.maxX, aabb.minY, averageZ), new Vec3(aabb.maxX - thirtyPercent, aabb.minY, aabb.maxZ - thirtyPercent), colourInt, 10, false, partialTicks); } } diff --git a/src/main/java/me/Danker/utils/RenderUtils.java b/src/main/java/me/Danker/utils/RenderUtils.java new file mode 100644 index 0000000..00f49b3 --- /dev/null +++ b/src/main/java/me/Danker/utils/RenderUtils.java @@ -0,0 +1,416 @@ +package me.Danker.utils; + +import me.Danker.features.CrystalHollowWaypoints; +import me.Danker.handlers.TextRenderer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class RenderUtils { + + public static void drawTitle(String text) { + Minecraft mc = Minecraft.getMinecraft(); + ScaledResolution scaledResolution = new ScaledResolution(mc); + + int height = scaledResolution.getScaledHeight(); + int width = scaledResolution.getScaledWidth(); + int drawHeight = 0; + String[] splitText = text.split("\n"); + for (String title : splitText) { + int textLength = mc.fontRendererObj.getStringWidth(title); + + double scale = 4; + if (textLength * scale > (width * 0.9F)) { + scale = (width * 0.9F) / (float) textLength; + } + + int titleX = (int) ((width / 2) - (textLength * scale / 2)); + int titleY = (int) ((height * 0.45) / scale) + (int) (drawHeight * scale); + new TextRenderer(mc, title, titleX, titleY, scale); + drawHeight += mc.fontRendererObj.FONT_HEIGHT; + } + } + + public static void drawOnSlot(int size, int xSlotPos, int ySlotPos, int colour) { + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + int guiLeft = (sr.getScaledWidth() - 176) / 2; + int guiTop = (sr.getScaledHeight() - 222) / 2; + int x = guiLeft + xSlotPos; + int y = guiTop + ySlotPos; + // Move down when chest isn't 6 rows + if (size != 90) y += (6 - (size - 36) / 9) * 9; + + GL11.glTranslated(0, 0, 1); + Gui.drawRect(x, y, x + 16, y + 16, colour); + GL11.glTranslated(0, 0, -1); + } + + public static void drawTextOnSlot(int size, int xSlotPos, int ySlotPos, String text) { + Minecraft mc = Minecraft.getMinecraft(); + ScaledResolution sr = new ScaledResolution(mc); + int guiLeft = (sr.getScaledWidth() - 176) / 2; + int guiTop = (sr.getScaledHeight() - 222) / 2; + int x = guiLeft + xSlotPos; + int y = guiTop + ySlotPos; + // Move down when chest isn't 6 rows + if (size != 90) y += (6 - (size - 36) / 9) * 9; + + int width = mc.fontRendererObj.getStringWidth(text); + GL11.glTranslated(0, 0, 1); + mc.fontRendererObj.drawString(text, x + 8 - width / 2, y + 5, 0xFFFFFF, true); + GL11.glTranslated(0, 0, -1); + } + + public static void draw3DLine(Vec3 pos1, Vec3 pos2, int colourInt, int lineWidth, boolean depth, float partialTicks) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + Color colour = new Color(colourInt); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glLineWidth(lineWidth); + if (!depth) { + GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(false); + } + GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue() / 255f, colour.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + + worldRenderer.pos(pos1.xCoord, pos1.yCoord, pos1.zCoord).endVertex(); + worldRenderer.pos(pos2.xCoord, pos2.yCoord, pos2.zCoord).endVertex(); + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + if (!depth) { + GL11.glEnable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(true); + } + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + + public static void draw3DString(BlockPos pos, String text, int colour, float partialTicks) { + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + double x = (pos.getX() - player.lastTickPosX) + ((pos.getX() - player.posX) - (pos.getX() - player.lastTickPosX)) * partialTicks; + double y = (pos.getY() - player.lastTickPosY) + ((pos.getY() - player.posY) - (pos.getY() - player.lastTickPosY)) * partialTicks; + double z = (pos.getZ() - player.lastTickPosZ) + ((pos.getZ() - player.posZ) - (pos.getZ() - 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(x, y, z); + 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(); + } + + 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) { + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + BlockPos pos = waypoint.pos; + double x = (pos.getX() - player.lastTickPosX) + ((pos.getX() - player.posX) - (pos.getX() - player.lastTickPosX)) * partialTicks; + double y = (pos.getY() - player.lastTickPosY) + ((pos.getY() - player.posY) - (pos.getY() - player.lastTickPosY)) * partialTicks; + double z = (pos.getZ() - player.lastTickPosZ) + ((pos.getZ() - player.posZ) - (pos.getZ() - player.lastTickPosZ)) * partialTicks; + + double distance = player.getDistance(x, y, z); + if (distance > 12) { + x *= 12 / distance; + y *= 12 / distance; + z *= 12 / distance; + } + + RenderManager renderManager = mc.getRenderManager(); + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + + float f = 1.6F; + float f1 = 0.016666668F * f; + int width = mc.fontRendererObj.getStringWidth(waypoint.location) / 2; + int width2 = mc.fontRendererObj.getStringWidth(waypoint.getDistance(player)) / 2; + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, z); + 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); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(false); + + mc.fontRendererObj.drawString(waypoint.location, -width, 0, 0x55FFFF); + + GlStateManager.rotate(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.translate(0, -1, 0); + GlStateManager.rotate(-renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + + mc.fontRendererObj.drawString(waypoint.getDistance(player), -width2, 0, 0xFFFF55); + + GL11.glEnable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(true); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + }*/ + + // https://github.com/Moulberry/NotEnoughUpdates/blob/master/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java#L261 + public static void draw3DWaypointString(CrystalHollowWaypoints.Waypoint waypoint, float partialTicks) { + GlStateManager.alphaFunc(516, 0.1F); + + GlStateManager.pushMatrix(); + + Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); + double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; + double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; + double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; + + double x = waypoint.pos.getX()-viewerX+0.5f; + double y = waypoint.pos.getY()-viewerY-viewer.getEyeHeight(); + double z = waypoint.pos.getZ()-viewerZ+0.5f; + + double distSq = x*x + y*y + z*z; + double dist = Math.sqrt(distSq); + if(distSq > 144) { + x *= 12/dist; + y *= 12/dist; + z *= 12/dist; + } + GlStateManager.translate(x, y, z); + GlStateManager.translate(0, viewer.getEyeHeight(), 0); + + renderNametag(EnumChatFormatting.AQUA + waypoint.location); + + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.translate(0, -0.25f, 0); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + + renderNametag(EnumChatFormatting.YELLOW + waypoint.getDistance(Minecraft.getMinecraft().thePlayer)); + + GlStateManager.popMatrix(); + + GlStateManager.disableLighting(); + } + + // https://github.com/Moulberry/NotEnoughUpdates/blob/master/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesWaypoints.java#L300 + public static void renderNametag(String str) { + FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; + float f = 1.6F; + float f1 = 0.016666668F * f; + GlStateManager.pushMatrix(); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.scale(-f1, -f1, f1); + GlStateManager.disableLighting(); + GlStateManager.depthMask(false); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int i = 0; + + int j = fontrenderer.getStringWidth(str) / 2; + GlStateManager.disableTexture2D(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); + GlStateManager.depthMask(true); + + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); + + GlStateManager.enableDepth(); + GlStateManager.enableBlend(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + + public static void draw3DBox(AxisAlignedBB aabb, int colourInt, float partialTicks) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + Color colour = new Color(colourInt); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glLineWidth(2); + + RenderGlobal.drawOutlinedBoundingBox(aabb, colour.getRed(), colour.getGreen(), colour.getBlue(), colour.getAlpha()); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + + public static void drawFilled3DBox(AxisAlignedBB aabb, int colourInt, boolean translucent, boolean depth, float partialTicks) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + Color colour = new Color(colourInt); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableAlpha(); + GlStateManager.enableBlend(); + GlStateManager.disableCull(); + GlStateManager.tryBlendFuncSeparate(770, translucent ? 1 : 771, 1, 0); + if (!depth) { + GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(false); + } + GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue() / 255f, colour.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + // Bottom + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); + // Top + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); + // West + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); + // East + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); + // North + worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); + // South + worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); + worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + if (!depth) { + GL11.glEnable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(true); + } + GlStateManager.enableCull(); + GlStateManager.disableAlpha(); + GlStateManager.disableBlend(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + } + + public static void renderItem(ItemStack stack, int x, int y, double scale) { + renderItem(stack, x, y, 0, scale); + } + + public static void renderItem(ItemStack stack, int x, int y, int z, double scale) { + GlStateManager.enableRescaleNormal(); + RenderHelper.enableGUIStandardItemLighting(); + + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, z); + GlStateManager.scale(scale, scale, scale); + + Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0); + + GlStateManager.popMatrix(); + + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableRescaleNormal(); + } + + public static void drawCenteredText(String text, int screenWidth, int height, double scale) { + Minecraft mc = Minecraft.getMinecraft(); + int textWidth = mc.fontRendererObj.getStringWidth(text); + new TextRenderer(mc, text, screenWidth / 2 - textWidth / 2, height, scale); + } + +} diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java index 1a24c69..7c92620 100644 --- a/src/main/java/me/Danker/utils/Utils.java +++ b/src/main/java/me/Danker/utils/Utils.java @@ -1,18 +1,16 @@ package me.Danker.utils; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import me.Danker.DankersSkyblockMod; +import me.Danker.features.ColouredNames; import me.Danker.features.GoldenEnchants; +import me.Danker.handlers.APIHandler; +import me.Danker.handlers.ConfigHandler; import me.Danker.handlers.ScoreboardHandler; -import me.Danker.handlers.TextRenderer; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItemFrame; import net.minecraft.entity.player.EntityPlayer; @@ -22,19 +20,20 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.util.*; -import org.lwjgl.opengl.GL11; import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; +import java.util.*; import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class Utils { public static boolean inSkyblock = false; public static boolean inDungeons = false; + public static DungeonFloor currentFloor = DungeonFloor.NONE; + public static String tabLocation = ""; public static int[] skillXPPerLevel = {0, 50, 125, 200, 300, 500, 750, 1000, 1500, 2000, 3500, 5000, 7500, 10000, 15000, 20000, 30000, 50000, 75000, 100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000, @@ -45,6 +44,17 @@ public class Utils { 1065000, 1410000, 1900000, 2500000, 3300000, 4300000, 5600000, 7200000, 9200000, 12000000, 15000000, 19000000, 24000000, 30000000, 38000000, 48000000, 60000000, 75000000, 93000000, 116250000}; static int[] expertiseKills = {50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000}; + static Pattern boldPattern = Pattern.compile("(?i)\\u00A7L"); + static Map<Character, Integer> romanNumerals = new HashMap<Character, Integer>(){{ + put('I', 1); + put('V', 5); + put('X', 10); + put('L', 50); + put('C', 100); + put('D', 500); + put('M', 1000); + }}; + public static String TITLE_SOUND; public static int getItems(String item) { Minecraft mc = Minecraft.getMinecraft(); @@ -92,34 +102,11 @@ public class Utils { } public static void createTitle(String text, int seconds) { - Minecraft.getMinecraft().thePlayer.playSound("random.orb", 1, (float) 0.5); + Minecraft.getMinecraft().thePlayer.playSound(TITLE_SOUND, 1, (float) 0.5); DankersSkyblockMod.titleTimer = seconds * 20; DankersSkyblockMod.showTitle = true; DankersSkyblockMod.titleText = text; } - - public static void drawTitle(String text) { - Minecraft mc = Minecraft.getMinecraft(); - ScaledResolution scaledResolution = new ScaledResolution(mc); - - int height = scaledResolution.getScaledHeight(); - int width = scaledResolution.getScaledWidth(); - int drawHeight = 0; - String[] splitText = text.split("\n"); - for (String title : splitText) { - int textLength = mc.fontRendererObj.getStringWidth(title); - - double scale = 4; - if (textLength * scale > (width * 0.9F)) { - scale = (width * 0.9F) / (float) textLength; - } - - int titleX = (int) ((width / 2) - (textLength * scale / 2)); - int titleY = (int) ((height * 0.45) / scale) + (int) (drawHeight * scale); - new TextRenderer(mc, title, titleX, titleY, scale); - drawHeight += mc.fontRendererObj.FONT_HEIGHT; - } - } public static boolean isOnHypixel() { Minecraft mc = Minecraft.getMinecraft(); @@ -145,17 +132,62 @@ public class Utils { } public static void checkForDungeons() { - if (inSkyblock) { + if (inSkyblock) { + if (isInScoreboard("The Catacombs")) { + inDungeons = true; + return; + } + } + inDungeons = false; + } + + public static void checkForDungeonFloor() { + if (inDungeons) { List<String> scoreboard = ScoreboardHandler.getSidebarLines(); + for (String s : scoreboard) { String sCleaned = ScoreboardHandler.cleanSB(s); - if (sCleaned.contains("The Catacombs")) { - inDungeons = true; + + if (sCleaned.contains("The Catacombs (")) { + String floor = sCleaned.substring(sCleaned.indexOf("(") + 1, sCleaned.indexOf(")")); + + try { + currentFloor = DungeonFloor.valueOf(floor); + } catch (IllegalArgumentException ex) { + currentFloor = DungeonFloor.NONE; + ex.printStackTrace(); + } + + break; + } + } + } else { + currentFloor = DungeonFloor.NONE; + } + } + + public static void checkTabLocation() { + if (inSkyblock) { + Collection<NetworkPlayerInfo> players = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap(); + for (NetworkPlayerInfo player : players) { + if (player == null || player.getDisplayName() == null) continue; + String text = player.getDisplayName().getUnformattedText(); + if (text.startsWith("Area: ")) { + tabLocation = text.substring(text.indexOf(":") + 2); return; } } } - inDungeons = false; + tabLocation = ""; + } + + public static boolean isInScoreboard(String text) { + List<String> scoreboard = ScoreboardHandler.getSidebarLines(); + for (String s : scoreboard) { + String sCleaned = ScoreboardHandler.cleanSB(s); + if (sCleaned.contains(text)) return true; + } + return false; } public static String capitalizeString(String string) { @@ -175,20 +207,6 @@ public class Utils { return result; } - public static void drawOnSlot(int size, int xSlotPos, int ySlotPos, int colour) { - ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); - int guiLeft = (sr.getScaledWidth() - 176) / 2; - int guiTop = (sr.getScaledHeight() - 222) / 2; - int x = guiLeft + xSlotPos; - int y = guiTop + ySlotPos; - // Move down when chest isn't 6 rows - if (size != 90) y += (6 - (size - 36) / 9) * 9; - - GL11.glTranslated(0, 0, 1); - Gui.drawRect(x, y, x + 16, y + 16, colour); - GL11.glTranslated(0, 0, -1); - } - public static String getTimeBetween(double timeOne, double timeTwo) { double secondsBetween = Math.floor(timeTwo - timeOne); @@ -233,16 +251,26 @@ public class Utils { } return limit; } + + public static int skillLevelToXp(int level) { + int sum = 0; + + for (int i = 1; i <= level; i++) { + sum += skillXPPerLevel[i]; + } + + return sum; + } public static double xpToDungeonsLevel(double xp) { for (int i = 0, xpAdded = 0; i < dungeonsXPPerLevel.length; i++) { xpAdded += dungeonsXPPerLevel[i]; if (xp < xpAdded) { double level = (i - 1) + (xp - (xpAdded - dungeonsXPPerLevel[i])) / dungeonsXPPerLevel[i]; - return (double) Math.round(level * 100) / 100; + return (double) Math.round(level * 100D) / 100; } } - return 50D; + return 50D + MathHelper.clamp_double(Math.round((xp - 569809640D) / 200000000D * 100D) / 100D, 0D, 49D); } public static int expertiseKillsLeft(int kills) { @@ -253,7 +281,8 @@ public class Utils { } return -1; } - + + // Only used when over limit public static int getPastXpEarned(int currentLevelXp, int limit) { if (currentLevelXp == 0) { int xpAdded = 0; @@ -268,6 +297,16 @@ public class Utils { } return 0; } + + public static double getTotalXpEarned(int currentLevel, double percentage) { + double progress = 0; + if (currentLevel < 60) progress = skillXPPerLevel[currentLevel + 1] * (percentage / 100D); + double xpAdded = 0; + for (int i = 1; i <= currentLevel; i++) { + xpAdded += skillXPPerLevel[i]; + } + return xpAdded + progress; + } public static String getColouredBoolean(boolean bool) { return bool ? EnumChatFormatting.GREEN + "On" : EnumChatFormatting.RED + "Off"; @@ -305,180 +344,6 @@ public class Utils { }); } - public static void draw3DLine(Vec3 pos1, Vec3 pos2, int colourInt, int lineWidth, boolean depth, float partialTicks) { - Entity render = Minecraft.getMinecraft().getRenderViewEntity(); - WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); - Color colour = new Color(colourInt); - - double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; - double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; - double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; - - GlStateManager.pushMatrix(); - GlStateManager.translate(-realX, -realY, -realZ); - GlStateManager.disableTexture2D(); - GlStateManager.enableBlend(); - GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GL11.glLineWidth(lineWidth); - if (!depth) { - GL11.glDisable(GL11.GL_DEPTH_TEST); - GlStateManager.depthMask(false); - } - GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue() / 255f, colour.getAlpha() / 255f); - worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); - - worldRenderer.pos(pos1.xCoord, pos1.yCoord, pos1.zCoord).endVertex(); - worldRenderer.pos(pos2.xCoord, pos2.yCoord, pos2.zCoord).endVertex(); - Tessellator.getInstance().draw(); - - GlStateManager.translate(realX, realY, realZ); - if (!depth) { - GL11.glEnable(GL11.GL_DEPTH_TEST); - GlStateManager.depthMask(true); - } - GlStateManager.disableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.enableTexture2D(); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.popMatrix(); - } - - public static void draw3DString(BlockPos pos, String text, int colour, float partialTicks) { - Minecraft mc = Minecraft.getMinecraft(); - EntityPlayer player = mc.thePlayer; - double x = (pos.getX() - player.lastTickPosX) + ((pos.getX() - player.posX) - (pos.getX() - player.lastTickPosX)) * partialTicks; - double y = (pos.getY() - player.lastTickPosY) + ((pos.getY() - player.posY) - (pos.getY() - player.lastTickPosY)) * partialTicks; - double z = (pos.getZ() - player.lastTickPosZ) + ((pos.getZ() - player.posZ) - (pos.getZ() - 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(x, y, z); - 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(); - } - - public static void draw3DBox(AxisAlignedBB aabb, int colourInt, float partialTicks) { - Entity render = Minecraft.getMinecraft().getRenderViewEntity(); - Color colour = new Color(colourInt); - - double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; - double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; - double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; - - GlStateManager.pushMatrix(); - GlStateManager.translate(-realX, -realY, -realZ); - GlStateManager.disableTexture2D(); - GlStateManager.enableBlend(); - GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GL11.glLineWidth(2); - - RenderGlobal.drawOutlinedBoundingBox(aabb, colour.getRed(), colour.getGreen(), colour.getBlue(), colour.getAlpha()); - - GlStateManager.translate(realX, realY, realZ); - GlStateManager.disableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.enableTexture2D(); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.popMatrix(); - } - - public static void drawFilled3DBox(AxisAlignedBB aabb, int colourInt, boolean translucent, boolean depth, float partialTicks) { - Entity render = Minecraft.getMinecraft().getRenderViewEntity(); - WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); - Color colour = new Color(colourInt); - - double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; - double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; - double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; - - GlStateManager.pushMatrix(); - GlStateManager.pushAttrib(); - GlStateManager.translate(-realX, -realY, -realZ); - GlStateManager.disableTexture2D(); - GlStateManager.enableAlpha(); - GlStateManager.enableBlend(); - GlStateManager.disableCull(); - GlStateManager.tryBlendFuncSeparate(770, translucent ? 1 : 771, 1, 0); - if (!depth) { - GL11.glDisable(GL11.GL_DEPTH_TEST); - GlStateManager.depthMask(false); - } - GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue() / 255f, colour.getAlpha() / 255f); - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - // Bottom - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); - // Top - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); - // West - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); - // East - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); - // North - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex(); - // South - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex(); - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex(); - Tessellator.getInstance().draw(); - - GlStateManager.translate(realX, realY, realZ); - if (!depth) { - GL11.glEnable(GL11.GL_DEPTH_TEST); - GlStateManager.depthMask(true); - } - GlStateManager.enableCull(); - GlStateManager.disableAlpha(); - GlStateManager.disableBlend(); - GlStateManager.enableTexture2D(); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.popAttrib(); - GlStateManager.popMatrix(); - } - - public static void renderItem(ItemStack item, float x, float y, float z) { - - GlStateManager.enableRescaleNormal(); - RenderHelper.enableGUIStandardItemLighting(); - GlStateManager.enableDepth(); - - GlStateManager.pushMatrix(); - GlStateManager.translate(x, y, z); - Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(item, 0, 0); - GlStateManager.popMatrix(); - - GlStateManager.disableDepth(); - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableRescaleNormal(); - } - public static BlockPos getFirstBlockPosAfterVectors(Minecraft mc, Vec3 pos1, Vec3 pos2, int strength, int distance) { double x = pos2.xCoord - pos1.xCoord; double y = pos2.yCoord - pos1.yCoord; @@ -533,5 +398,172 @@ public class Utils { return null; } } - + + public static boolean isRealPlayer(EntityPlayer player) { + return player.getUniqueID().version() == 4 && !player.isPlayerSleeping(); + } + + public static String removeBold(String text) { + return boldPattern.matcher(text).replaceAll(""); + } + + public static int getIntFromString(String text, boolean romanNumeral) { + if (text.matches(".*\\d.*")) { + return Integer.parseInt(StringUtils.stripControlCodes(text).replaceAll("[^\\d]", "")); + } else if (romanNumeral) { + int number = 0; + + for (int i = 0; i < text.length(); i++) { + if (!romanNumerals.containsKey(text.charAt(i))) continue; + int roman = romanNumerals.get(text.charAt(i)); + + if (i != text.length() - 1 && romanNumerals.containsKey(text.charAt(i + 1)) && roman < romanNumerals.get(text.charAt(i + 1))) { + number += romanNumerals.get(text.charAt(i + 1)) - roman; + i++; + } else { + number += roman; + } + } + + return number; + } + + return -1; + } + + public static boolean skillsInitialized() { + return DankersSkyblockMod.miningLevel != -1; + } + + public static int initializeSkill(ItemStack skillStack, String configValue) { + int level = -1; + + if (skillStack != null) { + String display = skillStack.getDisplayName(); + if (display.startsWith("§a")) { + if (display.contains(" ")) { + level = Utils.getIntFromString(display.substring(display.indexOf(" ") + 1), true); + } else { + level = 0; + } + } + } + + ConfigHandler.writeIntConfig("skills", configValue, level); + return level; + } + + public static void refreshRepo() { + DankersSkyblockMod.data = APIHandler.getResponse("https://raw.githubusercontent.com/bowser0000/SkyblockMod-REPO/main/data.json", false); + System.out.println("Loaded data from GitHub?: " + (DankersSkyblockMod.data != null && DankersSkyblockMod.data.has("trivia"))); + ColouredNames.users = DankersSkyblockMod.data.get("colourednames").getAsJsonObject().entrySet().stream() + .map(Map.Entry::getKey) + .collect(Collectors.toCollection(ArrayList::new)); + System.out.println("Refreshed DSM repo at " + System.currentTimeMillis()); + } + + public static int getCooldownFromAbility(String ability) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + boolean foundAbility = false; + + List<ItemStack> itemsToSearch = new ArrayList<>(); + + for (int i = 0; i < 8; i++) { + ItemStack hotbarItem = player.inventory.getStackInSlot(i); + if (hotbarItem == null) continue; + itemsToSearch.add(hotbarItem); + } + + for (int i = 0; i < 4; i++) { + ItemStack armorItem = player.inventory.armorItemInSlot(0); + if (armorItem == null) continue; + itemsToSearch.add(armorItem); + } + + for (ItemStack item : itemsToSearch) { + List<String> tooltip = item.getTooltip(player, false); + + for (String line : tooltip) { + if (line.contains(EnumChatFormatting.GOLD + "Ability: ") || line.contains(EnumChatFormatting.GOLD + "Full Set Bonus: ")) { + if (line.contains(EnumChatFormatting.GOLD + "Ability: " + ability)) { + foundAbility = true; + continue; + } else if (foundAbility) { + break; + } + } + + if (foundAbility && line.contains(EnumChatFormatting.DARK_GRAY + "Cooldown: ")) { + return Integer.parseInt(StringUtils.stripControlCodes(line).replaceAll("[^\\d]", "")); + } + } + } + + return 0; + } + + public static double getCooldownReductionFromLevel(int level) { + return (Math.floor(level / 2D) + 25) / 100D; + } + + public static void desktopNotification(String name, String title, String text, TrayIcon.MessageType messageType) { + try { + final SystemTray tray = SystemTray.getSystemTray(); + final Image image = Toolkit.getDefaultToolkit().createImage("icon.png"); + final TrayIcon trayIcon = new TrayIcon(image, name); + trayIcon.setImageAutoSize(true); + trayIcon.setToolTip(name); + tray.add(trayIcon); + trayIcon.displayMessage(title, text, messageType); + tray.remove(trayIcon); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static JsonObject deepCopy(JsonObject obj) { + JsonObject newObj = new JsonObject(); + + for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { + newObj.add(entry.getKey(), entry.getValue()); + } + + return newObj; + } + + // https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java#L139-L148 + public static NBTTagCompound getExtraAttributes(ItemStack item) { + if (item == null || !item.hasTagCompound()) return null; + return item.getSubCompound("ExtraAttributes", false); + } + + // https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java#L116-L131 + public static String getSkyblockItemID(ItemStack item) { + if (item == null) return null; + + NBTTagCompound extraAttributes = getExtraAttributes(item); + if (extraAttributes == null || !extraAttributes.hasKey("id", 8)) return null; + + return extraAttributes.getString("id"); + } + + public enum DungeonFloor { + NONE, + E0, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + M1, + M2, + M3, + M4, + M5, + M6, + M7 + } + } |