From d79fc0ac187b4fc14228a5d83200d382e98b6bbe Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 24 Aug 2022 09:20:39 +0200 Subject: moving copyToClipboard into OSUtils.kt and renaming ConfigUtils --- .../config/gui/GuiOptionEditorDraggableList.java | 19 +- .../gui/core/config/gui/GuiPositionEditor.java | 21 +- .../config/gui/core/util/GuiElementSlider.java | 21 +- .../skyhanni/config/gui/utils/ConfigUtils.java | 314 ++++++++++++++++++++ .../hannibal2/skyhanni/config/gui/utils/Utils.java | 320 --------------------- .../skyhanni/test/command/CopyItemCommand.kt | 4 +- .../test/command/CopyNearbyEntitiesCommand.kt | 4 +- .../java/at/hannibal2/skyhanni/utils/OSUtils.kt | 6 + 8 files changed, 356 insertions(+), 353 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/gui/utils/Utils.java diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java index dccab640a..ba72f34b9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java +++ b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiOptionEditorDraggableList.java @@ -1,15 +1,10 @@ package at.hannibal2.skyhanni.config.gui.core.config.gui; -import static at.hannibal2.skyhanni.config.gui.GuiTextures.DELETE; -import static at.hannibal2.skyhanni.config.gui.GuiTextures.button_tex; - import at.hannibal2.skyhanni.config.gui.core.config.struct.ConfigProcessor; import at.hannibal2.skyhanni.config.gui.core.util.lerp.LerpUtils; import at.hannibal2.skyhanni.config.gui.core.util.render.RenderUtils; import at.hannibal2.skyhanni.config.gui.core.util.render.TextRenderUtils; -import at.hannibal2.skyhanni.config.gui.utils.Utils; -import java.util.ArrayList; -import java.util.List; +import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -19,6 +14,12 @@ import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.List; + +import static at.hannibal2.skyhanni.config.gui.GuiTextures.DELETE; +import static at.hannibal2.skyhanni.config.gui.GuiTextures.button_tex; + public class GuiOptionEditorDraggableList extends GuiOptionEditor { private final String[] exampleText; @@ -72,7 +73,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { GlStateManager.color(1, greenBlue, greenBlue, 1); } Minecraft.getMinecraft().getTextureManager().bindTexture(DELETE); - Utils.drawTexturedRect(x + width / 6 + 27, y + 45 - 7 - 13, 11, 14, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x + width / 6 + 27, y + 45 - 7 - 13, 11, 14, GL11.GL_NEAREST); Gui.drawRect(x + 5, y + 45, x + width - 5, y + height - 5, 0xffdddddd); Gui.drawRect(x + 6, y + 46, x + width - 6, y + height - 6, 0xff000000); @@ -89,7 +90,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { if (i++ != dragStartIndex) { for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { String line = multilines[multilineIndex]; - Utils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff); + ConfigUtils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff); } Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", x + 10, y + 50 + yOff + ySize / 2 - 4, 0xffffff, true); } @@ -157,7 +158,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { GlStateManager.enableBlend(); for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { String line = multilines[multilineIndex]; - Utils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, dragOffsetX + mouseX + 10, dragOffsetY + mouseY + multilineIndex * 10, true, width - 20, 0xffffff | (opacity << 24)); + ConfigUtils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, dragOffsetX + mouseX + 10, dragOffsetY + mouseY + multilineIndex * 10, true, width - 20, 0xffffff | (opacity << 24)); } int ySize = multilines.length * 10; diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java index 087fab743..efb04043f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java +++ b/src/main/java/at/hannibal2/skyhanni/config/gui/core/config/gui/GuiPositionEditor.java @@ -1,8 +1,7 @@ package at.hannibal2.skyhanni.config.gui.core.config.gui; import at.hannibal2.skyhanni.config.gui.core.config.Position; -import at.hannibal2.skyhanni.config.gui.utils.Utils; -import java.io.IOException; +import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; @@ -10,6 +9,8 @@ import net.minecraft.client.gui.ScaledResolution; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import java.io.IOException; + public class GuiPositionEditor extends GuiScreen { private final Position position; @@ -51,7 +52,7 @@ public class GuiPositionEditor extends GuiScreen { super.drawScreen(mouseX, mouseY, partialTicks); ScaledResolution scaledResolution; if (guiScaleOverride >= 0) { - scaledResolution = Utils.pushGuiScale(guiScaleOverride); + scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); } @@ -78,12 +79,12 @@ public class GuiPositionEditor extends GuiScreen { Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); if (guiScaleOverride >= 0) { - Utils.pushGuiScale(-1); + ConfigUtils.pushGuiScale(-1); } scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff); - Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff); + ConfigUtils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff); + ConfigUtils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff); } @Override @@ -93,7 +94,7 @@ public class GuiPositionEditor extends GuiScreen { if (mouseButton == 0) { ScaledResolution scaledResolution; if (guiScaleOverride >= 0) { - scaledResolution = Utils.pushGuiScale(guiScaleOverride); + scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); } @@ -112,7 +113,7 @@ public class GuiPositionEditor extends GuiScreen { } if (guiScaleOverride >= 0) { - Utils.pushGuiScale(-1); + ConfigUtils.pushGuiScale(-1); } } } @@ -152,7 +153,7 @@ public class GuiPositionEditor extends GuiScreen { if (clicked) { ScaledResolution scaledResolution; if (guiScaleOverride >= 0) { - scaledResolution = Utils.pushGuiScale(guiScaleOverride); + scaledResolution = ConfigUtils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); } @@ -164,7 +165,7 @@ public class GuiPositionEditor extends GuiScreen { positionChangedCallback.run(); if (guiScaleOverride >= 0) { - Utils.pushGuiScale(-1); + ConfigUtils.pushGuiScale(-1); } } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java index b5bd6636c..d55c9ed23 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java +++ b/src/main/java/at/hannibal2/skyhanni/config/gui/core/util/GuiElementSlider.java @@ -1,16 +1,17 @@ package at.hannibal2.skyhanni.config.gui.core.util; -import static at.hannibal2.skyhanni.config.gui.GuiTextures.*; - import at.hannibal2.skyhanni.config.gui.core.GuiElement; -import at.hannibal2.skyhanni.config.gui.utils.Utils; -import java.util.function.Consumer; +import at.hannibal2.skyhanni.config.gui.utils.ConfigUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.util.function.Consumer; + +import static at.hannibal2.skyhanni.config.gui.GuiTextures.*; + public class GuiElementSlider extends GuiElement { public int x; @@ -61,28 +62,28 @@ public class GuiElementSlider extends GuiElement { GlStateManager.color(1f, 1f, 1f, 1f); Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_cap); - Utils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_cap); - Utils.drawTexturedRect(x + width - 4, y, 4, HEIGHT, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x + width - 4, y, 4, HEIGHT, GL11.GL_NEAREST); if (sliderAmountI > 5) { Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_segment); - Utils.drawTexturedRect(x + 4, y, sliderAmountI - 4, HEIGHT, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x + 4, y, sliderAmountI - 4, HEIGHT, GL11.GL_NEAREST); } if (sliderAmountI < width - 5) { Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_segment); - Utils.drawTexturedRect(x + sliderAmountI, y, width - 4 - sliderAmountI, HEIGHT, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x + sliderAmountI, y, width - 4 - sliderAmountI, HEIGHT, GL11.GL_NEAREST); } for (int i = 1; i < 4; i++) { int notchX = x + width * i / 4 - 1; Minecraft.getMinecraft().getTextureManager().bindTexture(notchX > x + sliderAmountI ? slider_off_notch : slider_on_notch); - Utils.drawTexturedRect(notchX, y + (HEIGHT - 4f) / 2, 2, 4, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(notchX, y + (HEIGHT - 4f) / 2, 2, 4, GL11.GL_NEAREST); } Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button_new); - Utils.drawTexturedRect(x + sliderAmountI - 4, y, 8, HEIGHT, GL11.GL_NEAREST); + ConfigUtils.drawTexturedRect(x + sliderAmountI - 4, y, 8, HEIGHT, GL11.GL_NEAREST); } @Override diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java new file mode 100644 index 000000000..4d733b3da --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/gui/utils/ConfigUtils.java @@ -0,0 +1,314 @@ +package at.hannibal2.skyhanni.config.gui.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.Loader; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.math.RoundingMode; +import java.nio.FloatBuffer; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.LinkedList; +import java.util.Locale; + +public class ConfigUtils { + + private static final LinkedList guiScales = new LinkedList<>(); + private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft()); + //Labymod compatibility + private static final FloatBuffer projectionMatrixOld = BufferUtils.createFloatBuffer(16); + private static final FloatBuffer modelviewMatrixOld = BufferUtils.createFloatBuffer(16); + + public static String removeColor(String input) { + return input.replaceAll("(?i)\\u00A7.", ""); + } + + public static String removeWhiteSpaceAndRemoveWord(String input, String replace) { + return input.toLowerCase().replace(" ", "").replace(replace, ""); + } + + public static boolean inRangeInclusive(int value, int min, int max) { + return value <= max && value >= min; + } + + public static float lerp(float f, float g, float h) { + return g + f * (h - g); + } + + public static double lerp(double d, double e, double f) { + return e + d * (f - e); + } + + public static int lerp(float f, int g, int h) { + return (int) (g + f * (h - g)); + } + + public static NBTTagCompound getSkyBlockTag(ItemStack stack) { + if (stack == null) return null; + if (!stack.hasTagCompound()) return null; + if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; + return stack.getTagCompound().getCompoundTag("ExtraAttributes"); + } + + public static boolean isDrill(ItemStack stack) { + NBTTagCompound tag = getSkyBlockTag(stack); + return tag != null && tag.hasKey("drill_fuel"); + } + + public static boolean overlayShouldRender(RenderGameOverlayEvent.ElementType type, boolean... booleans) { + return overlayShouldRender(false, type, RenderGameOverlayEvent.ElementType.HOTBAR, booleans); + } + + public static boolean overlayShouldRender(boolean hideOnf3, RenderGameOverlayEvent.ElementType type, RenderGameOverlayEvent.ElementType checkType, boolean... booleans) { + Minecraft mc = Minecraft.getMinecraft(); + for (boolean aBoolean : booleans) if (!aBoolean) return false; + if (hideOnf3) { + if (mc.gameSettings.showDebugInfo || (mc.gameSettings.keyBindPlayerList.isKeyDown() && (!mc.isIntegratedServerRunning() || mc.thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { + return false; + } + } + return ((type == null && Loader.isModLoaded("labymod")) || type == checkType); + } + + public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len / (float) strLen; + factor = Math.min(1, factor); + + drawStringScaled(str, fr, x, y, shadow, colour, factor); + } + + public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { + GlStateManager.scale(factor, factor, 1); + fr.drawString(str, x / factor, y / factor, colour, shadow); + GlStateManager.scale(1 / factor, 1 / factor, 1); + } + + public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len / (float) strLen; + float fontHeight = 8 * factor; + + drawStringScaled(str, fr, x - len / 2f, y - fontHeight / 2f, shadow, colour, factor); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { + GlStateManager.enableTexture2D(); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); + worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); + worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); + worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); + tessellator.draw(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GlStateManager.disableBlend(); + } + + public static void drawTexturedRect(float x, float y, float width, float height) { + drawTexturedRect(x, y, width, height, 0, 1, 0, 1); + } + + public static void drawTexturedRect(float x, float y, float width, float height, int filter) { + drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { + drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_LINEAR); + } + + public static void resetGuiScale() { + guiScales.clear(); + } + + public static ScaledResolution peekGuiScale() { + return lastScale; + } + + public static ScaledResolution pushGuiScale(int scale) { + if (guiScales.size() == 0) { + if (Loader.isModLoaded("labymod")) { + GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrixOld); + GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewMatrixOld); + } + } + + if (scale < 0) { + if (guiScales.size() > 0) { + guiScales.pop(); + } + } else { + if (scale == 0) { + guiScales.push(Minecraft.getMinecraft().gameSettings.guiScale); + } else { + guiScales.push(scale); + } + } + + int newScale = guiScales.size() > 0 ? Math.max(0, Math.min(4, guiScales.peek())) : Minecraft.getMinecraft().gameSettings.guiScale; + if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; + + int oldScale = Minecraft.getMinecraft().gameSettings.guiScale; + Minecraft.getMinecraft().gameSettings.guiScale = newScale; + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + Minecraft.getMinecraft().gameSettings.guiScale = oldScale; + + if (guiScales.size() > 0) { + GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + } else { + if (Loader.isModLoaded("labymod") && projectionMatrixOld.limit() > 0 && modelviewMatrixOld.limit() > 0) { + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GL11.glLoadMatrix(projectionMatrixOld); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GL11.glLoadMatrix(modelviewMatrixOld); + } else { + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + } + } + + lastScale = scaledresolution; + return scaledresolution; + } + + public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { + int strLen = fr.getStringWidth(str); + + float x2 = x - strLen / 2f; + float y2 = y - fr.FONT_HEIGHT / 2f; + + GL11.glTranslatef(x2, y2, 0); + fr.drawString(str, 0, 0, colour, shadow); + GL11.glTranslatef(-x2, -y2, 0); + } + + public static void renderWaypointText(String str, BlockPos loc, 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 = loc.getX() - viewerX; + double y = loc.getY() - viewerY - viewer.getEyeHeight(); + double z = loc.getZ() - viewerZ; + + 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); + + drawNametag(str); + + 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); + + drawNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); + + GlStateManager.popMatrix(); + + GlStateManager.disableLighting(); + } + + public static void drawNametag(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 String formattedNumber(int number, int numberToFormatAt) { + DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); + formatter.setRoundingMode(RoundingMode.FLOOR); + return number > numberToFormatAt - 1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); + } + + public static boolean equalsIgnoreCaseAnyOf(String string, String... strings) { + for (String o : strings) if (string.equalsIgnoreCase(o)) return true; + return false; + } + + public static String getItemCustomId(ItemStack stack) { + if (stack == null) return null; + if (!stack.hasTagCompound()) return null; + if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; + if (!stack.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("id")) return null; + return stack.getTagCompound().getCompoundTag("ExtraAttributes").getString("id"); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/utils/Utils.java b/src/main/java/at/hannibal2/skyhanni/config/gui/utils/Utils.java deleted file mode 100644 index 51ffd0c8d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/utils/Utils.java +++ /dev/null @@ -1,320 +0,0 @@ -package at.hannibal2.skyhanni.config.gui.utils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.BlockPos; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.fml.common.Loader; -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; -import java.awt.datatransfer.StringSelection; -import java.math.RoundingMode; -import java.nio.FloatBuffer; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.LinkedList; -import java.util.Locale; - -public class Utils { - - private static final LinkedList guiScales = new LinkedList<>(); - private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft()); - //Labymod compatibility - private static final FloatBuffer projectionMatrixOld = BufferUtils.createFloatBuffer(16); - private static final FloatBuffer modelviewMatrixOld = BufferUtils.createFloatBuffer(16); - - public static String removeColor(String input) { - return input.replaceAll("(?i)\\u00A7.", ""); - } - - public static String removeWhiteSpaceAndRemoveWord(String input, String replace) { - return input.toLowerCase().replace(" ", "").replace(replace, ""); - } - - public static boolean inRangeInclusive(int value, int min, int max) { - return value <= max && value >= min; - } - - public static float lerp(float f, float g, float h) { - return g + f * (h - g); - } - - public static double lerp(double d, double e, double f) { - return e + d * (f - e); - } - - public static int lerp(float f, int g, int h) { - return (int) (g + f * (h - g)); - } - - public static NBTTagCompound getSkyBlockTag(ItemStack stack) { - if (stack == null) return null; - if (!stack.hasTagCompound()) return null; - if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; - return stack.getTagCompound().getCompoundTag("ExtraAttributes"); - } - - public static boolean isDrill(ItemStack stack) { - NBTTagCompound tag = getSkyBlockTag(stack); - return tag != null && tag.hasKey("drill_fuel"); - } - - public static boolean overlayShouldRender(RenderGameOverlayEvent.ElementType type, boolean... booleans) { - return overlayShouldRender(false, type, RenderGameOverlayEvent.ElementType.HOTBAR, booleans); - } - - public static boolean overlayShouldRender(boolean hideOnf3, RenderGameOverlayEvent.ElementType type, RenderGameOverlayEvent.ElementType checkType, boolean... booleans) { - Minecraft mc = Minecraft.getMinecraft(); - for (boolean aBoolean : booleans) if (!aBoolean) return false; - if (hideOnf3) { - if (mc.gameSettings.showDebugInfo || (mc.gameSettings.keyBindPlayerList.isKeyDown() && (!mc.isIntegratedServerRunning() || mc.thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { - return false; - } - } - return ((type == null && Loader.isModLoaded("labymod")) || type == checkType); - } - - public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - factor = Math.min(1, factor); - - drawStringScaled(str, fr, x, y, shadow, colour, factor); - } - - public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { - GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x / factor, y / factor, colour, shadow); - GlStateManager.scale(1 / factor, 1 / factor, 1); - } - - public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len / (float) strLen; - float fontHeight = 8 * factor; - - drawStringScaled(str, fr, x - len / 2f, y - fontHeight / 2f, shadow, colour, factor); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { - GlStateManager.enableTexture2D(); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); - worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); - worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); - worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); - tessellator.draw(); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - GlStateManager.disableBlend(); - } - - public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1); - } - - public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_LINEAR); - } - - public static void resetGuiScale() { - guiScales.clear(); - } - - public static ScaledResolution peekGuiScale() { - return lastScale; - } - - public static ScaledResolution pushGuiScale(int scale) { - if (guiScales.size() == 0) { - if (Loader.isModLoaded("labymod")) { - GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrixOld); - GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewMatrixOld); - } - } - - if (scale < 0) { - if (guiScales.size() > 0) { - guiScales.pop(); - } - } else { - if (scale == 0) { - guiScales.push(Minecraft.getMinecraft().gameSettings.guiScale); - } else { - guiScales.push(scale); - } - } - - int newScale = guiScales.size() > 0 ? Math.max(0, Math.min(4, guiScales.peek())) : Minecraft.getMinecraft().gameSettings.guiScale; - if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; - - int oldScale = Minecraft.getMinecraft().gameSettings.guiScale; - Minecraft.getMinecraft().gameSettings.guiScale = newScale; - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - Minecraft.getMinecraft().gameSettings.guiScale = oldScale; - - if (guiScales.size() > 0) { - GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - } else { - if (Loader.isModLoaded("labymod") && projectionMatrixOld.limit() > 0 && modelviewMatrixOld.limit() > 0) { - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GL11.glLoadMatrix(projectionMatrixOld); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GL11.glLoadMatrix(modelviewMatrixOld); - } else { - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - } - } - - lastScale = scaledresolution; - return scaledresolution; - } - - public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { - int strLen = fr.getStringWidth(str); - - float x2 = x - strLen / 2f; - float y2 = y - fr.FONT_HEIGHT / 2f; - - GL11.glTranslatef(x2, y2, 0); - fr.drawString(str, 0, 0, colour, shadow); - GL11.glTranslatef(-x2, -y2, 0); - } - - public static void renderWaypointText(String str, BlockPos loc, 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 = loc.getX() - viewerX; - double y = loc.getY() - viewerY - viewer.getEyeHeight(); - double z = loc.getZ() - viewerZ; - - 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); - - drawNametag(str); - - 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); - - drawNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); - - GlStateManager.popMatrix(); - - GlStateManager.disableLighting(); - } - - public static void drawNametag(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 String formattedNumber(int number, int numberToFormatAt) { - DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); - formatter.setRoundingMode(RoundingMode.FLOOR); - return number > numberToFormatAt - 1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); - } - - public static boolean equalsIgnoreCaseAnyOf(String string, String... strings) { - for (String o : strings) if (string.equalsIgnoreCase(o)) return true; - return false; - } - - public static String getItemCustomId(ItemStack stack) { - if (stack == null) return null; - if (!stack.hasTagCompound()) return null; - if (!stack.getTagCompound().hasKey("ExtraAttributes")) return null; - if (!stack.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("id")) return null; - return stack.getTagCompound().getCompoundTag("ExtraAttributes").getString("id"); - } - public static void copyToClipboard(String str) { - Toolkit.getDefaultToolkit().getSystemClipboard() - .setContents(new StringSelection(str), null); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt index 854ab26eb..f00f73040 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt @@ -1,10 +1,10 @@ package at.hannibal2.skyhanni.test.command -import at.hannibal2.skyhanni.config.gui.utils.Utils import at.hannibal2.skyhanni.test.LorenzTest import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.OSUtils import net.minecraft.client.Minecraft object CopyItemCommand { @@ -38,7 +38,7 @@ object CopyItemCommand { } val string = resultList.joinToString("\n") - Utils.copyToClipboard(string) + OSUtils.copyToClipboard(string) LorenzUtils.debug("item info printed!") LorenzUtils.chat("§e[SkyHanni] item info copied into the clipboard!") } catch (_: Throwable) { diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt index c5a05d94a..718c8adfc 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt @@ -1,11 +1,11 @@ package at.hannibal2.skyhanni.test.command -import at.hannibal2.skyhanni.config.gui.utils.Utils import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth +import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.toLorenzVec import net.minecraft.client.Minecraft import net.minecraft.entity.EntityLivingBase @@ -95,7 +95,7 @@ object CopyNearbyEntitiesCommand { if (counter != 0) { val string = resultList.joinToString("\n") - Utils.copyToClipboard(string) + OSUtils.copyToClipboard(string) LorenzUtils.chat("§e[SkyHanni] $counter entities copied into the clipboard!") } else { LorenzUtils.chat("§e[SkyHanni] No entities found in a search radius of $searchRadius!") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt index 5633e7f72..cb87ff2cd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.utils import java.awt.Desktop +import java.awt.Toolkit +import java.awt.datatransfer.StringSelection import java.io.IOException import java.net.URI @@ -18,4 +20,8 @@ object OSUtils { LorenzUtils.warning("[SkyHanni] Web browser is not supported!") } } + + fun copyToClipboard(text: String) { + Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(text), null) + } } \ No newline at end of file -- cgit