package kihira.tails.client.render;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import kihira.tails.client.FakeEntity;
import kihira.tails.client.PartRegistry;
import kihira.tails.common.PartInfo;
import kihira.tails.common.PartsData;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.item.TinyPotatoRenderEvent;

public class FoxtatoRender {

    private FoxtatoFakeEntity fakeEntity;
    private PartInfo tailPartInfo = new PartInfo(true, 0, 0, 0, new int[]{-5480951, -6594259, -5197647}, PartsData.PartType.TAIL, null);
    private PartInfo earPartInfo = new PartInfo(true, 0, 0, 0, new int[]{-5480951, 0xFF000000, -5197647}, PartsData.PartType.EARS, null);

    @SubscribeEvent
    public void onWorldLoad(WorldEvent.Load e) {
        fakeEntity = new FoxtatoFakeEntity(Minecraft.getMinecraft().theWorld);
    }

    @SubscribeEvent
    public void onWorldUnload(WorldEvent.Unload e) {
        fakeEntity.setDead();
        fakeEntity = null;
    }

    @SubscribeEvent
    public void onPotatoRender(TinyPotatoRenderEvent e) {
        if (e.name.equalsIgnoreCase("foxtato")) {
            RenderPart foxTailRender = PartRegistry.getRenderPart(PartsData.PartType.TAIL, 0);
            RenderPart foxEarRender = PartRegistry.getRenderPart(PartsData.PartType.EARS, 0);

            foxTailRender.render(fakeEntity, tailPartInfo, e.x, e.y, e.z, e.partTicks);
            foxEarRender.render(fakeEntity, earPartInfo, e.x, e.y, e.z, e.partTicks);
            GL11.glColor3f(1f, 0f, 1f);
        }
    }

    public static class FoxtatoFakeEntity extends FakeEntity {
        public FoxtatoFakeEntity(World world) {
            super(world);
        }
    }
}

@@ -840,17 +840,19 @@
  onWorld
-L
+Unl
 oad(Worl
@@ -858,17 +858,19 @@
 ldEvent.
-L
+Unl
 oad e) %7B
@@ -870,32 +870,36 @@
 ad e) %7B%0A        
+if (
 fakeEntity = new
@@ -897,148 +897,23 @@
 ity 
+!
 = n
-ew FoxtatoFakeEntity(Minecraft.getMinecraft().theWorld);%0A    %7D%0A%0A    @SubscribeEvent%0A    public void onWorldUnload(WorldEvent.Unload e) %7B%0A
+ull) %7B%0A    
     
@@ -938,16 +938,20 @@
 Dead();%0A
+    
         
@@ -969,16 +969,26 @@
 = null;%0A
+        %7D%0A
     %7D%0A%0A 
@@ -1110,24 +1110,163 @@
 oxtato%22)) %7B%0A
+            if (fakeEntity == null) %7B%0A                fakeEntity = new FoxtatoFakeEntity(Minecraft.getMinecraft().theWorld);%0A            %7D%0A
             

Fix crash with foxtato when switching worlds