Search in sources :

Example 1 with ThreadDownloadImageData

use of net.minecraft.client.renderer.ThreadDownloadImageData in project Armourers-Workshop by RiskyKen.

the class PlayerTextureDownloader method getDownloadImageSkin.

private ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocation, String textureString, PlayerTexture playerTexture, TextureType textureType) {
    TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
    Object object = texturemanager.getTexture(resourceLocation);
    if (object == null) {
        object = new ModThreadDownloadImageData((File) null, textureString, AbstractClientPlayer.locationStevePng, new ImageBufferDownload(), playerTexture);
        texturemanager.loadTexture(resourceLocation, (ITextureObject) object);
    }
    return (ThreadDownloadImageData) object;
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) ImageBufferDownload(net.minecraft.client.renderer.ImageBufferDownload) ITextureObject(net.minecraft.client.renderer.texture.ITextureObject) File(java.io.File) ThreadDownloadImageData(net.minecraft.client.renderer.ThreadDownloadImageData)

Example 2 with ThreadDownloadImageData

use of net.minecraft.client.renderer.ThreadDownloadImageData in project Armourers-Workshop by RiskyKen.

the class PlayerTextureDownloader method downloadTexture.

private void downloadTexture(String textureString, PlayerTexture playerTexture, TextureType textureType) {
    ResourceLocation resourceLocation = null;
    if (StringUtils.isNullOrEmpty(textureString)) {
        return;
    }
    if (textureType == TextureType.URL) {
        resourceLocation = new ResourceLocation("skins/" + StringUtils.stripControlCodes(textureString));
        ThreadDownloadImageData imageData = getDownloadImageSkin(resourceLocation, textureString, playerTexture, textureType);
    } else {
        ModLogger.log("Setting wrong " + textureString);
    // resourceLocation = new ResourceLocation(LibModInfo.ID.toLowerCase(), StringUtils.stripControlCodes(textureString));
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ThreadDownloadImageData(net.minecraft.client.renderer.ThreadDownloadImageData)

Example 3 with ThreadDownloadImageData

use of net.minecraft.client.renderer.ThreadDownloadImageData in project Armourers-Workshop by RiskyKen.

the class SkinHelper method getBufferedImageSkin.

/*
     * Based on @KitsuneKihira texture helper class.
     * https://github.com/kihira/FoxLib/blob/2946cd6033d3039151064ceccfb8d38612d0af02/src/main/scala/kihira/foxlib/client/TextureHelper.scala#L28
     */
public static BufferedImage getBufferedImageSkin(AbstractClientPlayer player) {
    BufferedImage bufferedImage = null;
    ResourceLocation skinloc = AbstractClientPlayer.locationStevePng;
    InputStream inputStream = null;
    Minecraft mc = Minecraft.getMinecraft();
    skinloc = player.getLocationSkin();
    try {
        ITextureObject skintex = mc.getTextureManager().getTexture(skinloc);
        if (skintex instanceof ThreadDownloadImageData) {
            ThreadDownloadImageData imageData = (ThreadDownloadImageData) skintex;
            bufferedImage = ObfuscationReflectionHelper.getPrivateValue(ThreadDownloadImageData.class, imageData, "bufferedImage", "field_110560_d", "bpr.h");
        } else {
            inputStream = Minecraft.getMinecraft().getResourceManager().getResource(skinloc).getInputStream();
            bufferedImage = ImageIO.read(inputStream);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    return bufferedImage;
}
Also used : ITextureObject(net.minecraft.client.renderer.texture.ITextureObject) InputStream(java.io.InputStream) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Minecraft(net.minecraft.client.Minecraft) BufferedImage(java.awt.image.BufferedImage) ThreadDownloadImageData(net.minecraft.client.renderer.ThreadDownloadImageData)

Example 4 with ThreadDownloadImageData

use of net.minecraft.client.renderer.ThreadDownloadImageData in project ArsMagica2 by Mithion.

the class CloakUtils method downloadCapeTexture.

private static ThreadDownloadImageData downloadCapeTexture(ResourceLocation resourceLocation, String uuid) {
    ThreadDownloadImageData data = downloadedCloaks.get(uuid);
    if (data == null) {
        TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
        Object object = new ThreadDownloadImageData((File) null, AMCore.proxy.playerTracker.getCLF(uuid), null, null);
        texturemanager.loadTexture(resourceLocation, (ITextureObject) object);
        data = (ThreadDownloadImageData) object;
        downloadedCloaks.put(uuid, data);
    }
    return data;
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) ITextureObject(net.minecraft.client.renderer.texture.ITextureObject) ThreadDownloadImageData(net.minecraft.client.renderer.ThreadDownloadImageData)

Example 5 with ThreadDownloadImageData

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

the class MemoryHelper method worldEvent.

@InvokeEvent
public void worldEvent(WorldUnloadEvent event) {
    try {
        TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
        Map<ResourceLocation, ITextureObject> mapTextureObjects = ((IMixinTextureManager) textureManager).getMapTextureObjects();
        List<ResourceLocation> removes = new ArrayList<>();
        mapTextureObjects.forEach((key, iTextureObject) -> {
            if (iTextureObject instanceof ThreadDownloadImageData) {
                IImageBuffer imageBuffer = ((IMixinThreadDownloadImageData) iTextureObject).getImageBuffer();
                if (imageBuffer == null)
                    return;
                Class<? extends IImageBuffer> aClass = imageBuffer.getClass();
                // Optifine
                if (aClass.getName().equalsIgnoreCase("CapeImageBuffer")) {
                    removes.add(key);
                }
            }
        });
        removes.forEach(this::deleteSkin);
        // locations.forEach(this::deleteSkin);
        int size = locations.size();
        locations.clear();
        int del = 0;
        RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
        try {
            Method getSkinMap = renderManager.getClass().getMethod("getSkinMap");
            Object invoke = getSkinMap.invoke(renderManager);
            Map<String, RenderPlayer> skinMap = (Map<String, RenderPlayer>) invoke;
            for (RenderPlayer value : skinMap.values()) {
                ModelPlayer mainModel = value.getMainModel();
                Class<?> superClass = mainModel.getClass().getSuperclass();
                for (Field field : superClass.getDeclaredFields()) {
                    field.setAccessible(true);
                    try {
                        Object o = field.get(mainModel);
                        if (o != null) {
                            try {
                                Field entityIn = o.getClass().getSuperclass().getDeclaredField("entityIn");
                                entityIn.setAccessible(true);
                                Object o1 = entityIn.get(o);
                                if (o1 != null) {
                                    entityIn.set(o, null);
                                    del++;
                                }
                            } catch (IllegalAccessException | NoSuchFieldException ignored) {
                            }
                            try {
                                Field clientPlayer = o.getClass().getSuperclass().getDeclaredField("clientPlayer");
                                clientPlayer.setAccessible(true);
                                Object o1 = clientPlayer.get(o);
                                if (o1 != null) {
                                    clientPlayer.set(o, null);
                                    del++;
                                }
                            } catch (IllegalAccessException | NoSuchFieldException ignored) {
                            }
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        Hyperium.LOGGER.info("Deleted " + (removes.size() + size + del) + " cosmetic items / skins");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IMixinThreadDownloadImageData(cc.hyperium.mixins.client.renderer.IMixinThreadDownloadImageData) ArrayList(java.util.ArrayList) IMixinThreadDownloadImageData(cc.hyperium.mixins.client.renderer.IMixinThreadDownloadImageData) ThreadDownloadImageData(net.minecraft.client.renderer.ThreadDownloadImageData) Field(java.lang.reflect.Field) ResourceLocation(net.minecraft.util.ResourceLocation) RenderPlayer(net.minecraft.client.renderer.entity.RenderPlayer) IMixinTextureManager(cc.hyperium.mixins.client.renderer.texture.IMixinTextureManager) RenderManager(net.minecraft.client.renderer.entity.RenderManager) ITextureObject(net.minecraft.client.renderer.texture.ITextureObject) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) IMixinTextureManager(cc.hyperium.mixins.client.renderer.texture.IMixinTextureManager) ModelPlayer(net.minecraft.client.model.ModelPlayer) IImageBuffer(net.minecraft.client.renderer.IImageBuffer) ITextureObject(net.minecraft.client.renderer.texture.ITextureObject) Map(java.util.Map) InvokeEvent(cc.hyperium.event.InvokeEvent)

Aggregations

ThreadDownloadImageData (net.minecraft.client.renderer.ThreadDownloadImageData)13 ITextureObject (net.minecraft.client.renderer.texture.ITextureObject)9 IOException (java.io.IOException)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 BufferedImage (java.awt.image.BufferedImage)5 InputStream (java.io.InputStream)5 TextureManager (net.minecraft.client.renderer.texture.TextureManager)5 Minecraft (net.minecraft.client.Minecraft)3 File (java.io.File)2 Map (java.util.Map)2 InvokeEvent (cc.hyperium.event.InvokeEvent)1 IMixinThreadDownloadImageData (cc.hyperium.mixins.client.renderer.IMixinThreadDownloadImageData)1 IMixinTextureManager (cc.hyperium.mixins.client.renderer.texture.IMixinTextureManager)1 MinecraftProfileTexture (com.mojang.authlib.minecraft.MinecraftProfileTexture)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ModelPlayer (net.minecraft.client.model.ModelPlayer)1 IImageBuffer (net.minecraft.client.renderer.IImageBuffer)1