Search in sources :

Example 6 with DynamicTexture

use of net.minecraft.client.renderer.texture.DynamicTexture in project IDEProgram by Itay2805.

the class GLCanvas method render.

@Override
public void render(Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, boolean windowActive, float partialTicks) {
    ByteBuffer buffer = ByteBuffer.allocate(width * height * 3);
    gl.readPixels(0, 0, width, height, GL.RGB, GL.BYTE, buffer);
    image.getRaster().setDataElements(0, 0, width, height, buffer.array());
    rc = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("opengl11_context_image", new DynamicTexture(image));
    mc.getRenderManager().renderEngine.bindTexture(rc);
    drawRectWithFullTexture(x, y, 0, 0, width, height);
}
Also used : DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ByteBuffer(java.nio.ByteBuffer)

Example 7 with DynamicTexture

use of net.minecraft.client.renderer.texture.DynamicTexture in project Hyperium by HyperiumClient.

the class PlayerStatsGui method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    if (!texturesImage.isEmpty()) {
        texturesImage.forEach((s, value) -> {
            if (!logos.containsKey(s))
                logos.put(s, new DynamicTexture(value));
        });
    }
    super.drawScreen(mouseX, mouseY, partialTicks);
    ScaledResolution current = ResolutionUtil.current();
    HypixelApiGuild guild = player.getGuild();
    if (guild == null) {
        GeneralChatHandler.instance().sendMessage("Player not found!");
        mc.displayGuiScreen(null);
        return;
    }
    boolean isInGuild = guild.isLoaded() && guild.isValid();
    drawScaledText(player.getDisplayString() + (isInGuild ? " " + guild.getFormatedTag() : ""), current.getScaledWidth() / 2, 30, 2, -1, true, true);
    if (focused == null) {
        final int blockWidth = 64 + 32;
        int blocksPerLine = (int) (current.getScaledWidth() / (1.2D * blockWidth));
        if (blocksPerLine % 2 == 1) {
            blocksPerLine--;
        }
        final int startX = ResolutionUtil.current().getScaledWidth() / 2 - (blocksPerLine * blockWidth / 2);
        int x = -1;
        int y = 0;
        hovered = null;
        for (AbstractHypixelStats field : fields) {
            DynamicTexture dynamicTexture = logos.get(field);
            x++;
            if (x > blocksPerLine) {
                x = 0;
                y++;
            }
            if (dynamicTexture != null) {
                int y1 = 100 + y * blockWidth - 10 - offset;
                if (y1 < 70)
                    continue;
                GlStateManager.pushMatrix();
                GlStateManager.resetColor();
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                int y2 = 100 + y * blockWidth - offset;
                int x1 = startX + x * blockWidth;
                GuiBlock value = new GuiBlock(x1, x1 + blockWidth / 2, y2, y2 + blockWidth / 2);
                if (value.isMouseOver(mouseX, mouseY)) {
                    hovered = field;
                }
                location.put(field, value);
                GlStateManager.translate(x1, y2, 0);
                GlStateManager.bindTexture(dynamicTexture.getGlTextureId());
                GlStateManager.scale(.2, .2, .2);
                drawTexturedModalRect(0, 0, 0, 0, 128 * 2, 128 * 2);
                GlStateManager.popMatrix();
                GlStateManager.pushMatrix();
                GlStateManager.translate(startX + x * blockWidth + 24, y1, 0);
                drawScaledText(field.getName(), 0, 0, 1.0, Color.RED.getRGB(), true, true);
                GlStateManager.popMatrix();
            }
        }
        if (hovered != null) {
            List<StatsDisplayItem> preview = hovered.getPreview(player);
            int width = 0;
            int height = 0;
            for (StatsDisplayItem statsDisplayItem : preview) {
                width = Math.max(width, statsDisplayItem.width);
                height += statsDisplayItem.height;
            }
            GuiBlock block = location.get(hovered);
            int xOffset = 0;
            int yRenderOffset = 16;
            int rightSide = block.getRight() + (width + yRenderOffset) * 2;
            if (rightSide > current.getScaledWidth()) {
                xOffset = rightSide - current.getScaledWidth();
            }
            float scale = 1.0F;
            GlStateManager.scale(scale, scale, scale);
            int left = block.getRight() - xOffset + yRenderOffset - 8;
            int top = block.getTop();
            int printY = 0;
            if (top + height * 2 > current.getScaledHeight()) {
                top = current.getScaledHeight() - height * 2 - 50;
            }
            RenderUtils.drawRect((left - 3) / scale, (top - 3) / scale, (left + (width + 3) * scale) / scale, (top + (height + 3) * scale) / scale, new Color(0, 0, 0, 220).getRGB());
            for (StatsDisplayItem statsDisplayItem : preview) {
                statsDisplayItem.draw((int) (left / scale), (int) ((top) / scale) + printY);
                printY += statsDisplayItem.height;
            }
            GlStateManager.scale(1 / scale, 1 / scale, 1 / scale);
        }
    } else {
        DynamicTexture dynamicTexture = logos.get(focused);
        GlStateManager.resetColor();
        GlStateManager.pushMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.bindTexture(dynamicTexture.getGlTextureId());
        GlStateManager.translate((current.getScaledWidth() >> 1) - 24, 80, 0);
        GlStateManager.scale(.2, .2, .2);
        drawTexturedModalRect(0, 0, 0, 0, 128 * 2, 128 * 2);
        GlStateManager.popMatrix();
        GlStateManager.pushMatrix();
        drawScaledText(focused.getName(), current.getScaledWidth() / 2, 60, 2.0, Color.RED.getRGB(), true, true);
        Icons.EXTENSION.bind();
        GlStateModifier.INSTANCE.reset();
        Icons.EXIT.bind();
        float scale = 2.0F;
        GlStateManager.scale(scale, scale, scale);
        GlStateManager.translate(current.getScaledWidth() / 2F / scale - 90 / scale, (73) / scale, 0);
        GlStateManager.rotate(180, 0.0F, 0.0F, 1.0F);
        GlStateManager.translate(-16, -16, 0);
        drawScaledCustomSizeModalRect(0, 0, 0, 0, 64, 64, 16, 16, 64, 64);
        GlStateManager.popMatrix();
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) HypixelApiGuild(club.sk1er.website.api.requests.HypixelApiGuild) StatsDisplayItem(cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) GuiBlock(cc.hyperium.gui.GuiBlock)

