package net.minecraft.client.renderer;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockEnderChest;
import net.minecraft.block.BlockSign;
import net.minecraft.block.BlockSkull;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.client.renderer.chunk.CompiledChunk;
import net.minecraft.client.renderer.chunk.IRenderChunkFactory;
import net.minecraft.client.renderer.chunk.ListChunkFactory;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.client.renderer.chunk.VboChunkFactory;
import net.minecraft.client.renderer.chunk.VisGraph;
import net.minecraft.client.renderer.culling.ClippingHelper;
import net.minecraft.client.renderer.culling.ClippingHelperImpl;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.culling.ICamera;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.client.shader.ShaderGroup;
import net.minecraft.client.shader.ShaderLinkHelper;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityWitherSkull;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemRecord;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraft.world.IWorldAccess;
import net.minecraft.world.border.WorldBorder;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
public class RenderGlobal implements IWorldAccess, IResourceManagerReloadListener
{
    private static final Logger logger = LogManager.getLogger();
    private static final ResourceLocation locationMoonPhasesPng = new ResourceLocation("textures/environment/moon_phases.png");
    private static final ResourceLocation locationSunPng = new ResourceLocation("textures/environment/sun.png");
    private static final ResourceLocation locationCloudsPng = new ResourceLocation("textures/environment/clouds.png");
    private static final ResourceLocation locationEndSkyPng = new ResourceLocation("textures/environment/end_sky.png");
    private static final ResourceLocation field_175006_g = new ResourceLocation("textures/misc/forcefield.png");
    /** A reference to the Minecraft object. */
    private final Minecraft mc;
    /** The RenderEngine instance used by RenderGlobal */
    private final TextureManager renderEngine;
    private final RenderManager field_175010_j;
    private WorldClient theWorld;
    private Set field_175009_l = Sets.newLinkedHashSet();
    /** List of OpenGL lists for the current render pass */
    private List glRenderLists = Lists.newArrayListWithCapacity(69696);
    private ViewFrustum field_175008_n;
    /** The star GL Call list */
    private int starGLCallList = -1;
    /** OpenGL sky list */
    private int glSkyList = -1;
    /** OpenGL sky list 2 */
    private int glSkyList2 = -1;
    private VertexFormat field_175014_r;
    private VertexBuffer field_175013_s;
    private VertexBuffer field_175012_t;
    private VertexBuffer field_175011_u;
    /** counts the cloud render updates. Used with mod to stagger some updates */
    private int cloudTickCounter;
    /**
     * Stores blocks currently being broken. Key is entity ID of the thing doing the breaking. Value is a
     * DestroyBlockProgress
     */
    private final Map damagedBlocks = Maps.newHashMap();
    /** Currently playing sounds.  Type:  HashMap<ChunkCoordinates, ISound> */
    private final Map mapSoundPositions = Maps.newHashMap();
    private final TextureAtlasSprite[] destroyBlockIcons = new TextureAtlasSprite[10];
    private Framebuffer field_175015_z;
    private ShaderGroup field_174991_A;
    private double field_174992_B = Double.MIN_VALUE;
    private double field_174993_C = Double.MIN_VALUE;
    private double field_174987_D = Double.MIN_VALUE;
    private int field_174988_E = Integer.MIN_VALUE;
    private int field_174989_F = Integer.MIN_VALUE;
    private int field_174990_G = Integer.MIN_VALUE;
    private double field_174997_H = Double.MIN_VALUE;
    private double field_174998_I = Double.MIN_VALUE;
    private double field_174999_J = Double.MIN_VALUE;
    private double field_175000_K = Double.MIN_VALUE;
    private double field_174994_L = Double.MIN_VALUE;
    private final ChunkRenderDispatcher field_174995_M = new ChunkRenderDispatcher();
    private ChunkRenderContainer field_174996_N;
    private int renderDistanceChunks = -1;
    /** Render entities startup counter (init value=2) */
    private int renderEntitiesStartupCounter = 2;
    /** Count entities total */
    private int countEntitiesTotal;
    /** Count entities rendered */
    private int countEntitiesRendered;
    /** Count entities hidden */
    private int countEntitiesHidden;
    private boolean field_175002_T = false;
    private ClippingHelper field_175001_U;
    private final Vector4f[] field_175004_V = new Vector4f[8];
    private final Vector3d field_175003_W = new Vector3d();
    private boolean field_175005_X = false;
    IRenderChunkFactory field_175007_a;
    private double prevRenderSortX;
    private double prevRenderSortY;
    private double prevRenderSortZ;
    private boolean displayListEntitiesDirty = true;
    private static final String __OBFID = "CL_00000954";

