package tehnut.lib.util;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tehnut.lib.LendingLibrary;

import java.lang.reflect.Field;

@SideOnly(Side.CLIENT)
public class RenderHelper {

    public static boolean addPlayerLayerRenderer(Class<? extends LayerRenderer<?>> layerRendererClass) {
        RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
        try {
            Field renderPlayerField = RenderManager.class.getDeclaredField("playerRenderer");
            renderPlayerField.setAccessible(true);
            Object renderPlayerObj = renderPlayerField.get(renderManager);
            if (renderPlayerObj instanceof RenderPlayer) {
                RenderPlayer renderPlayer = (RenderPlayer) renderPlayerObj;
                LayerRenderer<?> layerRenderer = layerRendererClass.getConstructor(RenderPlayer.class).newInstance(renderPlayer);
                renderPlayer.addLayer(layerRenderer);
                return true;
            }
        } catch (Exception e) {
            LendingLibrary.getLogger().error(e.getLocalizedMessage());
        }

        return false;
    }
}

@@ -237,24 +237,90 @@
 erRenderer;%0A
+import net.minecraftforge.fml.common.ObfuscationReflectionHelper;%0A
 import net.m
@@ -354,16 +354,16 @@
 r.Side;%0A
-
 import n
@@ -444,41 +444,8 @@
 y;%0A%0A
-import java.lang.reflect.Field;%0A%0A
 @Sid
@@ -710,355 +710,153 @@
     
-Field renderPlayerField = RenderManager.class.getDeclaredField(%22playerRenderer%22);%0A            renderPlayerField.setAccessible(true);%0A            Object renderPlayerObj = renderPlayerField.get(renderManager);%0A            if (renderPlayerObj instanceof RenderPlayer) %7B%0A                RenderPlayer renderP
+RenderPlayer renderPlayer = ObfuscationReflectionHelper.getPrivateValue(RenderManager.class, renderManager, %22p
 layer
- = (
 Render
-Player) renderPlayerObj;%0A    
+er%22, %22field_178637_m%22);%0A
     
@@ -989,20 +989,16 @@
         
-    
 renderPl
@@ -1035,28 +1035,24 @@
             
-    
 return true;
@@ -1056,22 +1056,8 @@
 ue;%0A
-            %7D%0A
     

Fix render layer adder in obf environments