public void updateEntities()
    {
        Profiler.startSection("entities");
        Profiler.startSection("global");
        int var1;
        Entity var2;

        for (var1 = 0; var1 < this.weatherEffects.size(); ++var1)
        {
            var2 = (Entity)this.weatherEffects.get(var1);
            var2.onUpdate();

            if (var2.isDead)
            {
                this.weatherEffects.remove(var1--);
            }
        }

        Profiler.endStartSection("remove");
        this.loadedEntityList.removeAll(this.unloadedEntityList);
        int var3;
        int var4;

        for (var1 = 0; var1 < this.unloadedEntityList.size(); ++var1)
        {
            var2 = (Entity)this.unloadedEntityList.get(var1);
            var3 = var2.chunkCoordX;
            var4 = var2.chunkCoordZ;

            if (var2.addedToChunk && this.chunkExists(var3, var4))
            {
                this.getChunkFromChunkCoords(var3, var4).removeEntity(var2);
            }
        }

        for (var1 = 0; var1 < this.unloadedEntityList.size(); ++var1)
        {
            this.releaseEntitySkin((Entity)this.unloadedEntityList.get(var1));
        }

        this.unloadedEntityList.clear();
        Profiler.endStartSection("regular");

        for (var1 = 0; var1 < this.loadedEntityList.size(); ++var1)
        {
            var2 = (Entity)this.loadedEntityList.get(var1);

            if (var2.ridingEntity != null)
            {
                if (!var2.ridingEntity.isDead && var2.ridingEntity.riddenByEntity == var2)
                {
                    continue;
                }

                var2.ridingEntity.riddenByEntity = null;
                var2.ridingEntity = null;
            }

            if (!var2.isDead)
            {
                this.updateEntity(var2);
            }

            Profiler.startSection("remove");

            if (var2.isDead)
            {
                var3 = var2.chunkCoordX;
                var4 = var2.chunkCoordZ;

                if (var2.addedToChunk && this.chunkExists(var3, var4))
                {
                    this.getChunkFromChunkCoords(var3, var4).removeEntity(var2);
                }

                this.loadedEntityList.remove(var1--);
                this.releaseEntitySkin(var2);
            }

            Profiler.endSection();
        }

        Profiler.endStartSection("tileEntities");
        this.scanningTileEntities = true;
        Iterator var10 = this.loadedTileEntityList.iterator();

        while (var10.hasNext())
        {
            TileEntity var5 = (TileEntity)var10.next();

            if (!var5.isInvalid() && var5.worldObj != null && this.blockExists(var5.xCoord, var5.yCoord, var5.zCoord))
            {
                var5.updateEntity();
            }

            if (var5.isInvalid())
            {
                var10.remove();

                if (this.chunkExists(var5.xCoord >> 4, var5.zCoord >> 4))
                {
                    Chunk var7 = this.getChunkFromChunkCoords(var5.xCoord >> 4, var5.zCoord >> 4);

                    if (var7 != null)
                    {
                        var7.cleanChunkBlockTileEntity(var5.xCoord & 15, var5.yCoord, var5.zCoord & 15);
                    }
                }
            }
        }

        this.scanningTileEntities = false;

        if (!this.entityRemoval.isEmpty())
        {
            this.loadedTileEntityList.removeAll(this.entityRemoval);
            this.entityRemoval.clear();
        }

        Profiler.endStartSection("pendingTileEntities");

        if (!this.addedTileEntityList.isEmpty())
        {
            Iterator var6 = this.addedTileEntityList.iterator();

            while (var6.hasNext())
            {
                TileEntity var8 = (TileEntity)var6.next();

                if (!var8.isInvalid())
                {
                    if (!this.loadedTileEntityList.contains(var8))
                    {
                        this.loadedTileEntityList.add(var8);
                    }
                }
                else
                {
                    if (this.chunkExists(var8.xCoord >> 4, var8.zCoord >> 4))
                    {
                        Chunk var9 = this.getChunkFromChunkCoords(var8.xCoord >> 4, var8.zCoord >> 4);

                        if (var9 != null)
                        {
                            var9.cleanChunkBlockTileEntity(var8.xCoord & 15, var8.yCoord, var8.zCoord & 15);
                        }
                    }
                }
            }

            this.addedTileEntityList.clear();
        }

        Profiler.endSection();
        Profiler.endSection();
    }