Search in sources :

Example 1 with IMixinThreadDownloadImageData

use of cc.hyperium.mixins.client.renderer.IMixinThreadDownloadImageData 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

InvokeEvent (cc.hyperium.event.InvokeEvent)1 IMixinThreadDownloadImageData (cc.hyperium.mixins.client.renderer.IMixinThreadDownloadImageData)1 IMixinTextureManager (cc.hyperium.mixins.client.renderer.texture.IMixinTextureManager)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ModelPlayer (net.minecraft.client.model.ModelPlayer)1 IImageBuffer (net.minecraft.client.renderer.IImageBuffer)1 ThreadDownloadImageData (net.minecraft.client.renderer.ThreadDownloadImageData)1 RenderManager (net.minecraft.client.renderer.entity.RenderManager)1 RenderPlayer (net.minecraft.client.renderer.entity.RenderPlayer)1 ITextureObject (net.minecraft.client.renderer.texture.ITextureObject)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 ResourceLocation (net.minecraft.util.ResourceLocation)1