Example 8 with DynamicTexture

use of net.minecraft.client.renderer.texture.DynamicTexture in project Hyperium by HyperiumClient.

the class GuiHyperiumCredits method fetch.

private static void fetch(int tries) {
    try {
        String content = IOUtils.toString(URI.create("https://api.github.com/repos/HyperiumClient/Hyperium/stats/contributors"), StandardCharsets.UTF_8);
        JsonParser parser = new JsonParser();
        JsonArray a = parser.parse(content).getAsJsonArray();
        StreamSupport.stream(a.spliterator(), false).map(JsonElement::getAsJsonObject).filter(o -> o.has("total") & o.get("total").getAsInt() > 20).sorted(Comparator.comparingLong(o -> ((JsonObject) o).get("total").getAsInt()).reversed()).forEach(o -> {
            JsonObject con = o.get("author").getAsJsonObject();
            try {
                BufferedImage bi = ImageIO.read(new URL(con.get("avatar_url").getAsString() + "&size=64"));
                Minecraft.getMinecraft().addScheduledTask(() -> {
                    DynamicTexture tx = new DynamicTexture(bi);
                    try {
                        tx.loadTexture(Minecraft.getMinecraft().getResourceManager());
                        contributors.put(con.get("login").getAsString(), tx);
                        commits.put(con.get("login").getAsString(), o.get("total").getAsInt());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }).get();
            } catch (IOException | InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        if (tries < 5)
            fetch(tries + 1);
        else
            err = e.getMessage();
    }
}
Also used : DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) HashMap(java.util.HashMap) Keyboard(org.lwjgl.input.Keyboard) JsonParser(com.google.gson.JsonParser) JsonElement(com.google.gson.JsonElement) LinkedHashMap(java.util.LinkedHashMap) Minecraft(net.minecraft.client.Minecraft) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Multithreading(cc.hyperium.mods.sk1ercommon.Multithreading) ImageIO(javax.imageio.ImageIO) StreamSupport(java.util.stream.StreamSupport) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) GlStateManager(net.minecraft.client.renderer.GlStateManager) IOException(java.io.IOException) Mouse(org.lwjgl.input.Mouse) StandardCharsets(java.nio.charset.StandardCharsets) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) JsonArray(com.google.gson.JsonArray) GuiScreen(net.minecraft.client.gui.GuiScreen) FontRenderer(net.minecraft.client.gui.FontRenderer) Comparator(java.util.Comparator) JsonObject(com.google.gson.JsonObject) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JsonArray(com.google.gson.JsonArray) ExecutionException(java.util.concurrent.ExecutionException) JsonParser(com.google.gson.JsonParser)

Aggregations

DynamicTexture (net.minecraft.client.renderer.texture.DynamicTexture)8 IOException (java.io.IOException)4 BufferedImage (java.awt.image.BufferedImage)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 Minecraft (net.minecraft.client.Minecraft)2 ScaledResolution (net.minecraft.client.gui.ScaledResolution)2 TextureManager (net.minecraft.client.renderer.texture.TextureManager)2 GuiBlock (cc.hyperium.gui.GuiBlock)1 StatsDisplayItem (cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem)1 Multithreading (cc.hyperium.mods.sk1ercommon.Multithreading)1 NettyClient (cc.hyperium.netty.NettyClient)1 JsonHolder (cc.hyperium.utils.JsonHolder)1 HypixelApiGuild (club.sk1er.website.api.requests.HypixelApiGuild)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1