    public RenderGlobal(Minecraft mcIn)
    {
        this.mc = mcIn;
        this.field_175010_j = mcIn.getRenderManager();
        this.renderEngine = mcIn.getTextureManager();
        this.renderEngine.bindTexture(field_175006_g);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
        GlStateManager.func_179144_i(0);
        this.func_174971_n();
        this.field_175005_X = OpenGlHelper.func_176075_f();

        if (this.field_175005_X)
        {
            this.field_174996_N = new VboRenderList();
            this.field_175007_a = new VboChunkFactory();
        }
        else
        {
            this.field_174996_N = new RenderList();
            this.field_175007_a = new ListChunkFactory();
        }

        this.field_175014_r = new VertexFormat();
        this.field_175014_r.func_177349_a(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.POSITION, 3));
        this.func_174963_q();
        this.func_174980_p();
        this.func_174964_o();
    }

    public void onResourceManagerReload(IResourceManager p_110549_1_)
    {
        this.func_174971_n();
    }

    private void func_174971_n()
    {
        TextureMap texturemap = this.mc.getTextureMapBlocks();

        for (int i = 0; i < this.destroyBlockIcons.length; ++i)
        {
            this.destroyBlockIcons[i] = texturemap.getAtlasSprite("minecraft:blocks/destroy_stage_" + i);
        }
    }

    public void func_174966_b()
    {
        if (OpenGlHelper.shadersSupported)
        {
            if (ShaderLinkHelper.getStaticShaderLinkHelper() == null)
            {
                ShaderLinkHelper.setNewStaticShaderLinkHelper();
            }

            ResourceLocation resourcelocation = new ResourceLocation("shaders/post/entity_outline.json");

            try
            {
                this.field_174991_A = new ShaderGroup(this.mc.getTextureManager(), this.mc.getResourceManager(), this.mc.getFramebuffer(), resourcelocation);
                this.field_174991_A.createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
                this.field_175015_z = this.field_174991_A.func_177066_a("final");
            }
            catch (IOException ioexception)
            {
                logger.warn("Failed to load shader: " + resourcelocation, ioexception);
                this.field_174991_A = null;
                this.field_175015_z = null;
            }
            catch (JsonSyntaxException jsonsyntaxexception)
            {
                logger.warn("Failed to load shader: " + resourcelocation, jsonsyntaxexception);
                this.field_174991_A = null;
                this.field_175015_z = null;
            }
        }
        else
        {
            this.field_174991_A = null;
            this.field_175015_z = null;
        }
    }

    public void func_174975_c()
    {
        if (this.func_174985_d())
        {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 771, 0, 1);
            this.field_175015_z.func_178038_a(this.mc.displayWidth, this.mc.displayHeight, false);
            GlStateManager.disableBlend();
        }
    }

    protected boolean func_174985_d()
    {
        return this.field_175015_z != null && this.field_174991_A != null && this.mc.thePlayer != null && this.mc.thePlayer.isSpectator() && this.mc.gameSettings.field_178883_an.getIsKeyPressed();
    }

    private void func_174964_o()
    {
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        if (this.field_175011_u != null)
        {
            this.field_175011_u.func_177362_c();
        }

        if (this.glSkyList2 >= 0)
        {
            GLAllocation.deleteDisplayLists(this.glSkyList2);
            this.glSkyList2 = -1;
        }

        if (this.field_175005_X)
        {
            this.field_175011_u = new VertexBuffer(this.field_175014_r);
            this.func_174968_a(worldrenderer, -16.0F, true);
            worldrenderer.draw();
            worldrenderer.reset();
            this.field_175011_u.func_177360_a(worldrenderer.func_178966_f(), worldrenderer.func_178976_e());
        }
        else
        {
            this.glSkyList2 = GLAllocation.generateDisplayLists(1);
            GL11.glNewList(this.glSkyList2, GL11.GL_COMPILE);
            this.func_174968_a(worldrenderer, -16.0F, true);
            tessellator.draw();
            GL11.glEndList();
        }
    }

    private void func_174980_p()
    {
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        if (this.field_175012_t != null)
        {
            this.field_175012_t.func_177362_c();
        }

        if (this.glSkyList >= 0)
        {
            GLAllocation.deleteDisplayLists(this.glSkyList);
            this.glSkyList = -1;
        }

        if (this.field_175005_X)
        {
            this.field_175012_t = new VertexBuffer(this.field_175014_r);
            this.func_174968_a(worldrenderer, 16.0F, false);
            worldrenderer.draw();
            worldrenderer.reset();
            this.field_175012_t.func_177360_a(worldrenderer.func_178966_f(), worldrenderer.func_178976_e());
        }
        else
        {
            this.glSkyList = GLAllocation.generateDisplayLists(1);
            GL11.glNewList(this.glSkyList, GL11.GL_COMPILE);
            this.func_174968_a(worldrenderer, 16.0F, false);
            tessellator.draw();
            GL11.glEndList();
        }
    }

    private void func_174968_a(WorldRenderer p_174968_1_, float p_174968_2_, boolean p_174968_3_)
    {
        boolean flag1 = true;
        boolean flag2 = true;
        p_174968_1_.startDrawingQuads();

        for (int i = -384; i <= 384; i += 64)
        {
            for (int j = -384; j <= 384; j += 64)
            {
                float f1 = (float)i;
                float f2 = (float)(i + 64);

                if (p_174968_3_)
                {
                    f2 = (float)i;
                    f1 = (float)(i + 64);
                }

                p_174968_1_.addVertex((double)f1, (double)p_174968_2_, (double)j);
                p_174968_1_.addVertex((double)f2, (double)p_174968_2_, (double)j);
                p_174968_1_.addVertex((double)f2, (double)p_174968_2_, (double)(j + 64));
                p_174968_1_.addVertex((double)f1, (double)p_174968_2_, (double)(j + 64));
            }
        }
    }

    private void func_174963_q()
    {
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        if (this.field_175013_s != null)
        {
            this.field_175013_s.func_177362_c();
        }

        if (this.starGLCallList >= 0)
        {
            GLAllocation.deleteDisplayLists(this.starGLCallList);
            this.starGLCallList = -1;
        }

        if (this.field_175005_X)
        {
            this.field_175013_s = new VertexBuffer(this.field_175014_r);
            this.func_180444_a(worldrenderer);
            worldrenderer.draw();
            worldrenderer.reset();
            this.field_175013_s.func_177360_a(worldrenderer.func_178966_f(), worldrenderer.func_178976_e());
        }
        else
        {
            this.starGLCallList = GLAllocation.generateDisplayLists(1);
            GlStateManager.pushMatrix();
            GL11.glNewList(this.starGLCallList, GL11.GL_COMPILE);
            this.func_180444_a(worldrenderer);
            tessellator.draw();
            GL11.glEndList();
            GlStateManager.popMatrix();
        }
    }

    private void func_180444_a(WorldRenderer p_180444_1_)
    {
        Random random = new Random(10842L);
        p_180444_1_.startDrawingQuads();

        for (int i = 0; i < 1500; ++i)
        {
            double d0 = (double)(random.nextFloat() * 2.0F - 1.0F);
            double d1 = (double)(random.nextFloat() * 2.0F - 1.0F);
            double d2 = (double)(random.nextFloat() * 2.0F - 1.0F);
            double d3 = (double)(0.15F + random.nextFloat() * 0.1F);
            double d4 = d0 * d0 + d1 * d1 + d2 * d2;

            if (d4 < 1.0D && d4 > 0.01D)
            {
                d4 = 1.0D / Math.sqrt(d4);
                d0 *= d4;
                d1 *= d4;
                d2 *= d4;
                double d5 = d0 * 100.0D;
                double d6 = d1 * 100.0D;
                double d7 = d2 * 100.0D;
                double d8 = Math.atan2(d0, d2);
                double d9 = Math.sin(d8);
                double d10 = Math.cos(d8);
                double d11 = Math.atan2(Math.sqrt(d0 * d0 + d2 * d2), d1);
                double d12 = Math.sin(d11);
                double d13 = Math.cos(d11);
                double d14 = random.nextDouble() * Math.PI * 2.0D;
                double d15 = Math.sin(d14);
                double d16 = Math.cos(d14);

                for (int j = 0; j < 4; ++j)
                {
                    double d17 = 0.0D;
                    double d18 = (double)((j & 2) - 1) * d3;
                    double d19 = (double)((j + 1 & 2) - 1) * d3;
                    double d20 = 0.0D;
                    double d21 = d18 * d16 - d19 * d15;
                    double d22 = d19 * d16 + d18 * d15;
                    double d23 = d21 * d12 + 0.0D * d13;
                    double d24 = 0.0D * d12 - d21 * d13;
                    double d25 = d24 * d9 - d22 * d10;
                    double d26 = d22 * d9 + d24 * d10;
                    p_180444_1_.addVertex(d5 + d25, d6 + d23, d7 + d26);
                }
            }
        }
    }

    /**
     * set null to clear
     */
    public void setWorldAndLoadRenderers(WorldClient p_72732_1_)
    {
        if (this.theWorld != null)
        {
            this.theWorld.removeWorldAccess(this);
        }

        this.field_174992_B = Double.MIN_VALUE;
        this.field_174993_C = Double.MIN_VALUE;
        this.field_174987_D = Double.MIN_VALUE;
        this.field_174988_E = Integer.MIN_VALUE;
        this.field_174989_F = Integer.MIN_VALUE;
        this.field_174990_G = Integer.MIN_VALUE;
        this.field_175010_j.set(p_72732_1_);
        this.theWorld = p_72732_1_;

        if (p_72732_1_ != null)
        {
            p_72732_1_.addWorldAccess(this);
            this.loadRenderers();
        }
    }

    /**
     * Loads all the renderers and sets up the basic settings usage
     */
    public void loadRenderers()
    {
        if (this.theWorld != null)
        {
            this.displayListEntitiesDirty = true;
            Blocks.leaves.setGraphicsLevel(this.mc.gameSettings.fancyGraphics);
            Blocks.leaves2.setGraphicsLevel(this.mc.gameSettings.fancyGraphics);
            this.renderDistanceChunks = this.mc.gameSettings.renderDistanceChunks;
            boolean flag = this.field_175005_X;
            this.field_175005_X = OpenGlHelper.func_176075_f();

            if (flag && !this.field_175005_X)
            {
                this.field_174996_N = new RenderList();
                this.field_175007_a = new ListChunkFactory();
            }
            else if (!flag && this.field_175005_X)
            {
                this.field_174996_N = new VboRenderList();
                this.field_175007_a = new VboChunkFactory();
            }

            if (flag != this.field_175005_X)
            {
                this.func_174963_q();
                this.func_174980_p();
                this.func_174964_o();
            }

            if (this.field_175008_n != null)
            {
                this.field_175008_n.func_178160_a();
            }

            this.func_174986_e();
            this.field_175008_n = new ViewFrustum(this.theWorld, this.mc.gameSettings.renderDistanceChunks, this, this.field_175007_a);

            if (this.theWorld != null)
            {
                Entity entity = this.mc.getRenderViewEntity();

                if (entity != null)
                {
                    this.field_175008_n.func_178163_a(entity.posX, entity.posZ);
                }
            }

            this.renderEntitiesStartupCounter = 2;
        }
    }

    protected void func_174986_e()
    {
        this.field_175009_l.clear();
        this.field_174995_M.func_178514_b();
    }

    public void checkOcclusionQueryResult(int p_72720_1_, int p_72720_2_)
    {
        if (OpenGlHelper.shadersSupported)
        {
            if (this.field_174991_A != null)
            {
                this.field_174991_A.createBindFramebuffers(p_72720_1_, p_72720_2_);
            }
        }
    }

    public void func_180446_a(Entity p_180446_1_, ICamera p_180446_2_, float p_180446_3_)
    {
        int pass = net.minecraftforge.client.MinecraftForgeClient.getRenderPass();
        if (this.renderEntitiesStartupCounter > 0)
        {
            if (pass > 0) return;
            --this.renderEntitiesStartupCounter;
        }
        else
        {
            double d0 = p_180446_1_.prevPosX + (p_180446_1_.posX - p_180446_1_.prevPosX) * (double)p_180446_3_;
            double d1 = p_180446_1_.prevPosY + (p_180446_1_.posY - p_180446_1_.prevPosY) * (double)p_180446_3_;
            double d2 = p_180446_1_.prevPosZ + (p_180446_1_.posZ - p_180446_1_.prevPosZ) * (double)p_180446_3_;
            this.theWorld.theProfiler.startSection("prepare");
            TileEntityRendererDispatcher.instance.func_178470_a(this.theWorld, this.mc.getTextureManager(), this.mc.fontRendererObj, this.mc.getRenderViewEntity(), p_180446_3_);
            this.field_175010_j.func_180597_a(this.theWorld, this.mc.fontRendererObj, this.mc.getRenderViewEntity(), this.mc.pointedEntity, this.mc.gameSettings, p_180446_3_);
            if (pass == 0) // no indentation to shrink patch
            {
            this.countEntitiesTotal = 0;
            this.countEntitiesRendered = 0;
            this.countEntitiesHidden = 0;
            }
            Entity entity1 = this.mc.getRenderViewEntity();
            double d3 = entity1.lastTickPosX + (entity1.posX - entity1.lastTickPosX) * (double)p_180446_3_;
            double d4 = entity1.lastTickPosY + (entity1.posY - entity1.lastTickPosY) * (double)p_180446_3_;
            double d5 = entity1.lastTickPosZ + (entity1.posZ - entity1.lastTickPosZ) * (double)p_180446_3_;
            TileEntityRendererDispatcher.staticPlayerX = d3;
            TileEntityRendererDispatcher.staticPlayerY = d4;
            TileEntityRendererDispatcher.staticPlayerZ = d5;
            this.field_175010_j.func_178628_a(d3, d4, d5);
            this.mc.entityRenderer.enableLightmap();
            this.theWorld.theProfiler.endStartSection("global");
            List list = this.theWorld.getLoadedEntityList();
            if (pass == 0) // no indentation to shrink patch
            {
            this.countEntitiesTotal = list.size();
            }
            int i;
            Entity entity2;

            for (i = 0; i < this.theWorld.weatherEffects.size(); ++i)
            {
                entity2 = (Entity)this.theWorld.weatherEffects.get(i);
                if (!entity2.shouldRenderInPass(pass)) continue;
                ++this.countEntitiesRendered;

                if (entity2.isInRangeToRender3d(d0, d1, d2))
                {
                    this.field_175010_j.renderEntitySimple(entity2, p_180446_3_);
                }
            }

            if (this.func_174985_d())
            {
                GlStateManager.depthFunc(519);
                GlStateManager.disableFog();
                this.field_175015_z.framebufferClear();
                this.field_175015_z.bindFramebuffer(false);
                this.theWorld.theProfiler.endStartSection("entityOutlines");
                RenderHelper.disableStandardItemLighting();
                this.field_175010_j.func_178632_c(true);

                for (i = 0; i < list.size(); ++i)
                {
                    entity2 = (Entity)list.get(i);
                    if (!entity2.shouldRenderInPass(pass)) continue;
                    boolean flag = this.mc.getRenderViewEntity() instanceof EntityLivingBase && ((EntityLivingBase)this.mc.getRenderViewEntity()).isPlayerSleeping();
                    boolean flag1 = entity2.isInRangeToRender3d(d0, d1, d2) && (entity2.ignoreFrustumCheck || p_180446_2_.isBoundingBoxInFrustum(entity2.getEntityBoundingBox()) || entity2.riddenByEntity == this.mc.thePlayer) && entity2 instanceof EntityPlayer;

                    if ((entity2 != this.mc.getRenderViewEntity() || this.mc.gameSettings.thirdPersonView != 0 || flag) && flag1)
                    {
                        this.field_175010_j.renderEntitySimple(entity2, p_180446_3_);
                    }
                }

                this.field_175010_j.func_178632_c(false);
                RenderHelper.enableStandardItemLighting();
                GlStateManager.depthMask(false);
                this.field_174991_A.loadShaderGroup(p_180446_3_);
                GlStateManager.depthMask(true);
                this.mc.getFramebuffer().bindFramebuffer(false);
                GlStateManager.enableFog();
                GlStateManager.depthFunc(515);
                GlStateManager.enableDepth();
                GlStateManager.enableAlpha();
            }

            this.theWorld.theProfiler.endStartSection("entities");
            Iterator iterator = this.glRenderLists.iterator();
            RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation;

            while (iterator.hasNext())
            {
                containerlocalrenderinformation = (RenderGlobal.ContainerLocalRenderInformation)iterator.next();
                Chunk chunk = this.theWorld.getChunkFromBlockCoords(containerlocalrenderinformation.field_178036_a.func_178568_j());
                Iterator iterator2 = chunk.getEntityLists()[containerlocalrenderinformation.field_178036_a.func_178568_j().getY() / 16].iterator();

                while (iterator2.hasNext())
                {
                    Entity entity3 = (Entity)iterator2.next();
                    if (!entity3.shouldRenderInPass(pass)) continue;
                    boolean flag2 = this.field_175010_j.func_178635_a(entity3, p_180446_2_, d0, d1, d2) || entity3.riddenByEntity == this.mc.thePlayer;

                    if (flag2)
                    {
                        boolean flag3 = this.mc.getRenderViewEntity() instanceof EntityLivingBase ? ((EntityLivingBase)this.mc.getRenderViewEntity()).isPlayerSleeping() : false;

                        if (entity3 == this.mc.getRenderViewEntity() && this.mc.gameSettings.thirdPersonView == 0 && !flag3 || entity3.posY >= 0.0D && entity3.posY < 256.0D && !this.theWorld.isBlockLoaded(new BlockPos(entity3)))
                        {
                            continue;
                        }

                        ++this.countEntitiesRendered;
                        this.field_175010_j.renderEntitySimple(entity3, p_180446_3_);
                    }

                    if (!flag2 && entity3 instanceof EntityWitherSkull)
                    {
                        this.mc.getRenderManager().func_178630_b(entity3, p_180446_3_);
                    }
                }
            }

            this.theWorld.theProfiler.endStartSection("blockentities");
            RenderHelper.enableStandardItemLighting();
            iterator = this.glRenderLists.iterator();
            TileEntity tileentity;

            while (iterator.hasNext())
            {
                containerlocalrenderinformation = (RenderGlobal.ContainerLocalRenderInformation)iterator.next();
                Iterator iterator1 = containerlocalrenderinformation.field_178036_a.func_178571_g().func_178485_b().iterator();

                while (iterator1.hasNext())
                {
                    tileentity = (TileEntity)iterator1.next();
                    if (!tileentity.shouldRenderInPass(pass) || !p_180446_2_.isBoundingBoxInFrustum(tileentity.getRenderBoundingBox())) continue;
                    TileEntityRendererDispatcher.instance.func_180546_a(tileentity, p_180446_3_, -1);
                }
            }

            this.func_180443_s();
            iterator = this.damagedBlocks.values().iterator();

            while (iterator.hasNext())
            {
                DestroyBlockProgress destroyblockprogress = (DestroyBlockProgress)iterator.next();
                BlockPos blockpos = destroyblockprogress.func_180246_b();
                tileentity = this.theWorld.getTileEntity(blockpos);

                if (tileentity instanceof TileEntityChest)
                {
                    TileEntityChest tileentitychest = (TileEntityChest)tileentity;

                    if (tileentitychest.adjacentChestXNeg != null)
                    {
                        blockpos = blockpos.offset(EnumFacing.WEST);
                        tileentity = this.theWorld.getTileEntity(blockpos);
                    }
                    else if (tileentitychest.adjacentChestZNeg != null)
                    {
                        blockpos = blockpos.offset(EnumFacing.NORTH);
                        tileentity = this.theWorld.getTileEntity(blockpos);
                    }
                }

                Block block = this.theWorld.getBlockState(blockpos).getBlock();

                if (tileentity != null && tileentity.shouldRenderInPass(pass) && tileentity.canRenderBreaking() && p_180446_2_.isBoundingBoxInFrustum(tileentity.getRenderBoundingBox()))
                {
                    TileEntityRendererDispatcher.instance.func_180546_a(tileentity, p_180446_3_, destroyblockprogress.getPartialBlockDamage());
                }
            }

            this.func_174969_t();
            this.mc.entityRenderer.func_175072_h();
            this.mc.mcProfiler.endSection();
        }
    }

    /**
     * Gets the render info for use on the Debug screen
     */
    public String getDebugInfoRenders()
    {
        int i = this.field_175008_n.field_178164_f.length;
        int j = 0;
        Iterator iterator = this.glRenderLists.iterator();

        while (iterator.hasNext())
        {
            RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation = (RenderGlobal.ContainerLocalRenderInformation)iterator.next();
            CompiledChunk compiledchunk = containerlocalrenderinformation.field_178036_a.field_178590_b;

            if (compiledchunk != CompiledChunk.field_178502_a && !compiledchunk.func_178489_a())
            {
                ++j;
            }
        }

        return String.format("C: %d/%d %sD: %d, %s", new Object[] {Integer.valueOf(j), Integer.valueOf(i), this.mc.field_175612_E ? "(s) " : "", Integer.valueOf(this.renderDistanceChunks), this.field_174995_M.func_178504_a()});
    }

    /**
     * Gets the entities info for use on the Debug screen
     */
    public String getDebugInfoEntities()
    {
        return "E: " + this.countEntitiesRendered + "/" + this.countEntitiesTotal + ", B: " + this.countEntitiesHidden + ", I: " + (this.countEntitiesTotal - this.countEntitiesHidden - this.countEntitiesRendered);
    }

    public void func_174970_a(Entity p_174970_1_, double p_174970_2_, ICamera p_174970_4_, int p_174970_5_, boolean p_174970_6_)
    {
        if (this.mc.gameSettings.renderDistanceChunks != this.renderDistanceChunks)
        {
            this.loadRenderers();
        }

        this.theWorld.theProfiler.startSection("camera");
        double d1 = p_174970_1_.posX - this.field_174992_B;
        double d2 = p_174970_1_.posY - this.field_174993_C;
        double d3 = p_174970_1_.posZ - this.field_174987_D;

        if (this.field_174988_E != p_174970_1_.chunkCoordX || this.field_174989_F != p_174970_1_.chunkCoordY || this.field_174990_G != p_174970_1_.chunkCoordZ || d1 * d1 + d2 * d2 + d3 * d3 > 16.0D)
        {
            this.field_174992_B = p_174970_1_.posX;
            this.field_174993_C = p_174970_1_.posY;
            this.field_174987_D = p_174970_1_.posZ;
            this.field_174988_E = p_174970_1_.chunkCoordX;
            this.field_174989_F = p_174970_1_.chunkCoordY;
            this.field_174990_G = p_174970_1_.chunkCoordZ;
            this.field_175008_n.func_178163_a(p_174970_1_.posX, p_174970_1_.posZ);
        }

        this.theWorld.theProfiler.endStartSection("renderlistcamera");
        double d4 = p_174970_1_.lastTickPosX + (p_174970_1_.posX - p_174970_1_.lastTickPosX) * p_174970_2_;
        double d5 = p_174970_1_.lastTickPosY + (p_174970_1_.posY - p_174970_1_.lastTickPosY) * p_174970_2_;
        double d6 = p_174970_1_.lastTickPosZ + (p_174970_1_.posZ - p_174970_1_.lastTickPosZ) * p_174970_2_;
        this.field_174996_N.func_178004_a(d4, d5, d6);
        this.theWorld.theProfiler.endStartSection("cull");

        if (this.field_175001_U != null)
        {
            Frustum frustum = new Frustum(this.field_175001_U);
            frustum.setPosition(this.field_175003_W.x, this.field_175003_W.y, this.field_175003_W.z);
            p_174970_4_ = frustum;
        }

        this.mc.mcProfiler.endStartSection("culling");
        BlockPos blockpos1 = new BlockPos(d4, d5 + (double)p_174970_1_.getEyeHeight(), d6);
        RenderChunk renderchunk = this.field_175008_n.func_178161_a(blockpos1);
        BlockPos blockpos = new BlockPos(MathHelper.floor_double(d4) / 16 * 16, MathHelper.floor_double(d5) / 16 * 16, MathHelper.floor_double(d6) / 16 * 16);
        this.displayListEntitiesDirty = this.displayListEntitiesDirty || !this.field_175009_l.isEmpty() || p_174970_1_.posX != this.field_174997_H || p_174970_1_.posY != this.field_174998_I || p_174970_1_.posZ != this.field_174999_J || (double)p_174970_1_.rotationPitch != this.field_175000_K || (double)p_174970_1_.rotationYaw != this.field_174994_L;
        this.field_174997_H = p_174970_1_.posX;
        this.field_174998_I = p_174970_1_.posY;
        this.field_174999_J = p_174970_1_.posZ;
        this.field_175000_K = (double)p_174970_1_.rotationPitch;
        this.field_174994_L = (double)p_174970_1_.rotationYaw;
        boolean flag1 = this.field_175001_U != null;
        RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation1;
        RenderChunk renderchunk3;

        if (!flag1 && this.displayListEntitiesDirty)
        {
            this.displayListEntitiesDirty = false;
            this.glRenderLists = Lists.newArrayList();
            LinkedList linkedlist = Lists.newLinkedList();
            boolean flag2 = this.mc.field_175612_E;

            if (renderchunk == null)
            {
                int j = blockpos1.getY() > 0 ? 248 : 8;

                for (int k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k)
                {
                    for (int l = -this.renderDistanceChunks; l <= this.renderDistanceChunks; ++l)
                    {
                        RenderChunk renderchunk1 = this.field_175008_n.func_178161_a(new BlockPos((k << 4) + 8, j, (l << 4) + 8));

                        if (renderchunk1 != null && ((ICamera)p_174970_4_).isBoundingBoxInFrustum(renderchunk1.field_178591_c))
                        {
                            renderchunk1.func_178577_a(p_174970_5_);
                            linkedlist.add(new RenderGlobal.ContainerLocalRenderInformation(renderchunk1, (EnumFacing)null, 0, null));
                        }
                    }
                }
            }
            else
            {
                boolean flag3 = false;
                RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation2 = new RenderGlobal.ContainerLocalRenderInformation(renderchunk, (EnumFacing)null, 0, null);
                Set set1 = this.func_174978_c(blockpos1);

                if (!set1.isEmpty() && set1.size() == 1)
                {
                    Vector3f vector3f = this.func_174962_a(p_174970_1_, p_174970_2_);
                    EnumFacing enumfacing = EnumFacing.func_176737_a(vector3f.x, vector3f.y, vector3f.z).getOpposite();
                    set1.remove(enumfacing);
                }

                if (set1.isEmpty())
                {
                    flag3 = true;
                }

                if (flag3 && !p_174970_6_)
                {
                    this.glRenderLists.add(containerlocalrenderinformation2);
                }
                else
                {
                    if (p_174970_6_ && this.theWorld.getBlockState(blockpos1).getBlock().isOpaqueCube())
                    {
                        flag2 = false;
                    }

                    renderchunk.func_178577_a(p_174970_5_);
                    linkedlist.add(containerlocalrenderinformation2);
                }
            }

            while (!linkedlist.isEmpty())
            {
                containerlocalrenderinformation1 = (RenderGlobal.ContainerLocalRenderInformation)linkedlist.poll();
                renderchunk3 = containerlocalrenderinformation1.field_178036_a;
                EnumFacing enumfacing2 = containerlocalrenderinformation1.field_178034_b;
                BlockPos blockpos2 = renderchunk3.func_178568_j();
                this.glRenderLists.add(containerlocalrenderinformation1);
                EnumFacing[] aenumfacing = EnumFacing.values();
                int i1 = aenumfacing.length;

                for (int j1 = 0; j1 < i1; ++j1)
                {
                    EnumFacing enumfacing1 = aenumfacing[j1];
                    RenderChunk renderchunk2 = this.func_174973_a(blockpos1, blockpos2, enumfacing1);

                    if ((!flag2 || !containerlocalrenderinformation1.field_178035_c.contains(enumfacing1.getOpposite())) && (!flag2 || enumfacing2 == null || renderchunk3.func_178571_g().func_178495_a(enumfacing2.getOpposite(), enumfacing1)) && renderchunk2 != null && renderchunk2.func_178577_a(p_174970_5_) && ((ICamera)p_174970_4_).isBoundingBoxInFrustum(renderchunk2.field_178591_c))
                    {
                        RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation = new RenderGlobal.ContainerLocalRenderInformation(renderchunk2, enumfacing1, containerlocalrenderinformation1.field_178032_d + 1, null);
                        containerlocalrenderinformation.field_178035_c.addAll(containerlocalrenderinformation1.field_178035_c);
                        containerlocalrenderinformation.field_178035_c.add(enumfacing1);
                        linkedlist.add(containerlocalrenderinformation);
                    }
                }
            }
        }

        if (this.field_175002_T)
        {
            this.func_174984_a(d4, d5, d6);
            this.field_175002_T = false;
        }

        this.field_174995_M.func_178513_e();
        Set set = this.field_175009_l;
        this.field_175009_l = Sets.newLinkedHashSet();
        Iterator iterator = this.glRenderLists.iterator();

        while (iterator.hasNext())
        {
            containerlocalrenderinformation1 = (RenderGlobal.ContainerLocalRenderInformation)iterator.next();
            renderchunk3 = containerlocalrenderinformation1.field_178036_a;

            if (renderchunk3.func_178569_m() || renderchunk3.func_178583_l() || set.contains(renderchunk3))
            {
                this.displayListEntitiesDirty = true;

                if (this.func_174983_a(blockpos, containerlocalrenderinformation1.field_178036_a))
                {
                    this.mc.mcProfiler.startSection("build near");
                    this.field_174995_M.func_178505_b(renderchunk3);
                    renderchunk3.func_178575_a(false);
                    this.mc.mcProfiler.endSection();
                }
                else
                {
                    this.field_175009_l.add(renderchunk3);
                }
            }
        }

        this.field_175009_l.addAll(set);
        this.mc.mcProfiler.endSection();
    }

    private boolean func_174983_a(BlockPos p_174983_1_, RenderChunk p_174983_2_)
    {
        BlockPos blockpos1 = p_174983_2_.func_178568_j();
        return MathHelper.abs_int(p_174983_1_.getX() - blockpos1.getX()) > 16 ? false : (MathHelper.abs_int(p_174983_1_.getY() - blockpos1.getY()) > 16 ? false : MathHelper.abs_int(p_174983_1_.getZ() - blockpos1.getZ()) <= 16);
    }

    private Set func_174978_c(BlockPos p_174978_1_)
    {
        VisGraph visgraph = new VisGraph();
        BlockPos blockpos1 = new BlockPos(p_174978_1_.getX() >> 4 << 4, p_174978_1_.getY() >> 4 << 4, p_174978_1_.getZ() >> 4 << 4);
        Chunk chunk = this.theWorld.getChunkFromBlockCoords(blockpos1);
        Iterator iterator = BlockPos.getAllInBoxMutable(blockpos1, blockpos1.add(15, 15, 15)).iterator();

        while (iterator.hasNext())
        {
            BlockPos.MutableBlockPos mutableblockpos = (BlockPos.MutableBlockPos)iterator.next();

            if (chunk.getBlock(mutableblockpos).isOpaqueCube())
            {
                visgraph.func_178606_a(mutableblockpos);
            }
        }

        return visgraph.func_178609_b(p_174978_1_);
    }

    private RenderChunk func_174973_a(BlockPos p_174973_1_, BlockPos p_174973_2_, EnumFacing p_174973_3_)
    {
        BlockPos blockpos2 = p_174973_2_.offset(p_174973_3_, 16);
        return MathHelper.abs_int(p_174973_1_.getX() - blockpos2.getX()) > this.renderDistanceChunks * 16 ? null : (blockpos2.getY() >= 0 && blockpos2.getY() < 256 ? (MathHelper.abs_int(p_174973_1_.getZ() - blockpos2.getZ()) > this.renderDistanceChunks * 16 ? null : this.field_175008_n.func_178161_a(blockpos2)) : null);
    }

    private void func_174984_a(double p_174984_1_, double p_174984_3_, double p_174984_5_)
    {
        this.field_175001_U = new ClippingHelperImpl();
        ((ClippingHelperImpl)this.field_175001_U).init();
        Matrix4f matrix4f = new Matrix4f(this.field_175001_U.modelviewMatrix);
        matrix4f.transpose();
        Matrix4f matrix4f1 = new Matrix4f(this.field_175001_U.projectionMatrix);
        matrix4f1.transpose();
        Matrix4f matrix4f2 = new Matrix4f();
        matrix4f2.mul(matrix4f1, matrix4f);
        matrix4f2.invert();
        this.field_175003_W.x = p_174984_1_;
        this.field_175003_W.y = p_174984_3_;
        this.field_175003_W.z = p_174984_5_;
        this.field_175004_V[0] = new Vector4f(-1.0F, -1.0F, -1.0F, 1.0F);
        this.field_175004_V[1] = new Vector4f(1.0F, -1.0F, -1.0F, 1.0F);
        this.field_175004_V[2] = new Vector4f(1.0F, 1.0F, -1.0F, 1.0F);
        this.field_175004_V[3] = new Vector4f(-1.0F, 1.0F, -1.0F, 1.0F);
        this.field_175004_V[4] = new Vector4f(-1.0F, -1.0F, 1.0F, 1.0F);
        this.field_175004_V[5] = new Vector4f(1.0F, -1.0F, 1.0F, 1.0F);
        this.field_175004_V[6] = new Vector4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.field_175004_V[7] = new Vector4f(-1.0F, 1.0F, 1.0F, 1.0F);

        for (int i = 0; i < 8; ++i)
        {
            matrix4f2.transform(this.field_175004_V[i]);
            this.field_175004_V[i].x /= this.field_175004_V[i].w;
            this.field_175004_V[i].y /= this.field_175004_V[i].w;
            this.field_175004_V[i].z /= this.field_175004_V[i].w;
            this.field_175004_V[i].w = 1.0F;
        }
    }

    protected Vector3f func_174962_a(Entity p_174962_1_, double p_174962_2_)
    {
        float f = (float)((double)p_174962_1_.prevRotationPitch + (double)(p_174962_1_.rotationPitch - p_174962_1_.prevRotationPitch) * p_174962_2_);
        float f1 = (float)((double)p_174962_1_.prevRotationYaw + (double)(p_174962_1_.rotationYaw - p_174962_1_.prevRotationYaw) * p_174962_2_);

        if (Minecraft.getMinecraft().gameSettings.thirdPersonView == 2)
        {
            f += 180.0F;
        }

        float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
        float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
        float f4 = -MathHelper.cos(-f * 0.017453292F);
        float f5 = MathHelper.sin(-f * 0.017453292F);
        return new Vector3f(f3 * f4, f5, f2 * f4);
    }

    public int func_174977_a(EnumWorldBlockLayer p_174977_1_, double p_174977_2_, int p_174977_4_, Entity p_174977_5_)
    {
        RenderHelper.disableStandardItemLighting();

        if (p_174977_1_ == EnumWorldBlockLayer.TRANSLUCENT)
        {
            this.mc.mcProfiler.startSection("translucent_sort");
            double d1 = p_174977_5_.posX - this.prevRenderSortX;
            double d2 = p_174977_5_.posY - this.prevRenderSortY;
            double d3 = p_174977_5_.posZ - this.prevRenderSortZ;

            if (d1 * d1 + d2 * d2 + d3 * d3 > 1.0D)
            {
                this.prevRenderSortX = p_174977_5_.posX;
                this.prevRenderSortY = p_174977_5_.posY;
                this.prevRenderSortZ = p_174977_5_.posZ;
                int l = 0;
                Iterator iterator = this.glRenderLists.iterator();

                while (iterator.hasNext())
                {
                    RenderGlobal.ContainerLocalRenderInformation containerlocalrenderinformation = (RenderGlobal.ContainerLocalRenderInformation)iterator.next();

                    if (containerlocalrenderinformation.field_178036_a.field_178590_b.func_178492_d(p_174977_1_) && l++ < 15)
                    {
                        this.field_174995_M.func_178509_c(containerlocalrenderinformation.field_178036_a);
                    }
                }
            }

            this.mc.mcProfiler.endSection();
        }

        this.mc.mcProfiler.startSection("filterempty");
        int i1 = 0;
        boolean flag = p_174977_1_ == EnumWorldBlockLayer.TRANSLUCENT;
        int j1 = flag ? this.glRenderLists.size() - 1 : 0;
        int j = flag ? -1 : this.glRenderLists.size();
        int k1 = flag ? -1 : 1;

        for (int k = j1; k != j; k += k1)
        {
            RenderChunk renderchunk = ((RenderGlobal.ContainerLocalRenderInformation)this.glRenderLists.get(k)).field_178036_a;

            if (!renderchunk.func_178571_g().func_178491_b(p_174977_1_))
            {
                ++i1;
                this.field_174996_N.func_178002_a(renderchunk, p_174977_1_);
            }
        }

        this.mc.mcProfiler.endStartSection("render_" + p_174977_1_);
        this.func_174982_a(p_174977_1_);
        this.mc.mcProfiler.endSection();
        return i1;
    }

    private void func_174982_a(EnumWorldBlockLayer p_174982_1_)
    {
        this.mc.entityRenderer.enableLightmap();

        if (OpenGlHelper.func_176075_f())
        {
            GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
            GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
            GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
            OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
            GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        }

        this.field_174996_N.func_178001_a(p_174982_1_);

        if (OpenGlHelper.func_176075_f())
        {
            List list = DefaultVertexFormats.field_176600_a.func_177343_g();
            Iterator iterator = list.iterator();

            while (iterator.hasNext())
            {
                VertexFormatElement vertexformatelement = (VertexFormatElement)iterator.next();
                VertexFormatElement.EnumUsage enumusage = vertexformatelement.func_177375_c();
                int i = vertexformatelement.func_177369_e();

                switch (RenderGlobal.SwitchEnumUsage.field_178037_a[enumusage.ordinal()])
                {
                    case 1:
                        GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
                        break;
                    case 2:
                        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit + i);
                        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
                        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
                        break;
                    case 3:
                        GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
                        GlStateManager.func_179117_G();
                }
            }
        }

        this.mc.entityRenderer.func_175072_h();
    }

    private void func_174965_a(Iterator p_174965_1_)
    {
        while (p_174965_1_.hasNext())
        {
            DestroyBlockProgress destroyblockprogress = (DestroyBlockProgress)p_174965_1_.next();
            int i = destroyblockprogress.getCreationCloudUpdateTick();

            if (this.cloudTickCounter - i > 400)
            {
                p_174965_1_.remove();
            }
        }
    }

    public void updateClouds()
    {
        ++this.cloudTickCounter;

        if (this.cloudTickCounter % 20 == 0)
        {
            this.func_174965_a(this.damagedBlocks.values().iterator());
        }
    }

    private void func_180448_r()
    {
        GlStateManager.disableFog();
        GlStateManager.disableAlpha();
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        RenderHelper.disableStandardItemLighting();
        GlStateManager.depthMask(false);
        this.renderEngine.bindTexture(locationEndSkyPng);
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        for (int i = 0; i < 6; ++i)
        {
            GlStateManager.pushMatrix();

            if (i == 1)
            {
                GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
            }

            if (i == 2)
            {
                GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
            }

            if (i == 3)
            {
                GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
            }

            if (i == 4)
            {
                GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
            }

            if (i == 5)
            {
                GlStateManager.rotate(-90.0F, 0.0F, 0.0F, 1.0F);
            }

            worldrenderer.startDrawingQuads();
            worldrenderer.func_178991_c(2631720);
            worldrenderer.addVertexWithUV(-100.0D, -100.0D, -100.0D, 0.0D, 0.0D);
            worldrenderer.addVertexWithUV(-100.0D, -100.0D, 100.0D, 0.0D, 16.0D);
            worldrenderer.addVertexWithUV(100.0D, -100.0D, 100.0D, 16.0D, 16.0D);
            worldrenderer.addVertexWithUV(100.0D, -100.0D, -100.0D, 16.0D, 0.0D);
            tessellator.draw();
            GlStateManager.popMatrix();
        }

        GlStateManager.depthMask(true);
        GlStateManager.func_179098_w();
        GlStateManager.enableAlpha();
    }

    public void func_174976_a(float p_174976_1_, int p_174976_2_)
    {
        net.minecraftforge.client.IRenderHandler renderer = this.theWorld.provider.getSkyRenderer();
        if (renderer != null)
        {
            renderer.render(p_174976_1_, theWorld, mc);
            return;
        }
        if (this.mc.theWorld.provider.getDimensionId() == 1)
        {
            this.func_180448_r();
        }
        else if (this.mc.theWorld.provider.isSurfaceWorld())
        {
            GlStateManager.func_179090_x();
            Vec3 vec3 = this.theWorld.getSkyColor(this.mc.getRenderViewEntity(), p_174976_1_);
            float f1 = (float)vec3.xCoord;
            float f2 = (float)vec3.yCoord;
            float f3 = (float)vec3.zCoord;

            if (p_174976_2_ != 2)
            {
                float f4 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F;
                float f5 = (f1 * 30.0F + f2 * 70.0F) / 100.0F;
                float f6 = (f1 * 30.0F + f3 * 70.0F) / 100.0F;
                f1 = f4;
                f2 = f5;
                f3 = f6;
            }

            GlStateManager.color(f1, f2, f3);
            Tessellator tessellator = Tessellator.getInstance();
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
            GlStateManager.depthMask(false);
            GlStateManager.enableFog();
            GlStateManager.color(f1, f2, f3);

            if (this.field_175005_X)
            {
                this.field_175012_t.func_177359_a();
                GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
                GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0L);
                this.field_175012_t.func_177358_a(7);
                this.field_175012_t.func_177361_b();
                GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
            }
            else
            {
                GlStateManager.callList(this.glSkyList);
            }

            GlStateManager.disableFog();
            GlStateManager.disableAlpha();
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
            RenderHelper.disableStandardItemLighting();
            float[] afloat = this.theWorld.provider.calcSunriseSunsetColors(this.theWorld.getCelestialAngle(p_174976_1_), p_174976_1_);
            float f7;
            float f8;
            float f9;
            float f10;
            float f11;

            if (afloat != null)
            {
                GlStateManager.func_179090_x();
                GlStateManager.shadeModel(7425);
                GlStateManager.pushMatrix();
                GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
                GlStateManager.rotate(MathHelper.sin(this.theWorld.getCelestialAngleRadians(p_174976_1_)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F);
                GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
                f7 = afloat[0];
                f8 = afloat[1];
                f9 = afloat[2];
                float f12;

                if (p_174976_2_ != 2)
                {
                    f10 = (f7 * 30.0F + f8 * 59.0F + f9 * 11.0F) / 100.0F;
                    f11 = (f7 * 30.0F + f8 * 70.0F) / 100.0F;
                    f12 = (f7 * 30.0F + f9 * 70.0F) / 100.0F;
                    f7 = f10;
                    f8 = f11;
                    f9 = f12;
                }

                worldrenderer.startDrawing(6);
                worldrenderer.func_178960_a(f7, f8, f9, afloat[3]);
                worldrenderer.addVertex(0.0D, 100.0D, 0.0D);
                boolean flag = true;
                worldrenderer.func_178960_a(afloat[0], afloat[1], afloat[2], 0.0F);

                for (int j = 0; j <= 16; ++j)
                {
                    f12 = (float)j * (float)Math.PI * 2.0F / 16.0F;
                    float f13 = MathHelper.sin(f12);
                    float f14 = MathHelper.cos(f12);
                    worldrenderer.addVertex((double)(f13 * 120.0F), (double)(f14 * 120.0F), (double)(-f14 * 40.0F * afloat[3]));
                }

                tessellator.draw();
                GlStateManager.popMatrix();
                GlStateManager.shadeModel(7424);
            }

            GlStateManager.func_179098_w();
            GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0);
            GlStateManager.pushMatrix();
            f7 = 1.0F - this.theWorld.getRainStrength(p_174976_1_);
            f8 = 0.0F;
            f9 = 0.0F;
            f10 = 0.0F;
            GlStateManager.color(1.0F, 1.0F, 1.0F, f7);
            GlStateManager.translate(0.0F, 0.0F, 0.0F);
            GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(this.theWorld.getCelestialAngle(p_174976_1_) * 360.0F, 1.0F, 0.0F, 0.0F);
            f11 = 30.0F;
            this.renderEngine.bindTexture(locationSunPng);
            worldrenderer.startDrawingQuads();
            worldrenderer.addVertexWithUV((double)(-f11), 100.0D, (double)(-f11), 0.0D, 0.0D);
            worldrenderer.addVertexWithUV((double)f11, 100.0D, (double)(-f11), 1.0D, 0.0D);
            worldrenderer.addVertexWithUV((double)f11, 100.0D, (double)f11, 1.0D, 1.0D);
            worldrenderer.addVertexWithUV((double)(-f11), 100.0D, (double)f11, 0.0D, 1.0D);
            tessellator.draw();
            f11 = 20.0F;
            this.renderEngine.bindTexture(locationMoonPhasesPng);
            int k = this.theWorld.getMoonPhase();
            int l = k % 4;
            int i1 = k / 4 % 2;
            float f15 = (float)(l + 0) / 4.0F;
            float f16 = (float)(i1 + 0) / 2.0F;
            float f17 = (float)(l + 1) / 4.0F;
            float f18 = (float)(i1 + 1) / 2.0F;
            worldrenderer.startDrawingQuads();
            worldrenderer.addVertexWithUV((double)(-f11), -100.0D, (double)f11, (double)f17, (double)f18);
            worldrenderer.addVertexWithUV((double)f11, -100.0D, (double)f11, (double)f15, (double)f18);
            worldrenderer.addVertexWithUV((double)f11, -100.0D, (double)(-f11), (double)f15, (double)f16);
            worldrenderer.addVertexWithUV((double)(-f11), -100.0D, (double)(-f11), (double)f17, (double)f16);
            tessellator.draw();
            GlStateManager.func_179090_x();
            float f19 = this.theWorld.getStarBrightness(p_174976_1_) * f7;

            if (f19 > 0.0F)
            {
                GlStateManager.color(f19, f19, f19, f19);

                if (this.field_175005_X)
                {
                    this.field_175013_s.func_177359_a();
                    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
                    GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0L);
                    this.field_175013_s.func_177358_a(7);
                    this.field_175013_s.func_177361_b();
                    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
                }
                else
                {
                    GlStateManager.callList(this.starGLCallList);
                }
            }

            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            GlStateManager.disableBlend();
            GlStateManager.enableAlpha();
            GlStateManager.enableFog();
            GlStateManager.popMatrix();
            GlStateManager.func_179090_x();
            GlStateManager.color(0.0F, 0.0F, 0.0F);
            double d0 = this.mc.thePlayer.getPositionEyes(p_174976_1_).yCoord - this.theWorld.getHorizon();

            if (d0 < 0.0D)
            {
                GlStateManager.pushMatrix();
                GlStateManager.translate(0.0F, 12.0F, 0.0F);

                if (this.field_175005_X)
                {
                    this.field_175011_u.func_177359_a();
                    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
                    GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0L);
                    this.field_175011_u.func_177358_a(7);
                    this.field_175011_u.func_177361_b();
                    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
                }
                else
                {
                    GlStateManager.callList(this.glSkyList2);
                }

                GlStateManager.popMatrix();
                f9 = 1.0F;
                f10 = -((float)(d0 + 65.0D));
                f11 = -1.0F;
                worldrenderer.startDrawingQuads();
                worldrenderer.func_178974_a(0, 255);
                worldrenderer.addVertex(-1.0D, (double)f10, 1.0D);
                worldrenderer.addVertex(1.0D, (double)f10, 1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, -1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, -1.0D);
                worldrenderer.addVertex(1.0D, (double)f10, -1.0D);
                worldrenderer.addVertex(-1.0D, (double)f10, -1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, -1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(1.0D, (double)f10, 1.0D);
                worldrenderer.addVertex(1.0D, (double)f10, -1.0D);
                worldrenderer.addVertex(-1.0D, (double)f10, -1.0D);
                worldrenderer.addVertex(-1.0D, (double)f10, 1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, -1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, -1.0D);
                worldrenderer.addVertex(-1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, 1.0D);
                worldrenderer.addVertex(1.0D, -1.0D, -1.0D);
                tessellator.draw();
            }

            if (this.theWorld.provider.isSkyColored())
            {
                GlStateManager.color(f1 * 0.2F + 0.04F, f2 * 0.2F + 0.04F, f3 * 0.6F + 0.1F);
            }
            else
            {
                GlStateManager.color(f1, f2, f3);
            }

            GlStateManager.pushMatrix();
            GlStateManager.translate(0.0F, -((float)(d0 - 16.0D)), 0.0F);
            GlStateManager.callList(this.glSkyList2);
            GlStateManager.popMatrix();
            GlStateManager.func_179098_w();
            GlStateManager.depthMask(true);
        }
    }

    public void func_180447_b(float p_180447_1_, int p_180447_2_)
    {
        net.minecraftforge.client.IRenderHandler renderer = this.mc.theWorld.provider.getCloudRenderer();
        if (renderer != null)
        {
            renderer.render(p_180447_1_, this.mc.theWorld, mc);
            return;
        }
        if (this.mc.theWorld.provider.isSurfaceWorld())
        {
            if (this.mc.gameSettings.fancyGraphics)
            {
                this.func_180445_c(p_180447_1_, p_180447_2_);
            }
            else
            {
                GlStateManager.disableCull();
                float f1 = (float)(this.mc.getRenderViewEntity().lastTickPosY + (this.mc.getRenderViewEntity().posY - this.mc.getRenderViewEntity().lastTickPosY) * (double)p_180447_1_);
                boolean flag = true;
                boolean flag1 = true;
                Tessellator tessellator = Tessellator.getInstance();
                WorldRenderer worldrenderer = tessellator.getWorldRenderer();
                this.renderEngine.bindTexture(locationCloudsPng);
                GlStateManager.enableBlend();
                GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
                Vec3 vec3 = this.theWorld.getCloudColour(p_180447_1_);
                float f2 = (float)vec3.xCoord;
                float f3 = (float)vec3.yCoord;
                float f4 = (float)vec3.zCoord;
                float f5;

                if (p_180447_2_ != 2)
                {
                    f5 = (f2 * 30.0F + f3 * 59.0F + f4 * 11.0F) / 100.0F;
                    float f6 = (f2 * 30.0F + f3 * 70.0F) / 100.0F;
                    float f7 = (f2 * 30.0F + f4 * 70.0F) / 100.0F;
                    f2 = f5;
                    f3 = f6;
                    f4 = f7;
                }

                f5 = 4.8828125E-4F;
                double d2 = (double)((float)this.cloudTickCounter + p_180447_1_);
                double d0 = this.mc.getRenderViewEntity().prevPosX + (this.mc.getRenderViewEntity().posX - this.mc.getRenderViewEntity().prevPosX) * (double)p_180447_1_ + d2 * 0.029999999329447746D;
                double d1 = this.mc.getRenderViewEntity().prevPosZ + (this.mc.getRenderViewEntity().posZ - this.mc.getRenderViewEntity().prevPosZ) * (double)p_180447_1_;
                int j = MathHelper.floor_double(d0 / 2048.0D);
                int k = MathHelper.floor_double(d1 / 2048.0D);
                d0 -= (double)(j * 2048);
                d1 -= (double)(k * 2048);
                float f8 = this.theWorld.provider.getCloudHeight() - f1 + 0.33F;
                float f9 = (float)(d0 * 4.8828125E-4D);
                float f10 = (float)(d1 * 4.8828125E-4D);
                worldrenderer.startDrawingQuads();
                worldrenderer.func_178960_a(f2, f3, f4, 0.8F);

                for (int l = -256; l < 256; l += 32)
                {
                    for (int i1 = -256; i1 < 256; i1 += 32)
                    {
                        worldrenderer.addVertexWithUV((double)(l + 0), (double)f8, (double)(i1 + 32), (double)((float)(l + 0) * 4.8828125E-4F + f9), (double)((float)(i1 + 32) * 4.8828125E-4F + f10));
                        worldrenderer.addVertexWithUV((double)(l + 32), (double)f8, (double)(i1 + 32), (double)((float)(l + 32) * 4.8828125E-4F + f9), (double)((float)(i1 + 32) * 4.8828125E-4F + f10));
                        worldrenderer.addVertexWithUV((double)(l + 32), (double)f8, (double)(i1 + 0), (double)((float)(l + 32) * 4.8828125E-4F + f9), (double)((float)(i1 + 0) * 4.8828125E-4F + f10));
                        worldrenderer.addVertexWithUV((double)(l + 0), (double)f8, (double)(i1 + 0), (double)((float)(l + 0) * 4.8828125E-4F + f9), (double)((float)(i1 + 0) * 4.8828125E-4F + f10));
                    }
                }

                tessellator.draw();
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                GlStateManager.disableBlend();
                GlStateManager.enableCull();
            }
        }
    }

    /**
     * Checks if the given position is to be rendered with cloud fog
     */
    public boolean hasCloudFog(double p_72721_1_, double p_72721_3_, double p_72721_5_, float p_72721_7_)
    {
        return false;
    }

    private void func_180445_c(float p_180445_1_, int p_180445_2_)
    {
        GlStateManager.disableCull();
        float f1 = (float)(this.mc.getRenderViewEntity().lastTickPosY + (this.mc.getRenderViewEntity().posY - this.mc.getRenderViewEntity().lastTickPosY) * (double)p_180445_1_);
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        float f2 = 12.0F;
        float f3 = 4.0F;
        double d0 = (double)((float)this.cloudTickCounter + p_180445_1_);
        double d1 = (this.mc.getRenderViewEntity().prevPosX + (this.mc.getRenderViewEntity().posX - this.mc.getRenderViewEntity().prevPosX) * (double)p_180445_1_ + d0 * 0.029999999329447746D) / 12.0D;
        double d2 = (this.mc.getRenderViewEntity().prevPosZ + (this.mc.getRenderViewEntity().posZ - this.mc.getRenderViewEntity().prevPosZ) * (double)p_180445_1_) / 12.0D + 0.33000001311302185D;
        float f4 = this.theWorld.provider.getCloudHeight() - f1 + 0.33F;
        int j = MathHelper.floor_double(d1 / 2048.0D);
        int k = MathHelper.floor_double(d2 / 2048.0D);
        d1 -= (double)(j * 2048);
        d2 -= (double)(k * 2048);
        this.renderEngine.bindTexture(locationCloudsPng);
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        Vec3 vec3 = this.theWorld.getCloudColour(p_180445_1_);
        float f5 = (float)vec3.xCoord;
        float f6 = (float)vec3.yCoord;
        float f7 = (float)vec3.zCoord;
        float f8;
        float f9;
        float f10;

        if (p_180445_2_ != 2)
        {
            f8 = (f5 * 30.0F + f6 * 59.0F + f7 * 11.0F) / 100.0F;
            f9 = (f5 * 30.0F + f6 * 70.0F) / 100.0F;
            f10 = (f5 * 30.0F + f7 * 70.0F) / 100.0F;
            f5 = f8;
            f6 = f9;
            f7 = f10;
        }

        f8 = 0.00390625F;
        f9 = (float)MathHelper.floor_double(d1) * 0.00390625F;
        f10 = (float)MathHelper.floor_double(d2) * 0.00390625F;
        float f11 = (float)(d1 - (double)MathHelper.floor_double(d1));
        float f12 = (float)(d2 - (double)MathHelper.floor_double(d2));
        boolean flag = true;
        boolean flag1 = true;
        float f13 = 9.765625E-4F;
        GlStateManager.scale(12.0F, 1.0F, 12.0F);

        for (int l = 0; l < 2; ++l)
        {
            if (l == 0)
            {
                GlStateManager.colorMask(false, false, false, false);
            }
            else
            {
                switch (p_180445_2_)
                {
                    case 0:
                        GlStateManager.colorMask(false, true, true, true);
                        break;
                    case 1:
                        GlStateManager.colorMask(true, false, false, true);
                        break;
                    case 2:
                        GlStateManager.colorMask(true, true, true, true);
                }
            }

            for (int i1 = -3; i1 <= 4; ++i1)
            {
                for (int j1 = -3; j1 <= 4; ++j1)
                {
                    worldrenderer.startDrawingQuads();
                    float f14 = (float)(i1 * 8);
                    float f15 = (float)(j1 * 8);
                    float f16 = f14 - f11;
                    float f17 = f15 - f12;

                    if (f4 > -5.0F)
                    {
                        worldrenderer.func_178960_a(f5 * 0.7F, f6 * 0.7F, f7 * 0.7F, 0.8F);
                        worldrenderer.func_178980_d(0.0F, -1.0F, 0.0F);
                        worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + 8.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 0.0F), (double)(f17 + 8.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 0.0F), (double)(f17 + 0.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + 0.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                    }

                    if (f4 <= 5.0F)
                    {
                        worldrenderer.func_178960_a(f5, f6, f7, 0.8F);
                        worldrenderer.func_178980_d(0.0F, 1.0F, 0.0F);
                        worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 4.0F - 9.765625E-4F), (double)(f17 + 8.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 4.0F - 9.765625E-4F), (double)(f17 + 8.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 4.0F - 9.765625E-4F), (double)(f17 + 0.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                        worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 4.0F - 9.765625E-4F), (double)(f17 + 0.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                    }

                    worldrenderer.func_178960_a(f5 * 0.9F, f6 * 0.9F, f7 * 0.9F, 0.8F);
                    int k1;

                    if (i1 > -1)
                    {
                        worldrenderer.func_178980_d(-1.0F, 0.0F, 0.0F);

                        for (k1 = 0; k1 < 8; ++k1)
                        {
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + 8.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 0.0F), (double)(f4 + 4.0F), (double)(f17 + 8.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 0.0F), (double)(f4 + 4.0F), (double)(f17 + 0.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + 0.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                        }
                    }

                    if (i1 <= 1)
                    {
                        worldrenderer.func_178980_d(1.0F, 0.0F, 0.0F);

                        for (k1 = 0; k1 < 8; ++k1)
                        {
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 1.0F - 9.765625E-4F), (double)(f4 + 0.0F), (double)(f17 + 8.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 1.0F - 9.765625E-4F), (double)(f4 + 4.0F), (double)(f17 + 8.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 8.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 1.0F - 9.765625E-4F), (double)(f4 + 4.0F), (double)(f17 + 0.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + (float)k1 + 1.0F - 9.765625E-4F), (double)(f4 + 0.0F), (double)(f17 + 0.0F), (double)((f14 + (float)k1 + 0.5F) * 0.00390625F + f9), (double)((f15 + 0.0F) * 0.00390625F + f10));
                        }
                    }

                    worldrenderer.func_178960_a(f5 * 0.8F, f6 * 0.8F, f7 * 0.8F, 0.8F);

                    if (j1 > -1)
                    {
                        worldrenderer.func_178980_d(0.0F, 0.0F, -1.0F);

                        for (k1 = 0; k1 < 8; ++k1)
                        {
                            worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 4.0F), (double)(f17 + (float)k1 + 0.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 4.0F), (double)(f17 + (float)k1 + 0.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 0.0F), (double)(f17 + (float)k1 + 0.0F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + (float)k1 + 0.0F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                        }
                    }

                    if (j1 <= 1)
                    {
                        worldrenderer.func_178980_d(0.0F, 0.0F, 1.0F);

                        for (k1 = 0; k1 < 8; ++k1)
                        {
                            worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 4.0F), (double)(f17 + (float)k1 + 1.0F - 9.765625E-4F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 4.0F), (double)(f17 + (float)k1 + 1.0F - 9.765625E-4F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 8.0F), (double)(f4 + 0.0F), (double)(f17 + (float)k1 + 1.0F - 9.765625E-4F), (double)((f14 + 8.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                            worldrenderer.addVertexWithUV((double)(f16 + 0.0F), (double)(f4 + 0.0F), (double)(f17 + (float)k1 + 1.0F - 9.765625E-4F), (double)((f14 + 0.0F) * 0.00390625F + f9), (double)((f15 + (float)k1 + 0.5F) * 0.00390625F + f10));
                        }
                    }

                    tessellator.draw();
                }
            }
        }

        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableBlend();
        GlStateManager.enableCull();
    }

    public void func_174967_a(long p_174967_1_)
    {
        this.displayListEntitiesDirty |= this.field_174995_M.func_178516_a(p_174967_1_);
        Iterator iterator = this.field_175009_l.iterator();

        while (iterator.hasNext())
        {
            RenderChunk renderchunk = (RenderChunk)iterator.next();

            if (!this.field_174995_M.func_178507_a(renderchunk))
            {
                break;
            }

            renderchunk.func_178575_a(false);
            iterator.remove();
        }
    }

    public void func_180449_a(Entity p_180449_1_, float p_180449_2_)
    {
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        WorldBorder worldborder = this.theWorld.getWorldBorder();
        double d0 = (double)(this.mc.gameSettings.renderDistanceChunks * 16);

        if (p_180449_1_.posX >= worldborder.maxX() - d0 || p_180449_1_.posX <= worldborder.minX() + d0 || p_180449_1_.posZ >= worldborder.maxZ() - d0 || p_180449_1_.posZ <= worldborder.minZ() + d0)
        {
            double d1 = 1.0D - worldborder.getClosestDistance(p_180449_1_) / d0;
            d1 = Math.pow(d1, 4.0D);
            double d2 = p_180449_1_.lastTickPosX + (p_180449_1_.posX - p_180449_1_.lastTickPosX) * (double)p_180449_2_;
            double d3 = p_180449_1_.lastTickPosY + (p_180449_1_.posY - p_180449_1_.lastTickPosY) * (double)p_180449_2_;
            double d4 = p_180449_1_.lastTickPosZ + (p_180449_1_.posZ - p_180449_1_.lastTickPosZ) * (double)p_180449_2_;
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0);
            this.renderEngine.bindTexture(field_175006_g);
            GlStateManager.depthMask(false);
            GlStateManager.pushMatrix();
            int i = worldborder.getStatus().func_177766_a();
            float f1 = (float)(i >> 16 & 255) / 255.0F;
            float f2 = (float)(i >> 8 & 255) / 255.0F;
            float f3 = (float)(i & 255) / 255.0F;
            GlStateManager.color(f1, f2, f3, (float)d1);
            GlStateManager.doPolygonOffset(-3.0F, -3.0F);
            GlStateManager.enablePolygonOffset();
            GlStateManager.alphaFunc(516, 0.1F);
            GlStateManager.enableAlpha();
            GlStateManager.disableCull();
            float f4 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F;
            float f5 = 0.0F;
            float f6 = 0.0F;
            float f7 = 128.0F;
            worldrenderer.startDrawingQuads();
            worldrenderer.setTranslation(-d2, -d3, -d4);
            worldrenderer.markDirty();
            double d5 = Math.max((double)MathHelper.floor_double(d4 - d0), worldborder.minZ());
            double d6 = Math.min((double)MathHelper.ceiling_double_int(d4 + d0), worldborder.maxZ());
            float f8;
            double d7;
            double d8;
            float f9;

            if (d2 > worldborder.maxX() - d0)
            {
                f8 = 0.0F;

                for (d7 = d5; d7 < d6; f8 += 0.5F)
                {
                    d8 = Math.min(1.0D, d6 - d7);
                    f9 = (float)d8 * 0.5F;
                    worldrenderer.addVertexWithUV(worldborder.maxX(), 256.0D, d7, (double)(f4 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(worldborder.maxX(), 256.0D, d7 + d8, (double)(f4 + f9 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(worldborder.maxX(), 0.0D, d7 + d8, (double)(f4 + f9 + f8), (double)(f4 + 128.0F));
                    worldrenderer.addVertexWithUV(worldborder.maxX(), 0.0D, d7, (double)(f4 + f8), (double)(f4 + 128.0F));
                    ++d7;
                }
            }

            if (d2 < worldborder.minX() + d0)
            {
                f8 = 0.0F;

                for (d7 = d5; d7 < d6; f8 += 0.5F)
                {
                    d8 = Math.min(1.0D, d6 - d7);
                    f9 = (float)d8 * 0.5F;
                    worldrenderer.addVertexWithUV(worldborder.minX(), 256.0D, d7, (double)(f4 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(worldborder.minX(), 256.0D, d7 + d8, (double)(f4 + f9 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(worldborder.minX(), 0.0D, d7 + d8, (double)(f4 + f9 + f8), (double)(f4 + 128.0F));
                    worldrenderer.addVertexWithUV(worldborder.minX(), 0.0D, d7, (double)(f4 + f8), (double)(f4 + 128.0F));
                    ++d7;
                }
            }

            d5 = Math.max((double)MathHelper.floor_double(d2 - d0), worldborder.minX());
            d6 = Math.min((double)MathHelper.ceiling_double_int(d2 + d0), worldborder.maxX());

            if (d4 > worldborder.maxZ() - d0)
            {
                f8 = 0.0F;

                for (d7 = d5; d7 < d6; f8 += 0.5F)
                {
                    d8 = Math.min(1.0D, d6 - d7);
                    f9 = (float)d8 * 0.5F;
                    worldrenderer.addVertexWithUV(d7, 256.0D, worldborder.maxZ(), (double)(f4 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(d7 + d8, 256.0D, worldborder.maxZ(), (double)(f4 + f9 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(d7 + d8, 0.0D, worldborder.maxZ(), (double)(f4 + f9 + f8), (double)(f4 + 128.0F));
                    worldrenderer.addVertexWithUV(d7, 0.0D, worldborder.maxZ(), (double)(f4 + f8), (double)(f4 + 128.0F));
                    ++d7;
                }
            }

            if (d4 < worldborder.minZ() + d0)
            {
                f8 = 0.0F;

                for (d7 = d5; d7 < d6; f8 += 0.5F)
                {
                    d8 = Math.min(1.0D, d6 - d7);
                    f9 = (float)d8 * 0.5F;
                    worldrenderer.addVertexWithUV(d7, 256.0D, worldborder.minZ(), (double)(f4 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(d7 + d8, 256.0D, worldborder.minZ(), (double)(f4 + f9 + f8), (double)(f4 + 0.0F));
                    worldrenderer.addVertexWithUV(d7 + d8, 0.0D, worldborder.minZ(), (double)(f4 + f9 + f8), (double)(f4 + 128.0F));
                    worldrenderer.addVertexWithUV(d7, 0.0D, worldborder.minZ(), (double)(f4 + f8), (double)(f4 + 128.0F));
                    ++d7;
                }
            }

            tessellator.draw();
            worldrenderer.setTranslation(0.0D, 0.0D, 0.0D);
            GlStateManager.enableCull();
            GlStateManager.disableAlpha();
            GlStateManager.doPolygonOffset(0.0F, 0.0F);
            GlStateManager.disablePolygonOffset();
            GlStateManager.enableAlpha();
            GlStateManager.disableBlend();
            GlStateManager.popMatrix();
            GlStateManager.depthMask(true);
        }
    }

    private void func_180443_s()
    {
        GlStateManager.tryBlendFuncSeparate(774, 768, 1, 0);
        GlStateManager.enableBlend();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.5F);
        GlStateManager.doPolygonOffset(-3.0F, -3.0F);
        GlStateManager.enablePolygonOffset();
        GlStateManager.alphaFunc(516, 0.1F);
        GlStateManager.enableAlpha();
        GlStateManager.pushMatrix();
    }

    private void func_174969_t()
    {
        GlStateManager.disableAlpha();
        GlStateManager.doPolygonOffset(0.0F, 0.0F);
        GlStateManager.disablePolygonOffset();
        GlStateManager.enableAlpha();
        GlStateManager.depthMask(true);
        GlStateManager.popMatrix();
    }

    public void func_174981_a(Tessellator p_174981_1_, WorldRenderer p_174981_2_, Entity p_174981_3_, float p_174981_4_)
    {
        double d0 = p_174981_3_.lastTickPosX + (p_174981_3_.posX - p_174981_3_.lastTickPosX) * (double)p_174981_4_;
        double d1 = p_174981_3_.lastTickPosY + (p_174981_3_.posY - p_174981_3_.lastTickPosY) * (double)p_174981_4_;
        double d2 = p_174981_3_.lastTickPosZ + (p_174981_3_.posZ - p_174981_3_.lastTickPosZ) * (double)p_174981_4_;

        if (!this.damagedBlocks.isEmpty())
        {
            this.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
            this.func_180443_s();
            p_174981_2_.startDrawingQuads();
            p_174981_2_.setVertexFormat(DefaultVertexFormats.field_176600_a);
            p_174981_2_.setTranslation(-d0, -d1, -d2);
            p_174981_2_.markDirty();
            Iterator iterator = this.damagedBlocks.values().iterator();

            while (iterator.hasNext())
            {
                DestroyBlockProgress destroyblockprogress = (DestroyBlockProgress)iterator.next();
                BlockPos blockpos = destroyblockprogress.func_180246_b();
                double d3 = (double)blockpos.getX() - d0;
                double d4 = (double)blockpos.getY() - d1;
                double d5 = (double)blockpos.getZ() - d2;
                Block block = this.theWorld.getBlockState(blockpos).getBlock();
                TileEntity te = this.theWorld.getTileEntity(blockpos);
                boolean hasBreak = block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockSign || block instanceof BlockSkull;
                if (!hasBreak) hasBreak = te != null && te.canRenderBreaking();

                if (!hasBreak)
                {
                    if (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)
                    {
                        iterator.remove();
                    }
                    else
                    {
                        IBlockState iblockstate = this.theWorld.getBlockState(blockpos);

                        if (iblockstate.getBlock().getMaterial() != Material.air)
                        {
                            int i = destroyblockprogress.getPartialBlockDamage();
                            TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[i];
                            BlockRendererDispatcher blockrendererdispatcher = this.mc.getBlockRendererDispatcher();
                            blockrendererdispatcher.func_175020_a(iblockstate, blockpos, textureatlassprite, this.theWorld);
                        }
                    }
                }
            }

            p_174981_1_.draw();
            p_174981_2_.setTranslation(0.0D, 0.0D, 0.0D);
            this.func_174969_t();
        }
    }

    /**
     * Draws the selection box for the player. Args: entityPlayer, rayTraceHit, i, itemStack, partialTickTime
     */
    public void drawSelectionBox(EntityPlayer p_72731_1_, MovingObjectPosition p_72731_2_, int p_72731_3_, float p_72731_4_)
    {
        if (p_72731_3_ == 0 && p_72731_2_.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
            GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
            GL11.glLineWidth(2.0F);
            GlStateManager.func_179090_x();
            GlStateManager.depthMask(false);
            float f1 = 0.002F;
            BlockPos blockpos = p_72731_2_.func_178782_a();
            Block block = this.theWorld.getBlockState(blockpos).getBlock();

            if (block.getMaterial() != Material.air && this.theWorld.getWorldBorder().contains(blockpos))
            {
                block.setBlockBoundsBasedOnState(this.theWorld, blockpos);
                double d0 = p_72731_1_.lastTickPosX + (p_72731_1_.posX - p_72731_1_.lastTickPosX) * (double)p_72731_4_;
                double d1 = p_72731_1_.lastTickPosY + (p_72731_1_.posY - p_72731_1_.lastTickPosY) * (double)p_72731_4_;
                double d2 = p_72731_1_.lastTickPosZ + (p_72731_1_.posZ - p_72731_1_.lastTickPosZ) * (double)p_72731_4_;
                drawOutlinedBoundingBox(block.getSelectedBoundingBox(this.theWorld, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2), -1);
            }

            GlStateManager.depthMask(true);
            GlStateManager.func_179098_w();
            GlStateManager.disableBlend();
        }
    }

    /**
     * Draws lines for the edges of the bounding box.
     */
    public static void drawOutlinedBoundingBox(AxisAlignedBB p_147590_0_, int p_147590_1_)
    {
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        worldrenderer.startDrawing(3);

        if (p_147590_1_ != -1)
        {
            worldrenderer.func_178991_c(p_147590_1_);
        }

        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.minY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.minY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.minY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.minY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.minY, p_147590_0_.minZ);
        tessellator.draw();
        worldrenderer.startDrawing(3);

        if (p_147590_1_ != -1)
        {
            worldrenderer.func_178991_c(p_147590_1_);
        }

        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.maxY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.maxY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.maxY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.maxY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.maxY, p_147590_0_.minZ);
        tessellator.draw();
        worldrenderer.startDrawing(1);

        if (p_147590_1_ != -1)
        {
            worldrenderer.func_178991_c(p_147590_1_);
        }

        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.minY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.maxY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.minY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.maxY, p_147590_0_.minZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.minY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.maxX, p_147590_0_.maxY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.minY, p_147590_0_.maxZ);
        worldrenderer.addVertex(p_147590_0_.minX, p_147590_0_.maxY, p_147590_0_.maxZ);
        tessellator.draw();
    }

    /**
     * Marks the blocks in the given range for update
     */
    private void markBlocksForUpdate(int p_72725_1_, int p_72725_2_, int p_72725_3_, int p_72725_4_, int p_72725_5_, int p_72725_6_)
    {
        this.field_175008_n.func_178162_a(p_72725_1_, p_72725_2_, p_72725_3_, p_72725_4_, p_72725_5_, p_72725_6_);
    }

    public void markBlockForUpdate(BlockPos pos)
    {
        int i = pos.getX();
        int j = pos.getY();
        int k = pos.getZ();
        this.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1);
    }

    public void notifyLightSet(BlockPos pos)
    {
        int i = pos.getX();
        int j = pos.getY();
        int k = pos.getZ();
        this.markBlocksForUpdate(i - 1, j - 1, k - 1, i + 1, j + 1, k + 1);
    }

    /**
     * On the client, re-renders all blocks in this range, inclusive. On the server, does nothing. Args: min x, min y,
     * min z, max x, max y, max z
     */
    public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2)
    {
        this.markBlocksForUpdate(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1);
    }

    public void func_174961_a(String p_174961_1_, BlockPos p_174961_2_)
    {
        ISound isound = (ISound)this.mapSoundPositions.get(p_174961_2_);

        if (isound != null)
        {
            this.mc.getSoundHandler().stopSound(isound);
            this.mapSoundPositions.remove(p_174961_2_);
        }

        if (p_174961_1_ != null)
        {
            ItemRecord itemrecord = ItemRecord.getRecord(p_174961_1_);
            ResourceLocation resource = null;

            if (itemrecord != null)
            {
                this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal());
                resource = itemrecord.getRecordResource(p_174961_1_);
            }

            if (resource == null) resource = new ResourceLocation(p_174961_1_);
            PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.create(resource, (float)p_174961_2_.getX(), (float)p_174961_2_.getY(), (float)p_174961_2_.getZ());
            this.mapSoundPositions.put(p_174961_2_, positionedsoundrecord);
            this.mc.getSoundHandler().playSound(positionedsoundrecord);
        }
    }

    /**
     * Plays the specified sound. Arg: soundName, x, y, z, volume, pitch
     */
    public void playSound(String soundName, double x, double y, double z, float volume, float pitch) {}

    /**
     * Plays sound to all near players except the player reference given
     */
    public void playSoundToNearExcept(EntityPlayer except, String soundName, double x, double y, double z, float volume, float pitch) {}

    public void func_180442_a(int p_180442_1_, boolean p_180442_2_, final double p_180442_3_, final double p_180442_5_, final double p_180442_7_, double p_180442_9_, double p_180442_11_, double p_180442_13_, int ... p_180442_15_)
    {
        try
        {
            this.func_174974_b(p_180442_1_, p_180442_2_, p_180442_3_, p_180442_5_, p_180442_7_, p_180442_9_, p_180442_11_, p_180442_13_, p_180442_15_);
        }
        catch (Throwable throwable)
        {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception while adding particle");
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Particle being added");
            crashreportcategory.addCrashSection("ID", Integer.valueOf(p_180442_1_));

            if (p_180442_15_ != null)
            {
                crashreportcategory.addCrashSection("Parameters", p_180442_15_);
            }

            crashreportcategory.addCrashSectionCallable("Position", new Callable()
            {
                private static final String __OBFID = "CL_00000955";
                public String call()
                {
                    return CrashReportCategory.getCoordinateInfo(p_180442_3_, p_180442_5_, p_180442_7_);
                }
            });
            throw new ReportedException(crashreport);
        }
    }

    private void func_174972_a(EnumParticleTypes p_174972_1_, double p_174972_2_, double p_174972_4_, double p_174972_6_, double p_174972_8_, double p_174972_10_, double p_174972_12_, int ... p_174972_14_)
    {
        this.func_180442_a(p_174972_1_.func_179348_c(), p_174972_1_.func_179344_e(), p_174972_2_, p_174972_4_, p_174972_6_, p_174972_8_, p_174972_10_, p_174972_12_, p_174972_14_);
    }

    private EntityFX func_174974_b(int p_174974_1_, boolean p_174974_2_, double p_174974_3_, double p_174974_5_, double p_174974_7_, double p_174974_9_, double p_174974_11_, double p_174974_13_, int ... p_174974_15_)
    {
        if (this.mc != null && this.mc.getRenderViewEntity() != null && this.mc.effectRenderer != null)
        {
            int k = this.mc.gameSettings.particleSetting;

            if (k == 1 && this.theWorld.rand.nextInt(3) == 0)
            {
                k = 2;
            }

            double d6 = this.mc.getRenderViewEntity().posX - p_174974_3_;
            double d7 = this.mc.getRenderViewEntity().posY - p_174974_5_;
            double d8 = this.mc.getRenderViewEntity().posZ - p_174974_7_;

            if (p_174974_2_)
            {
                return this.mc.effectRenderer.func_178927_a(p_174974_1_, p_174974_3_, p_174974_5_, p_174974_7_, p_174974_9_, p_174974_11_, p_174974_13_, p_174974_15_);
            }
            else
            {
                double d9 = 16.0D;
                return d6 * d6 + d7 * d7 + d8 * d8 > 256.0D ? null : (k > 1 ? null : this.mc.effectRenderer.func_178927_a(p_174974_1_, p_174974_3_, p_174974_5_, p_174974_7_, p_174974_9_, p_174974_11_, p_174974_13_, p_174974_15_));
            }
        }
        else
        {
            return null;
        }
    }

    /**
     * Called on all IWorldAccesses when an entity is created or loaded. On client worlds, starts downloading any
     * necessary textures. On server worlds, adds the entity to the entity tracker.
     */
    public void onEntityAdded(Entity entityIn) {}

    /**
     * Called on all IWorldAccesses when an entity is unloaded or destroyed. On client worlds, releases any downloaded
     * textures. On server worlds, removes the entity from the entity tracker.
     */
    public void onEntityRemoved(Entity entityIn) {}

    /**
     * Deletes all display lists
     */
    public void deleteAllDisplayLists() {}

    public void func_180440_a(int p_180440_1_, BlockPos p_180440_2_, int p_180440_3_)
    {
        switch (p_180440_1_)
        {
            case 1013:
            case 1018:
                if (this.mc.getRenderViewEntity() != null)
                {
                    double d0 = (double)p_180440_2_.getX() - this.mc.getRenderViewEntity().posX;
                    double d1 = (double)p_180440_2_.getY() - this.mc.getRenderViewEntity().posY;
                    double d2 = (double)p_180440_2_.getZ() - this.mc.getRenderViewEntity().posZ;
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    double d4 = this.mc.getRenderViewEntity().posX;
                    double d5 = this.mc.getRenderViewEntity().posY;
                    double d6 = this.mc.getRenderViewEntity().posZ;

                    if (d3 > 0.0D)
                    {
                        d4 += d0 / d3 * 2.0D;
                        d5 += d1 / d3 * 2.0D;
                        d6 += d2 / d3 * 2.0D;
                    }

                    if (p_180440_1_ == 1013)
                    {
                        this.theWorld.playSound(d4, d5, d6, "mob.wither.spawn", 1.0F, 1.0F, false);
                    }
                    else
                    {
                        this.theWorld.playSound(d4, d5, d6, "mob.enderdragon.end", 5.0F, 1.0F, false);
                    }
                }
            default:
        }
    }

    public void func_180439_a(EntityPlayer p_180439_1_, int p_180439_2_, BlockPos p_180439_3_, int p_180439_4_)
    {
        Random random = this.theWorld.rand;
        double d0;
        double d1;
        double d2;
        int l;
        int i1;
        double d3;
        double d5;
        double d7;
        double d13;

        switch (p_180439_2_)
        {
            case 1000:
                this.theWorld.func_175731_a(p_180439_3_, "random.click", 1.0F, 1.0F, false);
                break;
            case 1001:
                this.theWorld.func_175731_a(p_180439_3_, "random.click", 1.0F, 1.2F, false);
                break;
            case 1002:
                this.theWorld.func_175731_a(p_180439_3_, "random.bow", 1.0F, 1.2F, false);
                break;
            case 1003:
                this.theWorld.func_175731_a(p_180439_3_, "random.door_open", 1.0F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 1004:
                this.theWorld.func_175731_a(p_180439_3_, "random.fizz", 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F, false);
                break;
            case 1005:
                if (Item.getItemById(p_180439_4_) instanceof ItemRecord)
                {
                    this.theWorld.func_175717_a(p_180439_3_, "records." + ((ItemRecord)Item.getItemById(p_180439_4_)).recordName);
                }
                else
                {
                    this.theWorld.func_175717_a(p_180439_3_, (String)null);
                }

                break;
            case 1006:
                this.theWorld.func_175731_a(p_180439_3_, "random.door_close", 1.0F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 1007:
                this.theWorld.func_175731_a(p_180439_3_, "mob.ghast.charge", 10.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1008:
                this.theWorld.func_175731_a(p_180439_3_, "mob.ghast.fireball", 10.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1009:
                this.theWorld.func_175731_a(p_180439_3_, "mob.ghast.fireball", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1010:
                this.theWorld.func_175731_a(p_180439_3_, "mob.zombie.wood", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1011:
                this.theWorld.func_175731_a(p_180439_3_, "mob.zombie.metal", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1012:
                this.theWorld.func_175731_a(p_180439_3_, "mob.zombie.woodbreak", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1014:
                this.theWorld.func_175731_a(p_180439_3_, "mob.wither.shoot", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1015:
                this.theWorld.func_175731_a(p_180439_3_, "mob.bat.takeoff", 0.05F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1016:
                this.theWorld.func_175731_a(p_180439_3_, "mob.zombie.infect", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1017:
                this.theWorld.func_175731_a(p_180439_3_, "mob.zombie.unfect", 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
                break;
            case 1020:
                this.theWorld.func_175731_a(p_180439_3_, "random.anvil_break", 1.0F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 1021:
                this.theWorld.func_175731_a(p_180439_3_, "random.anvil_use", 1.0F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 1022:
                this.theWorld.func_175731_a(p_180439_3_, "random.anvil_land", 0.3F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 2000:
                int j1 = p_180439_4_ % 3 - 1;
                int k = p_180439_4_ / 3 % 3 - 1;
                d1 = (double)p_180439_3_.getX() + (double)j1 * 0.6D + 0.5D;
                d2 = (double)p_180439_3_.getY() + 0.5D;
                d13 = (double)p_180439_3_.getZ() + (double)k * 0.6D + 0.5D;

                for (int k1 = 0; k1 < 10; ++k1)
                {
                    double d14 = random.nextDouble() * 0.2D + 0.01D;
                    double d15 = d1 + (double)j1 * 0.01D + (random.nextDouble() - 0.5D) * (double)k * 0.5D;
                    double d4 = d2 + (random.nextDouble() - 0.5D) * 0.5D;
                    double d6 = d13 + (double)k * 0.01D + (random.nextDouble() - 0.5D) * (double)j1 * 0.5D;
                    double d8 = (double)j1 * d14 + random.nextGaussian() * 0.01D;
                    double d10 = -0.03D + random.nextGaussian() * 0.01D;
                    double d12 = (double)k * d14 + random.nextGaussian() * 0.01D;
                    this.func_174972_a(EnumParticleTypes.SMOKE_NORMAL, d15, d4, d6, d8, d10, d12, new int[0]);
                }

                return;
            case 2001:
                Block block = Block.getBlockById(p_180439_4_ & 4095);

                if (block.getMaterial() != Material.air)
                {
                    this.mc.getSoundHandler().playSound(new PositionedSoundRecord(new ResourceLocation(block.stepSound.getBreakSound()), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getFrequency() * 0.8F, (float)p_180439_3_.getX() + 0.5F, (float)p_180439_3_.getY() + 0.5F, (float)p_180439_3_.getZ() + 0.5F));
                }

                this.mc.effectRenderer.func_180533_a(p_180439_3_, block.getStateFromMeta(p_180439_4_ >> 12 & 255));
                break;
            case 2002:
                d0 = (double)p_180439_3_.getX();
                d1 = (double)p_180439_3_.getY();
                d2 = (double)p_180439_3_.getZ();

                for (l = 0; l < 8; ++l)
                {
                    this.func_174972_a(EnumParticleTypes.ITEM_CRACK, d0, d1, d2, random.nextGaussian() * 0.15D, random.nextDouble() * 0.2D, random.nextGaussian() * 0.15D, new int[] {Item.getIdFromItem(Items.potionitem), p_180439_4_});
                }

                l = Items.potionitem.getColorFromDamage(p_180439_4_);
                float f = (float)(l >> 16 & 255) / 255.0F;
                float f1 = (float)(l >> 8 & 255) / 255.0F;
                float f2 = (float)(l >> 0 & 255) / 255.0F;
                EnumParticleTypes enumparticletypes = EnumParticleTypes.SPELL;

                if (Items.potionitem.isEffectInstant(p_180439_4_))
                {
                    enumparticletypes = EnumParticleTypes.SPELL_INSTANT;
                }

                for (i1 = 0; i1 < 100; ++i1)
                {
                    d3 = random.nextDouble() * 4.0D;
                    d5 = random.nextDouble() * Math.PI * 2.0D;
                    d7 = Math.cos(d5) * d3;
                    double d9 = 0.01D + random.nextDouble() * 0.5D;
                    double d11 = Math.sin(d5) * d3;
                    EntityFX entityfx = this.func_174974_b(enumparticletypes.func_179348_c(), enumparticletypes.func_179344_e(), d0 + d7 * 0.1D, d1 + 0.3D, d2 + d11 * 0.1D, d7, d9, d11, new int[0]);

                    if (entityfx != null)
                    {
                        float f3 = 0.75F + random.nextFloat() * 0.25F;
                        entityfx.setRBGColorF(f * f3, f1 * f3, f2 * f3);
                        entityfx.multiplyVelocity((float)d3);
                    }
                }

                this.theWorld.func_175731_a(p_180439_3_, "game.potion.smash", 1.0F, this.theWorld.rand.nextFloat() * 0.1F + 0.9F, false);
                break;
            case 2003:
                d0 = (double)p_180439_3_.getX() + 0.5D;
                d1 = (double)p_180439_3_.getY();
                d2 = (double)p_180439_3_.getZ() + 0.5D;

                for (l = 0; l < 8; ++l)
                {
                    this.func_174972_a(EnumParticleTypes.ITEM_CRACK, d0, d1, d2, random.nextGaussian() * 0.15D, random.nextDouble() * 0.2D, random.nextGaussian() * 0.15D, new int[] {Item.getIdFromItem(Items.ender_eye)});
                }

                for (d13 = 0.0D; d13 < (Math.PI * 2D); d13 += 0.15707963267948966D)
                {
                    this.func_174972_a(EnumParticleTypes.PORTAL, d0 + Math.cos(d13) * 5.0D, d1 - 0.4D, d2 + Math.sin(d13) * 5.0D, Math.cos(d13) * -5.0D, 0.0D, Math.sin(d13) * -5.0D, new int[0]);
                    this.func_174972_a(EnumParticleTypes.PORTAL, d0 + Math.cos(d13) * 5.0D, d1 - 0.4D, d2 + Math.sin(d13) * 5.0D, Math.cos(d13) * -7.0D, 0.0D, Math.sin(d13) * -7.0D, new int[0]);
                }

                return;
            case 2004:
                for (i1 = 0; i1 < 20; ++i1)
                {
                    d3 = (double)p_180439_3_.getX() + 0.5D + ((double)this.theWorld.rand.nextFloat() - 0.5D) * 2.0D;
                    d5 = (double)p_180439_3_.getY() + 0.5D + ((double)this.theWorld.rand.nextFloat() - 0.5D) * 2.0D;
                    d7 = (double)p_180439_3_.getZ() + 0.5D + ((double)this.theWorld.rand.nextFloat() - 0.5D) * 2.0D;
                    this.theWorld.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
                    this.theWorld.spawnParticle(EnumParticleTypes.FLAME, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
                }

                return;
            case 2005:
                ItemDye.func_180617_a(this.theWorld, p_180439_3_, p_180439_4_);
        }
    }

    public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress)
    {
        if (progress >= 0 && progress < 10)
        {
            DestroyBlockProgress destroyblockprogress = (DestroyBlockProgress)this.damagedBlocks.get(Integer.valueOf(breakerId));

            if (destroyblockprogress == null || destroyblockprogress.func_180246_b().getX() != pos.getX() || destroyblockprogress.func_180246_b().getY() != pos.getY() || destroyblockprogress.func_180246_b().getZ() != pos.getZ())
            {
                destroyblockprogress = new DestroyBlockProgress(breakerId, pos);
                this.damagedBlocks.put(Integer.valueOf(breakerId), destroyblockprogress);
            }

            destroyblockprogress.setPartialBlockDamage(progress);
            destroyblockprogress.setCloudUpdateTick(this.cloudTickCounter);
        }
        else
        {
            this.damagedBlocks.remove(Integer.valueOf(breakerId));
        }
    }

    public void func_174979_m()
    {
        this.displayListEntitiesDirty = true;
    }

    @SideOnly(Side.CLIENT)
    class ContainerLocalRenderInformation
    {
        final RenderChunk field_178036_a;
        final EnumFacing field_178034_b;
        final Set field_178035_c;
        final int field_178032_d;
        private static final String __OBFID = "CL_00002534";

        private ContainerLocalRenderInformation(RenderChunk p_i46248_2_, EnumFacing p_i46248_3_, int p_i46248_4_)
        {
            this.field_178035_c = EnumSet.noneOf(EnumFacing.class);
            this.field_178036_a = p_i46248_2_;
            this.field_178034_b = p_i46248_3_;
            this.field_178032_d = p_i46248_4_;
        }

        ContainerLocalRenderInformation(RenderChunk p_i46249_2_, EnumFacing p_i46249_3_, int p_i46249_4_, Object p_i46249_5_)
        {
            this(p_i46249_2_, p_i46249_3_, p_i46249_4_);
        }
    }

    @SideOnly(Side.CLIENT)

    static final class SwitchEnumUsage
        {
            static final int[] field_178037_a = new int[VertexFormatElement.EnumUsage.values().length];
            private static final String __OBFID = "CL_00002535";

            static
            {
                try
                {
                    field_178037_a[VertexFormatElement.EnumUsage.POSITION.ordinal()] = 1;
                }
                catch (NoSuchFieldError var3)
                {
                    ;
                }

                try
                {
                    field_178037_a[VertexFormatElement.EnumUsage.UV.ordinal()] = 2;
                }
                catch (NoSuchFieldError var2)
                {
                    ;
                }

                try
                {
                    field_178037_a[VertexFormatElement.EnumUsage.COLOR.ordinal()] = 3;
                }
                catch (NoSuchFieldError var1)
                {
                    ;
                }
            }
        }
}